import { client } from "@/shared/api"; import { ENDPOINT } from "@/shared/config"; import { commentFormSchema, commentUpdateFormSchema, type Comment, type CommentService, type CommentList, type CommentParams, type CommentFormData, type CommentUpdateFormData, } from "../model/comment-interface"; export class CommentApiService implements CommentService { public async getComments(params: CommentParams): Promise { const response = await client.get( `${ENDPOINT.BOARD_SERVICE.POSTS_COMMENTS}`, { params }, ); return response.data; } public async createComment(data: CommentFormData): Promise { const validatedData = commentFormSchema.parse(data); const response = await client.post( `${ENDPOINT.BOARD_SERVICE.POSTS_COMMENTS}`, validatedData, ); return response.data; } public async updateComment( bbsId: number, pstNo: number, cmntNo: number, data: CommentUpdateFormData, ): Promise { const validatedData = commentUpdateFormSchema.parse(data); const response = await client.put( `${ENDPOINT.BOARD_SERVICE.POSTS_COMMENTS}/${bbsId}/${pstNo}/${cmntNo}`, validatedData, ); return response.data; } public async deleteComment( bbsId: number, pstNo: number, cmntNo: number, cmntPswd: string, ): Promise { const response = await client.delete( `${ENDPOINT.BOARD_SERVICE.POSTS_COMMENTS}/${bbsId}/${pstNo}/${cmntNo}`, { params: { cmntPswd } }, ); return response.data; } } export const CommentApi = new CommentApiService();