init create-fias

This commit is contained in:
Samandar Turgunboyev
2025-12-20 09:26:40 +05:00
commit fd397b670b
60 changed files with 6817 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
const BASE_URL =
import.meta.env.VITE_API_URL || 'https://jsonplaceholder.typicode.com';
const ENDP_POSTS = '/posts/';
export { BASE_URL, ENDP_POSTS };

View File

@@ -0,0 +1,35 @@
import axios from 'axios';
import { BASE_URL } from './URLs';
import i18n from '@/shared/config/i18n';
const httpClient = axios.create({
baseURL: BASE_URL,
timeout: 10000,
});
httpClient.interceptors.request.use(
async (config) => {
console.log(`API REQUEST to ${config.url}`, config);
// Language configs
const language = i18n.language;
config.headers['Accept-Language'] = language;
// const accessToken = localStorage.getItem('accessToken');
// if (accessToken) {
// config.headers['Authorization'] = `Bearer ${accessToken}`;
// }
return config;
},
(error) => Promise.reject(error),
);
httpClient.interceptors.response.use(
(response) => response,
(error) => {
console.error('API error:', error);
return Promise.reject(error);
},
);
export default httpClient;

View File

@@ -0,0 +1,6 @@
export interface TestApiType {
userId: number;
id: number;
title: string;
body: string;
}

View File

@@ -0,0 +1,14 @@
import httpClient from '@/shared/config/api/httpClient';
import type { TestApiType } from '@/shared/config/api/test/test.model';
import type { ReqWithPagination } from '@/shared/config/api/types';
import { ENDP_POSTS } from '@/shared/config/api/URLs';
import type { AxiosResponse } from 'axios';
const getPosts = async (
pagination?: ReqWithPagination,
): Promise<AxiosResponse<TestApiType>> => {
const response = await httpClient.get(ENDP_POSTS, { params: pagination });
return response;
};
export { getPosts };

View File

@@ -0,0 +1,20 @@
export interface ResWithPagination<T> {
success: boolean;
message: string;
links: Links;
total_items: number;
total_pages: number;
page_size: number;
current_page: number;
data: T[];
}
interface Links {
next: number | null;
previous: number | null;
}
export interface ReqWithPagination {
_start?: number;
_limit?: number;
}