diff --git a/controllers/photoController.js b/controllers/photoController.js index 76fc3e1..de3cace 100644 --- a/controllers/photoController.js +++ b/controllers/photoController.js @@ -145,4 +145,17 @@ const getPhoto = async (req, res) => { } }; -module.exports = { createTemp, updateInfo, updateRecord, savePhoto, deletePhoto, getPhoto }; \ No newline at end of file +const sharePhoto = async (req, res) => { + const { photo_id } = req.params; + try { + const photo = await Photo.findByPk(photo_id); + if (!photo) { + res.status(404).json({ status: 'fail', message: '사진을 찾을 수 없습니다.'}); + } + res.status(200).json({ status: "success",shareLink: photo.image_url }); + } catch (error) { + res.status(500).json({ status: 'fail', message: " 공유 링크 생성 실패"}); + } +} + +module.exports = { createTemp, updateInfo, updateRecord, savePhoto, deletePhoto, getPhoto, sharePhoto }; \ No newline at end of file diff --git a/routes/photoRouter.js b/routes/photoRouter.js index 2357b8f..3b3c5a3 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 } = require('../controllers/photoController'); +const { createTemp, updateInfo, updateRecord, savePhoto, deletePhoto, getPhoto, sharePhoto } = require('../controllers/photoController'); // 사진 등록용 라우트 1: 사용자id와 사진url 저장 (photoTemp 테이블) router.post('/temp/upload/qr', uploadImageByQR, uploadOneImageUrl, createTemp); // 1) QR 업로드 @@ -20,6 +20,9 @@ router.post('/save/:photoTemp_id', savePhoto); // 사진 삭제용 라우트 router.delete('/delete/:photo_id', deletePhoto); +// 사진 공유 +router.get('/share/:photo_id', sharePhoto); + // 사진 조회용 라우트 router.get('/:photo_id', getPhoto);