feat: extract API endpoints to separate endpoints.ts file and enhance axios configuration with centralized setup and error handling
This commit is contained in:
@@ -1,3 +1,18 @@
|
||||
// src/lib/axios.ts
|
||||
//
|
||||
// PURPOSE:
|
||||
// - Centralized Axios instance configuration
|
||||
// - Global response error handling
|
||||
// - Standardized API endpoint definitions
|
||||
// - Reusable fetcher utility
|
||||
//
|
||||
// RULES:
|
||||
// - All API calls must use this axiosInstance
|
||||
// - Custom error handling in interceptor
|
||||
// - Endpoints should be defined here for consistency
|
||||
// - Fetcher should be used for simple GET requests
|
||||
//
|
||||
|
||||
import type { AxiosRequestConfig } from 'axios';
|
||||
import axios from 'axios';
|
||||
import { CONFIG } from 'src/global-config';
|
||||
@@ -27,99 +42,3 @@ export const fetcher = async (args: string | [string, AxiosRequestConfig]) => {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export const endpoints = {
|
||||
chat: '/api/chat',
|
||||
kanban: '/api/kanban',
|
||||
calendar: '/api/calendar',
|
||||
auth: {
|
||||
me: '/api/auth/me',
|
||||
signIn: '/api/auth/sign-in',
|
||||
signUp: '/api/auth/sign-up',
|
||||
},
|
||||
mail: {
|
||||
list: '/api/mail/list',
|
||||
details: '/api/mail/details',
|
||||
labels: '/api/mail/labels',
|
||||
},
|
||||
post: {
|
||||
list: '/api/post/list',
|
||||
details: '/api/post/details',
|
||||
latest: '/api/post/latest',
|
||||
search: '/api/post/search',
|
||||
},
|
||||
product: {
|
||||
list: '/api/product/list',
|
||||
details: '/api/product/details',
|
||||
search: '/api/product/search',
|
||||
save: '/api/product/saveProduct',
|
||||
create: '/api/product/create',
|
||||
update: '/api/product/update',
|
||||
delete: '/api/product/delete',
|
||||
},
|
||||
user: {
|
||||
list: '/api/user/list',
|
||||
profile: '/api/user/profile',
|
||||
update: '/api/user/update',
|
||||
settings: '/api/user/settings',
|
||||
details: '/api/user/details',
|
||||
},
|
||||
order: {
|
||||
list: '/api/order/list',
|
||||
profile: '/api/order/profile',
|
||||
update: '/api/order/update',
|
||||
settings: '/api/order/settings',
|
||||
details: '/api/order/details',
|
||||
changeStatus: (orderId: string) => `/api/order/changeStatus?orderId=${orderId}`,
|
||||
},
|
||||
invoice: {
|
||||
list: '/api/invoice/list',
|
||||
profile: '/api/invoice/profile',
|
||||
update: '/api/invoice/update',
|
||||
saveInvoice: (invoiceId: string) => `/api/invoice/saveInvoice?invoiceId=${invoiceId}`,
|
||||
settings: '/api/invoice/settings',
|
||||
details: '/api/invoice/details',
|
||||
changeStatus: (invoiceId: string) => `/api/invoice/changeStatus?invoiceId=${invoiceId}`,
|
||||
search: '/api/invoice/search',
|
||||
},
|
||||
//
|
||||
//
|
||||
//
|
||||
partyEvent: {
|
||||
list: '/api/party-event/list',
|
||||
details: '/api/party-event/details',
|
||||
search: '/api/party-event/search',
|
||||
create: '/api/party-event/create',
|
||||
update: '/api/party-event/update',
|
||||
delete: '/api/party-event/delete',
|
||||
},
|
||||
partyOrder: {
|
||||
create: '/api/party-order/create',
|
||||
delete: '/api/party-order/delete',
|
||||
list: '/api/party-order/list',
|
||||
profile: '/api/party-order/profile',
|
||||
update: '/api/party-order/update',
|
||||
settings: '/api/party-order/settings',
|
||||
details: '/api/party-order/details',
|
||||
changeStatus: (partyOrderId: string) =>
|
||||
`/api/party-order/changeStatus?partyOrderId=${partyOrderId}`,
|
||||
},
|
||||
partyUser: {
|
||||
list: '/api/party-user/list',
|
||||
details: '/api/party-user/details',
|
||||
search: '/api/party-user/search',
|
||||
create: '/api/party-user/create',
|
||||
update: '/api/party-user/update',
|
||||
delete: '/api/party-user/delete',
|
||||
//
|
||||
detailsByPartyUserId: (partyUserId: string) =>
|
||||
`/api/party-user/details?partyUserId=${partyUserId}`,
|
||||
},
|
||||
partyUserAuth: {
|
||||
me: '/api/party-user-auth/me',
|
||||
signIn: '/api/party-user-auth/sign-in',
|
||||
signUp: '/api/party-user-auth/sign-up',
|
||||
},
|
||||
};
|
||||
|
96
03_source/frontend/src/lib/endpoints.ts
Normal file
96
03_source/frontend/src/lib/endpoints.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export const endpoints = {
|
||||
chat: '/api/chat',
|
||||
kanban: '/api/kanban',
|
||||
calendar: '/api/calendar',
|
||||
auth: {
|
||||
me: '/api/auth/me',
|
||||
signIn: '/api/auth/sign-in',
|
||||
signUp: '/api/auth/sign-up',
|
||||
},
|
||||
mail: {
|
||||
list: '/api/mail/list',
|
||||
details: '/api/mail/details',
|
||||
labels: '/api/mail/labels',
|
||||
},
|
||||
post: {
|
||||
list: '/api/post/list',
|
||||
details: '/api/post/details',
|
||||
latest: '/api/post/latest',
|
||||
search: '/api/post/search',
|
||||
},
|
||||
product: {
|
||||
list: '/api/product/list',
|
||||
details: '/api/product/details',
|
||||
search: '/api/product/search',
|
||||
save: '/api/product/saveProduct',
|
||||
create: '/api/product/create',
|
||||
update: '/api/product/update',
|
||||
delete: '/api/product/delete',
|
||||
},
|
||||
user: {
|
||||
list: '/api/user/list',
|
||||
profile: '/api/user/profile',
|
||||
update: '/api/user/update',
|
||||
settings: '/api/user/settings',
|
||||
details: '/api/user/details',
|
||||
},
|
||||
order: {
|
||||
list: '/api/order/list',
|
||||
profile: '/api/order/profile',
|
||||
update: '/api/order/update',
|
||||
settings: '/api/order/settings',
|
||||
details: '/api/order/details',
|
||||
changeStatus: (orderId: string) => `/api/order/changeStatus?orderId=${orderId}`,
|
||||
},
|
||||
invoice: {
|
||||
list: '/api/invoice/list',
|
||||
profile: '/api/invoice/profile',
|
||||
update: '/api/invoice/update',
|
||||
saveInvoice: (invoiceId: string) => `/api/invoice/saveInvoice?invoiceId=${invoiceId}`,
|
||||
settings: '/api/invoice/settings',
|
||||
details: '/api/invoice/details',
|
||||
changeStatus: (invoiceId: string) => `/api/invoice/changeStatus?invoiceId=${invoiceId}`,
|
||||
search: '/api/invoice/search',
|
||||
},
|
||||
//
|
||||
//
|
||||
//
|
||||
partyEvent: {
|
||||
list: '/api/party-event/list',
|
||||
details: '/api/party-event/details',
|
||||
search: '/api/party-event/search',
|
||||
create: '/api/party-event/create',
|
||||
update: '/api/party-event/update',
|
||||
delete: '/api/party-event/delete',
|
||||
numOfEvent: '/api/party-event/numOfEvent',
|
||||
},
|
||||
partyOrder: {
|
||||
create: '/api/party-order/create',
|
||||
delete: '/api/party-order/delete',
|
||||
list: '/api/party-order/list',
|
||||
profile: '/api/party-order/profile',
|
||||
update: '/api/party-order/update',
|
||||
settings: '/api/party-order/settings',
|
||||
details: '/api/party-order/details',
|
||||
changeStatus: (partyOrderId: string) =>
|
||||
`/api/party-order/changeStatus?partyOrderId=${partyOrderId}`,
|
||||
},
|
||||
partyUser: {
|
||||
list: '/api/party-user/list',
|
||||
details: '/api/party-user/details',
|
||||
search: '/api/party-user/search',
|
||||
create: '/api/party-user/create',
|
||||
update: '/api/party-user/update',
|
||||
delete: '/api/party-user/delete',
|
||||
//
|
||||
detailsByPartyUserId: (partyUserId: string) =>
|
||||
`/api/party-user/details?partyUserId=${partyUserId}`,
|
||||
},
|
||||
partyUserAuth: {
|
||||
me: '/api/party-user-auth/me',
|
||||
signIn: '/api/party-user-auth/sign-in',
|
||||
signUp: '/api/party-user-auth/sign-up',
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user