From ac0c113683ea1d310ee9e78b9ea179c6b248b143 Mon Sep 17 00:00:00 2001 From: sooieese Date: Thu, 7 Nov 2024 11:03:27 +0900 Subject: [PATCH] =?UTF-8?q?feat:=EC=82=AC=EC=A7=84=EC=A2=8B=EC=95=84?= =?UTF-8?q?=EC=9A=94=ED=86=A0=EA=B8=80api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/photoController.js | 29 ++++++++++++++++-- docs/openapi.yaml | 2 ++ docs/photo-toggleLike.yaml | 54 ++++++++++++++++++++++++++++++++++ routes/photoRouter.js | 7 +++-- 4 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 docs/photo-toggleLike.yaml diff --git a/controllers/photoController.js b/controllers/photoController.js index 1aa7b26..0e9f725 100644 --- a/controllers/photoController.js +++ b/controllers/photoController.js @@ -225,7 +225,7 @@ const getBoothVisit = async (req, res) => { }; -// 사진 즐겨찾기 +// 사진 무조건 즐겨찾기 const photoLike = async (req, res) => { try { const { photo_id } = req.params; @@ -249,5 +249,30 @@ const photoLike = async (req, res) => { } }; -module.exports = { createTemp, updateInfo, updateRecord, savePhoto, deletePhoto, getPhoto, sharePhoto , getBooth, getBoothVisit, photoLike }; + +// 사진 즐겨찾기 +const photoToggleLike = async (req, res) => { + try { + const { photo_id } = req.params; + + const photo = await Photo.findByPk(photo_id); + if (!photo) { + res.status(404).json({ status: 'fail', message: '사진을 찾을 수 없습니다.'}); + } + + photo.photo_like = !photo.photo_like; + await photo.save(); + + return res.status(200).json({ + photo_id: photo.id, + photo_like: photo.photo_like, + }, + ); + } catch (error) { + console.error('photoLike Error', error); + res.status(500).json({ status: 'fail', message: "즐겨찾기 업데이트 실패"}); + } +}; + +module.exports = { createTemp, updateInfo, updateRecord, savePhoto, deletePhoto, getPhoto, sharePhoto , getBooth, getBoothVisit, photoLike , photoToggleLike}; diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 1f0d3f6..9826345 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -29,6 +29,8 @@ paths: $ref: './album.yaml' /api/photo/like/{photo_id}: $ref: './photo-like.yaml' + /api/photo/toggleLike/{photo_id}: + $ref: './photo-like.yaml' /api/photo/{photo_id}: $ref: './get-photo.yaml' /api/photo/temp/upload/qr: diff --git a/docs/photo-toggleLike.yaml b/docs/photo-toggleLike.yaml new file mode 100644 index 0000000..7abb1e7 --- /dev/null +++ b/docs/photo-toggleLike.yaml @@ -0,0 +1,54 @@ +post: + tags: + - Photo + summary: "사진 즐겨찾기 토글" + description: "특정 사진의 즐겨찾기 상태를 반대로 변경합니다. 사진이 즐겨찾기에 등록되어 있으면 해제하고, 해제되어 있으면 등록합니다." + parameters: + - in: path + name: photo_id + required: true + schema: + type: integer + description: "즐겨찾기 상태를 변경할 사진의 ID" + responses: + 200: + description: "즐겨찾기 상태가 성공적으로 업데이트되었습니다." + content: + application/json: + schema: + type: object + properties: + photo_id: + type: integer + description: "즐겨찾기 상태가 업데이트된 사진의 ID" + example: 1 + photo_like: + type: boolean + description: "변경된 즐겨찾기 상태" + example: true + 404: + description: "해당 ID의 사진이 존재하지 않는 경우" + content: + application/json: + schema: + type: object + properties: + status: + type: string + example: "fail" + message: + type: string + example: "사진을 찾을 수 없습니다." + 500: + description: "서버 오류 발생 시" + content: + application/json: + schema: + type: object + properties: + status: + type: string + example: "fail" + message: + type: string + example: "즐겨찾기 업데이트 실패" diff --git a/routes/photoRouter.js b/routes/photoRouter.js index dc7a6a9..d567037 100644 --- a/routes/photoRouter.js +++ b/routes/photoRouter.js @@ -2,7 +2,7 @@ const express = require('express'); const router = express.Router(); const { uploadOneImageUrl, uploadOneImage } = require('../middlewares/s3'); const { uploadImageByQR } = require('../middlewares/uploadPhoto'); -const { createTemp, updateInfo, updateRecord, savePhoto, deletePhoto, getPhoto, sharePhoto, getBooth, photoLike } = require('../controllers/photoController'); +const { createTemp, updateInfo, updateRecord, savePhoto, deletePhoto, getPhoto, sharePhoto, getBooth, photoLike, photoToggleLike } = require('../controllers/photoController'); // 사진 등록용 라우트 1: 사용자id와 사진url 저장 (photoTemp 테이블) router.post('/temp/upload/qr', uploadImageByQR, uploadOneImageUrl, createTemp); // 1) QR 업로드 @@ -29,7 +29,10 @@ router.get('/share/:photo_id', sharePhoto); // 사진 조회용 라우트 router.get('/:photo_id', getPhoto); -// 사진 즐겨찾기 등록,해제 라우트 +// 사진 즐겨찾기 true만 라우트 router.post('/like/:photo_id', photoLike); +// 사진 즐겨찾기 등록, 해제 라우트 +router.post('/toggleLike/:photo_id', photoToggleLike); + module.exports = router;