diff --git a/src/controllers/MumentController.ts b/src/controllers/MumentController.ts index 8fc1d8f..84400f9 100644 --- a/src/controllers/MumentController.ts +++ b/src/controllers/MumentController.ts @@ -19,9 +19,11 @@ const createMument = async (req: Request, res: Response) => { try { const data: PostBaseResponseDto | null = await MumentService.createMument(userId, musicId, mumentCreateDto); - if (!data) res.status(statusCode.NOT_FOUND).send(util.fail(statusCode.NOT_FOUND, message.NOT_FOUND_ID)); - - res.status(statusCode.CREATED).send(util.success(statusCode.CREATED, message.CREATE_MUMENT_SUCCESS, data)); + if (!data) { + res.status(statusCode.NOT_FOUND).send(util.fail(statusCode.NOT_FOUND, message.NOT_FOUND_ID)); + } else { + res.status(statusCode.CREATED).send(util.success(statusCode.CREATED, message.CREATE_MUMENT_SUCCESS, data)); + } } catch (error) { console.log(error); @@ -81,6 +83,24 @@ const getMument = async (req: Request, res: Response) => { } }; +/** + * @ROUTE DELETE /:mumentId + * @DESC Delete Mument + */ +const deleteMument = async (req: Request, res: Response) => { + const { mumentId } = req.params; + + try { + const data = await MumentService.deleteMument(mumentId); + + res.status(statusCode.NO_CONTENT).send(util.success(statusCode.NO_CONTENT, message.DELETE_MUMENT_SUCCESS)); + } catch (error) { + console.log(error); + + res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, message.INTERNAL_SERVER_ERROR)); + } +}; + /** * @ROUTE GET /mument/:userId/:musicId/is-first * @DESC 특정 음악에 대해 뮤멘트 기록하기 전 처음/다시 태그 판단 @@ -195,8 +215,7 @@ const deleteLike = async (req: Request, res: Response) => { res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, message.DELETE_LIKE_FAIL)); } - res.status(statusCode.OK).send(util.success(statusCode.OK, message.DELETE_LIKE_SUCCESS, data)); - + res.status(statusCode.OK).send(util.success(statusCode.OK, message.DELETE_LIKE_SUCCESS)); } catch (error) { console.log(error); res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, message.INTERNAL_SERVER_ERROR)); @@ -207,6 +226,7 @@ export default { createMument, updateMument, getMument, + deleteMument, getIsFirst, getMumentHistory, createLike, diff --git a/src/modules/responseMessage.ts b/src/modules/responseMessage.ts index 8a661c1..b259cb9 100644 --- a/src/modules/responseMessage.ts +++ b/src/modules/responseMessage.ts @@ -17,6 +17,7 @@ const message = { CREATE_MUMENT_SUCCESS: '뮤멘트 기록하기 성공', UPDATE_MUMENT_SUCCESS: '뮤멘트 수정하기 성공', READ_MUMENT_SUCEESS: '뮤멘트 상세보기 성공', + DELETE_MUMENT_SUCCESS: '뮤멘트 삭제하기 성공', NOT_YOUR_MUMENT: '비밀글 입니다', READ_MUMENT_HISTORY_SUCCESS: '뮤멘트 히스토리 조회 성공', CREATE_LIKE_SUCCESS: '좋아요 등록 성공', diff --git a/src/routes/MumentRouter.ts b/src/routes/MumentRouter.ts index baeaf38..ac19fd0 100644 --- a/src/routes/MumentRouter.ts +++ b/src/routes/MumentRouter.ts @@ -14,6 +14,8 @@ router.put('/:mumentId', [ router.get('/:mumentId/:userId', MumentController.getMument); router.get('/:userId/:musicId/is-first', MumentController.getIsFirst); +router.delete('/:mumentId', MumentController.deleteMument); + // 히스토리 조회 router.get('/:userId/:musicId/history', [ param('musicId').isString().isLength({ min: 24, max: 24 }), diff --git a/src/services/MumentService.ts b/src/services/MumentService.ts index 266cbc9..5a42f02 100644 --- a/src/services/MumentService.ts +++ b/src/services/MumentService.ts @@ -185,6 +185,31 @@ const getMument = async (mumentId: string, userId: string): Promise => { + try { + const mument = await Mument.findById(mumentId); + if (!mument) return null; + + //Mument soft delete + await Mument.findByIdAndUpdate(mumentId, { + $set: { + isDeleted: true, + }, + }); + + //Like에서 Mument 제거 + await Like.updateMany( + {}, + { + $pull: { mument: { _id: mumentId } }, + }, + ); + } catch (error) { + console.log(error); + throw error; + } +}; + const getIsFirst = async (userId: string, musicId: string): Promise => { try { const music = await Music.findById(musicId); @@ -408,6 +433,7 @@ export default { createMument, updateMument, getMument, + deleteMument, getIsFirst, getMumentHistory, createLike,