| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 'use server';
- import CommentListRequest from '@/dtos/request/forum/comment/commentListRequest';
- import CommentListResponse from '@/dtos/response/forum/comment/commentListResponse';
- import CommentCreateResponse from '@/dtos/response/forum/comment/commentCreateResponse';
- import CommentUpdateResponse from '@/dtos/response/forum/comment/commentUpdateResponse';
- import { ResultDto } from '@/dtos/response/common';
- import { fetchJson } from '@/lib/utils/server';
- // 댓글 목록 조회
- export async function fetchCommentList(params: CommentListRequest): Promise<ResultDto<CommentListResponse>> {
- const queryParams = new URLSearchParams();
- queryParams.set('postID', String(params.postID));
- queryParams.set('pageNum', String(params.page));
- if (params.perPage) queryParams.set('perPage', String(params.perPage));
- if (params.sort !== undefined) queryParams.set('sort', String(params.sort));
- return await fetchJson<CommentListResponse>(`/api/forum/comments?${queryParams.toString()}`, {
- method: 'GET',
- headers: {'Accept': 'application/json'}
- });
- }
- // 댓글/답글 등록
- export async function fetchCommentCreate(formData: FormData): Promise<ResultDto<CommentCreateResponse>> {
- return await fetchJson<CommentCreateResponse>('/api/forum/comments', {
- method: 'POST',
- headers: {'Accept': 'application/json'},
- body: formData
- });
- }
- // 댓글/답글 수정
- export async function fetchCommentUpdate(commentID: number, formData: FormData): Promise<ResultDto<CommentUpdateResponse>> {
- return await fetchJson<CommentUpdateResponse>(`/api/forum/comments/${commentID}`, {
- method: 'PUT',
- headers: {'Accept': 'application/json'},
- body: formData
- });
- }
- // 댓글/답글 삭제
- export async function fetchCommentDelete(commentID: number): Promise<ResultDto> {
- return await fetchJson(`/api/forum/comments/${commentID}`, {
- method: 'DELETE',
- headers: {'Accept': 'application/json'}
- });
- }
|