-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters