From 932d9725575ae06e8f7fa433fca229cc0b88726e Mon Sep 17 00:00:00 2001 From: gs0428 Date: Tue, 13 Feb 2024 15:34:24 +0900 Subject: [PATCH] =?UTF-8?q?feature-060:=20=EB=B9=84=EB=94=94=EC=98=A4=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20API=20=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/videos.ts | 8 ++++++++ src/pages/CategoryPage.tsx | 29 ++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/apis/videos.ts b/src/apis/videos.ts index 9fea94c..6cf2828 100644 --- a/src/apis/videos.ts +++ b/src/apis/videos.ts @@ -2,6 +2,7 @@ import { APIResponse } from '@/models/config/axios'; import { IVideo, VideoVersionType } from '@/models/video'; import axios from './config/instance'; +import axiosInstance from './config/instance'; const PREFIX = '/videos'; @@ -11,3 +12,10 @@ export const getVideoAPI = ( ) => { return axios.get>(PREFIX + `/${videoId}/${versionId}`); }; + +export const deleteVideos = async (videos: number[]) => { + const response = await axiosInstance.delete('/videos/selectDelete', { + data: { videos }, + }); + return response.data; +}; diff --git a/src/pages/CategoryPage.tsx b/src/pages/CategoryPage.tsx index 8e8167d..a11a17f 100644 --- a/src/pages/CategoryPage.tsx +++ b/src/pages/CategoryPage.tsx @@ -13,6 +13,7 @@ import { useRecoilValue } from 'recoil'; import { categoryState } from '@/stores/category'; import { ISubFolderProps } from 'types/category'; import EmptyCard from '@/components/category/EmptyCard'; +import { deleteVideos } from '@/apis/videos'; const CategoryPage = () => { const params = useParams(); @@ -46,11 +47,22 @@ const CategoryPage = () => { } }, [categories, params.top_folder]); - const allCheckBtnHandler = () => { - if (checkedVideos.length === videos.length) { - // 삭제 API 요청 - console.log('모두 삭제'); + const handleDeleteVideos = async () => { + const res = await deleteVideos(checkedVideos); + if (res.isSuccess) { + const existVideos = videos.filter( + (video) => !checkedVideos.includes(video.video_id), + ); + setVideos(existVideos); setCheckedVideos([]); + } else { + alert('비디오를 삭제하는데 실패했습니다.'); + } + }; + + const allCheckBtnHandler = async () => { + if (checkedVideos.length === videos.length) { + handleDeleteVideos(); } else { console.log('모두 선택'); setCheckedVideos(videos.map((video) => video.video_id)); @@ -60,10 +72,7 @@ const CategoryPage = () => { const dirMoveHanlder = () => { console.log(checkedVideos); }; - - const garbageHandler = () => { - console.log(checkedVideos); - }; + console.log(videos); return ( @@ -90,7 +99,9 @@ const CategoryPage = () => { - +