diff --git a/ui/src/lib/apis/review/client.ts b/ui/src/lib/apis/review/client.ts index 21d225f8..5501e1f7 100644 --- a/ui/src/lib/apis/review/client.ts +++ b/ui/src/lib/apis/review/client.ts @@ -7,63 +7,48 @@ import type { UpdateReviewRequest, UpdateReviewResponse, } from '@/lib/definitions/review'; -import dummyReviewList from '@/lib/dummy/review'; export async function createReview(data: CreateReviewRequest): Promise { - try { - const response = await fetch('/api/v1/reviews', { - method: 'POST', - body: JSON.stringify(data), - headers: { 'Content-Type': 'application/json' }, - }); - - if (!response.ok) { - const { messages } = (await response.json()) as HttpErrorResponse; - - // TODO: build proper error message - console.error( - `status: ${response.status}\nstatusText: ${response.statusText}\nmessages:\n${messages.join('\n')}` - ); - - throw new Error('네트워크 오류가 발생했습니다. 다시 시도해주세요.'); - } - - return (await response.json()) as CreateReviewResponse; - } catch (error) { - // TODO: DELETE THIS WHEN API IS READY - return await new Promise((resolve) => - setTimeout(() => resolve({ review: dummyReviewList.reviews[0] }), 500) + const response = await fetch('/api/v1/reviews', { + method: 'POST', + body: JSON.stringify(data), + headers: { 'Content-Type': 'application/json' }, + }); + + if (!response.ok) { + const { messages } = (await response.json()) as HttpErrorResponse; + + // TODO: build proper error message + console.error( + `status: ${response.status}\nstatusText: ${response.statusText}\nmessages:\n${messages.join('\n')}` ); + + throw new Error('네트워크 오류가 발생했습니다. 다시 시도해주세요.'); } + + return (await response.json()) as CreateReviewResponse; } export async function updateReview( id: number, data: UpdateReviewRequest ): Promise { - try { - const response = await fetch(`/api/v1/reviews/${id}`, { - method: 'PUT', - body: JSON.stringify(data), - headers: { 'Content-Type': 'application/json' }, - }); - - if (!response.ok) { - const { messages } = (await response.json()) as HttpErrorResponse; - - // TODO: build proper error message - console.error( - `status: ${response.status}\nstatusText: ${response.statusText}\nmessages:\n${messages.join('\n')}` - ); - - throw new Error('네트워크 오류가 발생했습니다. 다시 시도해주세요.'); - } - - return (await response.json()) as UpdateReviewResponse; - } catch (error) { - // TODO: DELETE THIS WHEN API IS READY - return await new Promise((resolve) => - setTimeout(() => resolve({ review: dummyReviewList.reviews[Number(id) - 1] }), 500) + const response = await fetch(`/api/v1/reviews/${id}`, { + method: 'PUT', + body: JSON.stringify(data), + headers: { 'Content-Type': 'application/json' }, + }); + + if (!response.ok) { + const { messages } = (await response.json()) as HttpErrorResponse; + + // TODO: build proper error message + console.error( + `status: ${response.status}\nstatusText: ${response.statusText}\nmessages:\n${messages.join('\n')}` ); + + throw new Error('네트워크 오류가 발생했습니다. 다시 시도해주세요.'); } + + return (await response.json()) as UpdateReviewResponse; } diff --git a/ui/src/lib/apis/review/server.ts b/ui/src/lib/apis/review/server.ts index fbd98b86..5e03c0cb 100644 --- a/ui/src/lib/apis/review/server.ts +++ b/ui/src/lib/apis/review/server.ts @@ -7,7 +7,6 @@ import type { ListReviewsQuery, ListReviewsResponse, } from '@/lib/definitions/review'; -import dummyReviewList from '@/lib/dummy/review'; export async function listReviews(query: ListReviewsQuery): Promise { noStore(); @@ -20,43 +19,27 @@ export async function listReviews(query: ListReviewsQuery): Promise setTimeout(() => resolve(dummyReviewList), 1000)); + if (!response.ok) { + throw new Error( + `Network Error: Failed to fetch reviews list from BACKEND API: ${response.statusText}` + ); } + + return (await response.json()) as ListReviewsResponse; } export async function getReview(id: string): Promise { noStore(); - try { - const response = await fetch(`${process.env.BACKEND_URL}/api/v1/reviews/${id}`); - - if (!response.ok) { - throw new Error( - `Network Error: Failed to fetch review from BACKEND API: ${response.statusText}` - ); - } + const response = await fetch(`${process.env.BACKEND_URL}/api/v1/reviews/${id}`); - return (await response.json()) as GetReviewResponse; - } catch (error) { - // TODO: DELETE ME when reviews api works - return await new Promise((resolve) => - setTimeout(() => resolve({ review: dummyReviewList.reviews[Number(id) - 1] }), 1000) + if (!response.ok) { + throw new Error( + `Network Error: Failed to fetch review from BACKEND API: ${response.statusText}` ); } + + return (await response.json()) as GetReviewResponse; }