feat: 콘텐츠 삭제 작업

This commit is contained in:
2025-04-18 16:04:22 +09:00
parent 1b0e310513
commit c6814a65f9
3 changed files with 24 additions and 12 deletions
@@ -59,8 +59,13 @@ export class ContentsApiService implements ContentsService {
return response.data;
}
public async deleteContents(contsSn: number): Promise<void> {
await client.delete(`${ENDPOINT.CMS_SERVICE.CONTENTS}/${contsSn}`);
public async deleteContents(
contsSn: number,
contsVer: number,
): Promise<void> {
await client.delete(
`${ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS}/${contsSn}/${contsVer}`,
);
}
}
@@ -90,5 +90,5 @@ export interface ContentsService {
contsVer: number,
data: ContentsFormData,
): Promise<void>;
deleteContents(contsSn: number): Promise<void>;
deleteContents(contsSn: number, contsVer: number): Promise<void>;
}
+16 -9
View File
@@ -34,7 +34,7 @@ function ModifyPage({ sequential }: { sequential: string }) {
queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, sequential],
queryFn: () =>
ContentsApi.getContentsVersionList({
contsSn: Number(sequential),
contsSn: contsSn,
page: 0,
size: 100,
}),
@@ -42,8 +42,7 @@ function ModifyPage({ sequential }: { sequential: string }) {
const { data: contentsDetail } = useQuery({
queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, contentsVersion],
queryFn: () =>
ContentsApi.getLatestContentsInfo(Number(sequential), contentsVersion),
queryFn: () => ContentsApi.getLatestContentsInfo(contsSn, contentsVersion),
enabled: !!contentsVersion,
});
@@ -59,21 +58,28 @@ function ModifyPage({ sequential }: { sequential: string }) {
const { mutateAsync: updateContents } = useMutation({
mutationFn: (data: ContentsFormData) =>
ContentsApi.updateContents(
Number(sequential),
contentsDetail?.contsVer ?? 0,
data,
),
ContentsApi.updateContents(contsSn, contentsDetail?.contsVer ?? 0, data),
onSuccess: () => {
alert("수정되었습니다.");
},
});
const { mutateAsync: deleteContents } = useMutation({
mutationFn: () => ContentsApi.deleteContents(contsSn, contentsVersion),
onSuccess: () => {
alert("삭제되었습니다.");
queryClient.invalidateQueries({
queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, sequential],
});
},
});
const form = useForm<ContentsFormData>({
resolver: zodResolver(contentsFormSchema),
values: contentsDetail,
});
const contsSn = Number(sequential);
const isApprovedContents =
contentsDetail?.aprvCd === CONTENTS_APPROVAL_STATUS.APPROVED;
@@ -120,9 +126,10 @@ function ModifyPage({ sequential }: { sequential: string }) {
</div>
<ContentsForm
form={form}
contsSn={Number(sequential)}
contsSn={contsSn}
disabledFields={disabledFields}
handleSave={isApprovedContents ? createContents : updateContents}
handleDelete={deleteContents}
/>
</div>
);