Skip to content

Commit

Permalink
Merge pull request #204 from MovieReviewComment/feature/issue-162/get…
Browse files Browse the repository at this point in the history
…-reviews-list

[#162] implement listReviews
  • Loading branch information
2wheeh authored Feb 27, 2024
2 parents 8f5cbe2 + ab297fd commit be5e2af
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions ui/src/lib/apis/review/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use server';

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

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

export async function listReviews(query: ListReviewsQuery): Promise<ListReviewsResponse> {
noStore();

const params = Object.entries(query).reduce((acc, [key, value]) => {
if (value) {
acc.set(key, String(value));
}

return acc;
}, new URLSearchParams());

try {
const response = await fetch(`${process.env.BACKEND_URL}/api/v1/reviews?${params.toString()}`);

if (!response.ok) {
throw new Error(
`Network Error: Failed to fetch reviews list from BACKEND API: ${response.statusText}`
);
}

return (await response.json()) as ListReviewsResponse;
} catch (error) {
// TODO: handle error
// console.error('Fetch Error:', error);
// throw new Error('Internal Server Error: Failed to fetch reviews list');

// TODO: DELETE ME when reviews api works
return await new Promise((resolve) => setTimeout(() => resolve(dummyReviewList), 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 @@ -23,3 +23,7 @@ export interface ListReviewsResponse {
pagination: Pagination;
filter?: ReviewFilter;
}

export interface ListReviewsQuery
extends ReviewFilter,
Partial<Omit<Pagination, 'totalPageCount'>> {}

0 comments on commit be5e2af

Please sign in to comment.