Skip to content

Commit

Permalink
Merge pull request #41 from 9oormthonUniv-seoultech/docs/#34
Browse files Browse the repository at this point in the history
feat:사진좋아요토글api
  • Loading branch information
sooieese00 authored Nov 7, 2024
2 parents a4bd7b5 + ac0c113 commit 51b8f90
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 4 deletions.
29 changes: 27 additions & 2 deletions controllers/photoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const getBoothVisit = async (req, res) => {
};


// 사진 즐겨찾기
// 사진 무조건 즐겨찾기
const photoLike = async (req, res) => {
try {
const { photo_id } = req.params;
Expand All @@ -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};

2 changes: 2 additions & 0 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
54 changes: 54 additions & 0 deletions docs/photo-toggleLike.yaml
Original file line number Diff line number Diff line change
@@ -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: "즐겨찾기 업데이트 실패"
7 changes: 5 additions & 2 deletions routes/photoRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 업로드
Expand All @@ -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;

0 comments on commit 51b8f90

Please sign in to comment.