Skip to content

Commit

Permalink
Merge pull request #329 from MovieReviewComment/feature/issue-327/ser…
Browse files Browse the repository at this point in the history
…ver-apis

[#327] Add listComments
  • Loading branch information
2wheeh authored Apr 14, 2024
2 parents 3ff5179 + e5eb363 commit 39b641c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ui/src/lib/apis/comment/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use server';

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

import type { ListCommentsQuery, ListCommentsResponse } from '@/lib/definitions/comment';

export async function listComments(query: ListCommentsQuery): Promise<ListCommentsResponse> {
noStore();

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

return acc;
}, new URLSearchParams());

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

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

return (await response.json()) as ListCommentsResponse;
}

0 comments on commit 39b641c

Please sign in to comment.