Fix for working with backend

This commit is contained in:
KamilM1205 2026-01-02 16:02:13 +04:00
parent 5ab2d8abfd
commit d44d106b85
6 changed files with 28 additions and 22 deletions

View file

@ -1,11 +1,12 @@
import axios from "axios";
const API_BASE_URL = 'http://localhost:3000/api';
const API_BASE_URL = 'http://localhost:8080/api/v1/';
const apiClient = axios.create({
baseURL: API_BASE_URL,
timeout: 10000,
headers: {
'Content-Type': 'application/json',
'Origin': 'localhost:8080'
}
});
@ -17,4 +18,4 @@ apiClient.interceptors.response.use(
}
);
export default apiClient;
export default apiClient;

View file

@ -3,8 +3,12 @@ import apiClient from './api.js';
export const blogService = {
// Получить все статьи
async getBlogPosts(params = {}) {
let request = '/post/'
if (params["offset"] != null) {
request += 'offset/' + params["offset"]
}
try {
const response = await apiClient.get('/posts', { params });
const response = await apiClient.get(request);
return response.data;
} catch (error) {
console.error('Error fetching blog posts:', error);
@ -15,7 +19,7 @@ export const blogService = {
// Получить статью по ID
async getPostById(id) {
try {
const response = await apiClient.get(`/posts/${id}`);
const response = await apiClient.get(`/post/${id}`);
return response.data;
} catch (error) {
console.error('Error fetching post:', error);
@ -26,7 +30,7 @@ async getPostById(id) {
// Получить статьи по категории
async getPostsByCategory(category, params = {}) {
try {
const response = await apiClient.get('/posts', {
const response = await apiClient.get('/post', {
params: { category, ...params }
});
return response.data;
@ -39,7 +43,7 @@ async getPostById(id) {
// Получить статьи по тегу
async getPostsByTag(tag, params = {}) {
try {
const response = await apiClient.get('/posts', {
const response = await apiClient.get('/post', {
params: { tag, ...params }
});
return response.data;
@ -52,7 +56,7 @@ async getPostById(id) {
// Получить статьи по автору
async getPostsByAuthor(username, params = {}) {
try {
const response = await apiClient.get('/posts', {
const response = await apiClient.get('/post', {
params: { username, ...params }
});
return response.data;
@ -161,4 +165,4 @@ function getMockBlogPosts() {
updatedAt: "2024-01-08T13:10:00Z"
}
];
}
}

View file

@ -9,6 +9,7 @@ export function formatDate(dateString) {
export function formatDateTime(dateString) {
const date = new Date(dateString);
console.log("date: ", dateString, " ", date)
return date.toLocaleDateString('ru-RU', {
year: 'numeric',
month: 'long',
@ -29,4 +30,4 @@ export function getRelativeTime(dateString) {
if (diffInSeconds < 604800) return `${Math.floor(diffInSeconds / 86400)} дн. назад`;
return formatDate(dateString);
}
}

View file

@ -12,11 +12,11 @@
const error = writable(null);
const slogans = [
"Innovation Through Retro",
"Code Like It's 1999",
"Future Ready, Retro Style",
"Where Vintage Meets Modern",
"Digital Revolution, Classic Soul"
"Код, который решает. Команда, которая вдохновляет.",
"Ваши идеи — наш код. Ваш успех — наша миссия.",
"Преобразуем сложное в элегантные решения.",
"Сила в технологии. Успех в команде.",
"За пределами кода — безграничные возможности."
];
const currentSlogan = writable(slogans[0]);
@ -292,8 +292,8 @@
{#each $blogPosts as post}
<article class="article-preview">
<div class="article-meta">
<span class="article-date">{new Date(post.date).toLocaleDateString()}</span>
<span class="article-author">by {post.author}</span>
<span class="article-date">{new Date(post.updatedAt).toLocaleDateString()}</span>
<span class="article-author">by {post.username}</span>
</div>
<h4 class="article-title">{post.title}</h4>
<p class="article-excerpt">{post.excerpt}</p>
@ -303,7 +303,7 @@
<span class="tag">#{tag}</span>
{/each}
</div>
<a href={`/blog/${post.slug}`} class="read-more">READ →</a>
<a href={`/blog/${post.id}`} class="read-more">READ →</a>
</div>
</article>
{/each}
@ -957,4 +957,4 @@
border: 1px solid var(--secondary-pink);
}
</style>
</style>

View file

@ -80,7 +80,7 @@
const nextPage = $currentPage + 1;
const newPosts = await blogService.getBlogPosts({
limit: postsPerPage,
offset: postsPerPage,
...buildApiFilters($selectedFilters)
});

View file

@ -230,7 +230,7 @@
<div class="related-meta">
<span class="related-category">{relatedPost.category}</span>
<span class="related-date">{getRelativeTime(relatedPost.updatedAt)}</span>
<span class="related-date">{formatDateTime(relatedPost.updatedAt)}</span>
</div>
{#if relatedPost.description}
@ -284,7 +284,7 @@
<style>
.post-page {
height: 100vh;
min-height: 100vh;
padding-top: 50px;
background: var(--bg-dark);
overflow: hidden;
@ -654,4 +654,4 @@
padding: 15px;
}
}
</style>
</style>