Skip to content

Commit

Permalink
Merge pull request #283 from MovieReviewComment/feature/issue-268/upd…
Browse files Browse the repository at this point in the history
…ate-review

[#268] Implement updateReview
  • Loading branch information
2wheeh authored Mar 14, 2024
2 parents 2a69966 + c97734e commit f307e12
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
37 changes: 36 additions & 1 deletion ui/src/lib/apis/review/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
'use client';

import type { HttpErrorResponse } from '@/lib/definitions/error';
import type { CreateReviewRequest, CreateReviewResponse } from '@/lib/definitions/review';
import type {
CreateReviewRequest,
CreateReviewResponse,
UpdateReviewRequest,
UpdateReviewResponse,
} from '@/lib/definitions/review';
import dummyReviewList from '@/lib/dummy/review';

export async function createReview(data: CreateReviewRequest): Promise<CreateReviewResponse> {
Expand Down Expand Up @@ -30,3 +35,33 @@ export async function createReview(data: CreateReviewRequest): Promise<CreateRev
);
}
}

export async function updateReview(
id: number,
data: UpdateReviewRequest
): Promise<UpdateReviewResponse> {
try {
const response = await fetch(`/api/v1/reviews/${id}`, {
method: 'PUT',
body: JSON.stringify(data),
});

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)
);
}
}
10 changes: 10 additions & 0 deletions ui/src/lib/definitions/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,13 @@ export interface CreateReviewResponse {
export interface GetReviewResponse {
review: Review;
}

export interface UpdateReviewRequest {
title: string;
movieName: string;
content: string;
}

export interface UpdateReviewResponse {
review: Review;
}

0 comments on commit f307e12

Please sign in to comment.