Skip to content

Commit

Permalink
feat: implement getReview
Browse files Browse the repository at this point in the history
  • Loading branch information
2wheeh committed Mar 13, 2024
1 parent 4caa4ee commit e41a161
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 26 additions & 1 deletion ui/src/lib/apis/review/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import { unstable_noStore as noStore } from 'next/cache';

import type { ListReviewsQuery, ListReviewsResponse } from '@/lib/definitions/review';
import type {
GetReviewResponse,
ListReviewsQuery,
ListReviewsResponse,
} from '@/lib/definitions/review';
import dummyReviewList from '@/lib/dummy/review';

export async function listReviews(query: ListReviewsQuery): Promise<ListReviewsResponse> {
Expand Down Expand Up @@ -35,3 +39,24 @@ export async function listReviews(query: ListReviewsQuery): Promise<ListReviewsR
return await new Promise((resolve) => setTimeout(() => resolve(dummyReviewList), 1000));
}
}

export async function getReview(id: string): Promise<GetReviewResponse> {
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}`
);
}

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

export interface GetReviewResponse {
review: Review;
}

0 comments on commit e41a161

Please sign in to comment.