Skip to content

Commit

Permalink
feat: add listReviews
Browse files Browse the repository at this point in the history
  • Loading branch information
2wheeh committed Feb 26, 2024
1 parent aa58906 commit ab297fd
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 ab297fd

Please sign in to comment.