feat(construction): Phase 3.1 카테고리관리 API 연동 완료

- apiClient에 patch 메서드 추가
- apiClient.get에 params 옵션 지원 추가
- updateCategory: PUT → PATCH 수정
- reorderCategories: PUT → POST 수정
This commit is contained in:
2026-01-09 22:01:47 +09:00
parent ae90bd7c52
commit e4b5e6ae30
2 changed files with 23 additions and 6 deletions

View File

@@ -94,7 +94,7 @@ export async function createCategory(data: {
/**
* 카테고리 수정
* PUT /api/v1/categories/{id}
* PATCH /api/v1/categories/{id}
*/
export async function updateCategory(
id: string,
@@ -105,7 +105,7 @@ export async function updateCategory(
error?: string;
}> {
try {
const response = await apiClient.put<ApiCategory>(`/categories/${id}`, {
const response = await apiClient.patch<ApiCategory>(`/categories/${id}`, {
name: data.name,
});
return { success: true, data: transformCategory(response) };
@@ -161,7 +161,7 @@ export async function deleteCategory(id: string): Promise<{
/**
* 카테고리 순서 변경
* PUT /api/v1/categories/reorder
* POST /api/v1/categories/reorder
*/
export async function reorderCategories(
items: { id: string; sort_order: number }[]
@@ -170,7 +170,7 @@ export async function reorderCategories(
error?: string;
}> {
try {
await apiClient.put('/categories/reorder', {
await apiClient.post('/categories/reorder', {
items: items.map((item) => ({
id: Number(item.id),
sort_order: item.sort_order,

View File

@@ -102,9 +102,16 @@ export class ApiClient {
/**
* GET 요청
* @param endpoint API 엔드포인트
* @param options 쿼리 파라미터 등 옵션
*/
async get<T>(endpoint: string): Promise<T> {
return this.request<T>(endpoint, { method: 'GET' });
async get<T>(endpoint: string, options?: { params?: Record<string, string> }): Promise<T> {
let url = endpoint;
if (options?.params) {
const searchParams = new URLSearchParams(options.params);
url = `${endpoint}?${searchParams.toString()}`;
}
return this.request<T>(url, { method: 'GET' });
}
/**
@@ -127,6 +134,16 @@ export class ApiClient {
});
}
/**
* PATCH 요청
*/
async patch<T>(endpoint: string, data?: unknown): Promise<T> {
return this.request<T>(endpoint, {
method: 'PATCH',
body: data ? JSON.stringify(data) : undefined,
});
}
/**
* DELETE 요청
*/