Skip to content

Commit

Permalink
feat: 포토부스 즐겨찾기 라우트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyou10 committed Nov 5, 2024
1 parent 4797c9b commit e64c293
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
42 changes: 31 additions & 11 deletions controllers/boothLikeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,44 @@ const User = require('../models/user');
const Photobooth = require('../models/photobooth');

// 부스 즐겨찾기 추가
const addBoothLike = async(user_id, photobooth_id) => {
const user = User.findByPk(user_id);
const booth = Photobooth.findByPk(photobooth_id);
const addBoothLike = async(req, res) => {
try {
const { user_id, photobooth_id } = req.body;
const user = User.findByPk(user_id);
const booth = Photobooth.findByPk(photobooth_id);

if (user && booth) {
await user.addLikedBooths(booth);
console.log('포토부스가 즐겨찾기 되었습니다.');
if (user && booth) {
await user.addLikedBooths(booth);
console.log('포토부스가 즐겨찾기 되었습니다.');
res.status(200).json({message: '포토부스가 즐겨찾기 되었습니다.'});
}
else {
res.status(400).json({message: '존재하지 않는 유저거나 존재하지 않는 부스입니다.'});
}
} catch(error) {
console.error(error);
res.status(500).json({message: '즐겨찾기에 실패했습니다.'});
}
};

// 부스 즐겨찾기 삭제
const deleteBoothLike = async(user_id, photobooth_id) => {
const user = User.findByPk(user_id);
const booth = Photobooth.findByPk(photobooth_id);
try {
const { user_id, photobooth_id } = req.body;

if (user && booth) {
await user.removeLikedBooths(booth);
console.log('포토부스가 즐겨찾기 해제 되었습니다.');
const user = User.findByPk(user_id);
const booth = Photobooth.findByPk(photobooth_id);

if (user && booth) {
await user.removeLikedBooths(booth);
console.log('포토부스가 즐겨찾기 해제 되었습니다.');
res.status(200).json({message: '포토부스가 즐겨찾기 해제 되었습니다.'});
} else {
res.status(400).json({message: '존재하지 않는 유저거나 존재하지 않는 부스입니다.'});
}
} catch (error) {
console.error(error);
res.status(500).json({message: '즐겨찾기 해제에 실패했습니다.'});
}
};

Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ app.use('/api/map', mapRouter);
const photoRouter = require('./routes/photoRouter');
app.use('/api/photo', photoRouter);

const boothLikeRouter = require('./routes/boothLikeRouter');
app.use('/api/booth', boothLikeRouter);

// 스웨거 세팅
const swaggerUi = require('swagger-ui-express');
const YAML = require('yamljs');
Expand Down
11 changes: 11 additions & 0 deletions routes/boothLikeRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require('express');
const router = express.Router();
const { addBoothLike, deleteBoothLike, readBoothLike } = require('../controllers/boothLikeController');

// 즐겨찾기 등록 라우트
router.post('/', addBoothLike);

// 즐겨찾기 삭제 라우트
router.delete('/', deleteBoothLike);

module.exports = router;
4 changes: 4 additions & 0 deletions routes/userRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express');
const router = express.Router();
const { getUserById, updateUser, deleteUser } = require('../controllers/userController');
const { uploadFiveImages} = require('../middlewares/s3');
const { readBoothLike } = require('../controllers/boothLikeController');

// (마이페이지) 회원 조회 라우터
router.get('/:user_id', getUserById);
Expand All @@ -12,4 +13,7 @@ router.put('/:user_id',uploadFiveImages, updateUser);
// 회원 탈퇴 라우터
router.delete('/:user_id', deleteUser);

// 회원이 즐겨찾기 한 포토부스 조회
router.get('/:user_id/booth-like', readBoothLike);

module.exports = router;

0 comments on commit e64c293

Please sign in to comment.