feat: 댓글 수정, 삭제 기능
This commit is contained in:
@@ -2,11 +2,13 @@ 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 {
|
||||
@@ -26,6 +28,32 @@ export class CommentApiService implements CommentService {
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
public async updateComment(
|
||||
bbsId: number,
|
||||
pstNo: number,
|
||||
cmntNo: number,
|
||||
data: CommentUpdateFormData,
|
||||
): Promise<Comment> {
|
||||
const validatedData = commentUpdateFormSchema.parse(data);
|
||||
const response = await client.put<Comment>(
|
||||
`${ENDPOINT.BOARD_SERVICE.POSTS_COMMENTS}/${bbsId}/${pstNo}/${cmntNo}`,
|
||||
validatedData,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
public async deleteComment(
|
||||
bbsId: number,
|
||||
pstNo: number,
|
||||
cmntNo: number,
|
||||
cmntPswd: string,
|
||||
): Promise<Comment> {
|
||||
const response = await client.delete<Comment>(
|
||||
`${ENDPOINT.BOARD_SERVICE.POSTS_COMMENTS}/${bbsId}/${pstNo}/${cmntNo}?cmntPswd=${cmntPswd}`,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
export const CommentApi = new CommentApiService();
|
||||
|
||||
@@ -6,4 +6,5 @@ export {
|
||||
type CommentList,
|
||||
type CommentParams,
|
||||
type CommentFormData,
|
||||
type CommentUpdateFormData,
|
||||
} from "./model/comment-interface";
|
||||
|
||||
@@ -18,6 +18,7 @@ export interface Comment {
|
||||
rgtr: string;
|
||||
mdfcnDt: string;
|
||||
mdfr: string;
|
||||
delYn: string;
|
||||
}
|
||||
|
||||
export const commentFormSchema = z.object({
|
||||
@@ -39,16 +40,16 @@ export type CommentUpdateFormData = z.infer<typeof commentUpdateFormSchema>;
|
||||
export interface CommentService {
|
||||
getComments(params: CommentParams): Promise<CommentList>;
|
||||
createComment(data: CommentFormData): Promise<Comment>;
|
||||
// updateComment(
|
||||
// bbsId: number,
|
||||
// pstNo: number,
|
||||
// cmntNo: number,
|
||||
// data: CommentUpdateFormData,
|
||||
// ): Promise<Comment>;
|
||||
// deleteComment(
|
||||
// bbsId: number,
|
||||
// pstNo: number,
|
||||
// cmntNo: number,
|
||||
// cmntPswd: string,
|
||||
// ): Promise<void>;
|
||||
updateComment(
|
||||
bbsId: number,
|
||||
pstNo: number,
|
||||
cmntNo: number,
|
||||
data: CommentUpdateFormData,
|
||||
): Promise<Comment>;
|
||||
deleteComment(
|
||||
bbsId: number,
|
||||
pstNo: number,
|
||||
cmntNo: number,
|
||||
cmntPswd: string,
|
||||
): Promise<Comment>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user