From f8958f7ead4fdbfa5693dabb2bd7a1504f3b9c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=B0=AC=ED=98=B8?= Date: Thu, 23 Sep 2021 17:03:56 +0900 Subject: [PATCH 1/9] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20user=20schema?= =?UTF-8?q?=EC=97=90=EC=84=9C=20oauthToken=20column=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=20githubId=20column=EC=9C=BC=EB=A1=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit token을 저장하는 것은 유효 기간이 있어서 사용 불가하므로 github id로 대체 --- backend/src/models/user.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/models/user.js b/backend/src/models/user.js index 234ac2d..ded305e 100644 --- a/backend/src/models/user.js +++ b/backend/src/models/user.js @@ -6,8 +6,7 @@ const userSchema = new Schema({ nickName: String, email: String, teamIds: Array, - oauthToken : String, - githubId: String + githubId : String, }); module.exports = mongoose.model('User', userSchema); \ No newline at end of file From d7e7f404705e193ce694f4661918555753896326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=B0=AC=ED=98=B8?= Date: Thu, 23 Sep 2021 17:14:56 +0900 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=91=94=20=EC=8A=A4=ED=84=B0=EB=94=94?= =?UTF-8?q?=20=EA=B7=B8=EB=A3=B9=EC=9D=98=20=EC=83=9D=EC=84=B1=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20Team=20=EC=83=9D=EC=84=B1=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/services/team/team.js | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 backend/src/services/team/team.js diff --git a/backend/src/services/team/team.js b/backend/src/services/team/team.js new file mode 100644 index 0000000..cc45027 --- /dev/null +++ b/backend/src/services/team/team.js @@ -0,0 +1,33 @@ +const Team = require("../../models/team"); + +const createTeam = async (req, res, next) => { + try{ + await Team.create({...req.body}); + await res.status(201).json({ + code: '2001', + status: '성공 : Team 생성', + message: 'Team이 정상적으로 생성되었습니다.' + }); + } + catch(err){ + console.error(err); + await res.status(500).json({ + code: '5000', + status: '에러 : 서버 에러', + message : '요청 처리 중 서버에서 문제가 발생했습니다.' + }); + } +}; + + +const deleteTeam = async (req, res, next) => { + +}; + +const updateTeam = async (req, res, next) => { + +}; + +const searchTeams = async (req, res, next) => { + +}; \ No newline at end of file From 596c61b431ecbb0e884b86b355be94b5c4f1c094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=B0=AC=ED=98=B8?= Date: Thu, 23 Sep 2021 17:24:29 +0900 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=91=94=20=EC=8A=A4=ED=84=B0=EB=94=94?= =?UTF-8?q?=20=EA=B7=B8=EB=A3=B9=20=EC=82=AD=EC=A0=9C=EB=A5=BC=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20teamId=EA=B0=80=20=EC=9D=BC=EC=B9=98=ED=95=98?= =?UTF-8?q?=EB=8A=94=20team=20=EC=82=AD=EC=A0=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/services/team/team.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/backend/src/services/team/team.js b/backend/src/services/team/team.js index cc45027..04ad90e 100644 --- a/backend/src/services/team/team.js +++ b/backend/src/services/team/team.js @@ -14,20 +14,46 @@ const createTeam = async (req, res, next) => { await res.status(500).json({ code: '5000', status: '에러 : 서버 에러', - message : '요청 처리 중 서버에서 문제가 발생했습니다.' + message : '생성 요청 처리 중 서버에서 문제가 발생했습니다.' }); } }; const deleteTeam = async (req, res, next) => { - + try{ + const teamId = req.params['teamId']; + await Team.findByIdAndDelete(teamId); + await res.status(200).json({ + code: '2000', + status: '성공 : Team 삭제', + message: 'Team이 정상적으로 삭제되었습니다.' + }); + } + catch{ + console.error(err); + await res.status(500).json({ + code: '5000', + status: '에러 : 서버 에러', + message : '삭제 요청 처리 중 서버에서 문제가 발생했습니다.' + }); + } }; const updateTeam = async (req, res, next) => { + try{ + } + catch{ + + } }; const searchTeams = async (req, res, next) => { + try{ + } + catch{ + + } }; \ No newline at end of file From dbabb6a47544a337ce087592b1d2c8e8c91478f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=B0=AC=ED=98=B8?= Date: Thu, 23 Sep 2021 17:38:36 +0900 Subject: [PATCH 4/9] =?UTF-8?q?=F0=9F=91=94=20=EC=8A=A4=ED=84=B0=EB=94=94?= =?UTF-8?q?=20=EA=B7=B8=EB=A3=B9=EC=9D=98=20=EB=82=B4=EC=9A=A9=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit teamId를 받아서 그 Id에 해당하는 객체의 값을 요청 바디에 있는 값으로 변경 --- backend/src/services/team/team.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/src/services/team/team.js b/backend/src/services/team/team.js index 04ad90e..efd8fea 100644 --- a/backend/src/services/team/team.js +++ b/backend/src/services/team/team.js @@ -42,10 +42,21 @@ const deleteTeam = async (req, res, next) => { const updateTeam = async (req, res, next) => { try{ - + const teamId = req.params['teamId']; + await Team.findByIdAndUpdate(teamId,{...req.body}); + await res.status(200).json({ + code: '2000', + status: '성공 : Team 수정', + message: 'Team이 정상적으로 수정되었습니다.' + }); } catch{ - + console.error(err); + await res.status(500).json({ + code: '5000', + status: '에러 : 서버 에러', + message : '수정 요청 처리 중 서버에서 문제가 발생했습니다.' + }); } }; @@ -54,6 +65,6 @@ const searchTeams = async (req, res, next) => { } catch{ - + } }; \ No newline at end of file From 4d3913bd6fe008dec22fc7c0abf28cfdcf35f3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=B0=AC=ED=98=B8?= Date: Thu, 23 Sep 2021 17:43:26 +0900 Subject: [PATCH 5/9] =?UTF-8?q?=F0=9F=91=94=20=EC=8A=A4=ED=84=B0=EB=94=94?= =?UTF-8?q?=20=EA=B7=B8=EB=A3=B9=EC=9D=98=20=EC=9D=B4=EB=A6=84=EC=9D=B4=20?= =?UTF-8?q?=ED=8F=AC=ED=95=A8=EB=90=98=EC=96=B4=20=EC=9E=88=EC=9C=BC?= =?UTF-8?q?=EB=A9=B4=20=EC=84=A0=ED=83=9D=EB=90=98=EB=8A=94=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/services/team/team.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/src/services/team/team.js b/backend/src/services/team/team.js index efd8fea..39d6424 100644 --- a/backend/src/services/team/team.js +++ b/backend/src/services/team/team.js @@ -62,9 +62,21 @@ const updateTeam = async (req, res, next) => { const searchTeams = async (req, res, next) => { try{ - + const title = req.query["title"]; + const teams = await Team.find({title: `/${title}/gi`}).exec(); + await res.status(200).json({ + code: '2000', + status: '성공 : Team 검색', + message: 'Team이 정상적으로 검색되었습니다.', + study: teams + }); } catch{ - + console.error(err); + await res.status(500).json({ + code: '5000', + status: '에러 : 서버 에러', + message : '검색 요청 처리 중 서버에서 문제가 발생했습니다.' + }); } }; \ No newline at end of file From 99a9572e631042379f26015ad6f68d2f32ac9b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=B0=AC=ED=98=B8?= Date: Thu, 23 Sep 2021 20:30:43 +0900 Subject: [PATCH 6/9] =?UTF-8?q?=E2=9C=A8=20=EC=8A=A4=ED=84=B0=EB=94=94=20?= =?UTF-8?q?=EA=B7=B8=EB=A3=B9=20CRUD=20=EB=9D=BC=EC=9A=B0=ED=84=B0=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20=EB=B0=8F=20app.js=EC=97=90=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app.js | 2 ++ backend/src/routes/team.js | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 backend/src/routes/team.js diff --git a/backend/app.js b/backend/app.js index 005909a..7674e58 100644 --- a/backend/app.js +++ b/backend/app.js @@ -11,6 +11,7 @@ require("dotenv").config(); const indexRouter = require('./src/routes/index'); const userRouter = require('./src/routes/user'); const authRouter = require('./src/routes/auth'); +const teamRouter = require('./src/routes/team'); const app = express(); @@ -29,5 +30,6 @@ require('./src/configs/passport')(); app.use('/', indexRouter); app.use('/user', userRouter); app.use('/auth', authRouter); +app.use('/study',teamRouter); module.exports = app; diff --git a/backend/src/routes/team.js b/backend/src/routes/team.js new file mode 100644 index 0000000..e1b5532 --- /dev/null +++ b/backend/src/routes/team.js @@ -0,0 +1,13 @@ +const {createTeam, deleteTeam, updateTeam, searchTeams} = require("../services/team/team"); +const express = require('express'); +const router = express.Router(); + +router.get('/',searchTeams); + +router.post('/',createTeam); + +router.put('/:teamId',updateTeam); + +router.delete('/:teamId',deleteTeam); + +module.exports = router; \ No newline at end of file From ad28b2826ca0bc8934010ab57c4fc19f5dd54a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=B0=AC=ED=98=B8?= Date: Thu, 23 Sep 2021 20:31:16 +0900 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=94=A5=20Mongoose=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0=20=EC=8B=9C,=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C?= =?UTF-8?q?=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/bin/www | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/bin/www b/backend/bin/www index 2dab2d1..cae08e3 100644 --- a/backend/bin/www +++ b/backend/bin/www @@ -9,10 +9,9 @@ const debug = require('debug')('backend:server'); const http = require('http'); const mongoose = require('mongoose'); -mongoose.connect(process.env.DATABASE_URL,{ - useNewUrlParser: true, - useUnifiedTopology: true, -}) +require('dotenv').config(); + +mongoose.connect(process.env.DATABASE_URL) .then(res => console.log("MongoDB Connected")) .catch(err => console.error(err)); From de79c64ac02c191243bf977657e84e5b4677d62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=B0=AC=ED=98=B8?= Date: Thu, 23 Sep 2021 20:34:53 +0900 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=90=9B=20=EC=A0=95=EA=B7=9C=ED=91=9C?= =?UTF-8?q?=ED=98=84=EC=8B=9D=20=EC=9E=91=EC=84=B1=20=EC=8B=9C,=20?= =?UTF-8?q?=ED=83=AC=ED=94=8C=EB=A6=BF=20=EB=A6=AC=ED=84=B0=EB=9F=B4?= =?UTF-8?q?=EC=9D=B4=20=EC=9E=91=EB=8F=99=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 탬플릿 리터럴을 활용하지 않고, 객체를 생성해서 필터링 진행 --- backend/src/services/team/team.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/src/services/team/team.js b/backend/src/services/team/team.js index 39d6424..4d6a0bc 100644 --- a/backend/src/services/team/team.js +++ b/backend/src/services/team/team.js @@ -62,8 +62,10 @@ const updateTeam = async (req, res, next) => { const searchTeams = async (req, res, next) => { try{ - const title = req.query["title"]; - const teams = await Team.find({title: `/${title}/gi`}).exec(); + let title = req.query["title"]; + if(title === undefined) title = ''; + const teams = await Team.find({title: new RegExp(`${title}`,'i')}).exec(); + await res.status(200).json({ code: '2000', status: '성공 : Team 검색', @@ -79,4 +81,6 @@ const searchTeams = async (req, res, next) => { message : '검색 요청 처리 중 서버에서 문제가 발생했습니다.' }); } -}; \ No newline at end of file +}; + +module.exports = { createTeam, deleteTeam, updateTeam, searchTeams }; \ No newline at end of file From 6de4e0cfc6e07d0567466aaad00ad186c3e3f15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=B0=AC=ED=98=B8?= Date: Thu, 23 Sep 2021 21:15:39 +0900 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=90=9B=20catch=EB=AC=B8=EC=97=90?= =?UTF-8?q?=EC=84=9C=20error=EB=A5=BC=20=EB=AA=85=EC=8B=9C=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EC=95=84=20=EB=B0=9C=EC=83=9D=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95,=20response?= =?UTF-8?q?=EB=A1=9C=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=EA=B0=80=20=ED=8F=AC=ED=95=A8=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/services/team/team.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/src/services/team/team.js b/backend/src/services/team/team.js index 4d6a0bc..fe5e084 100644 --- a/backend/src/services/team/team.js +++ b/backend/src/services/team/team.js @@ -2,11 +2,12 @@ const Team = require("../../models/team"); const createTeam = async (req, res, next) => { try{ - await Team.create({...req.body}); + const result = await Team.create({...req.body}); await res.status(201).json({ code: '2001', status: '성공 : Team 생성', - message: 'Team이 정상적으로 생성되었습니다.' + message: 'Team이 정상적으로 생성되었습니다.', + id: result["_id"] }); } catch(err){ @@ -30,7 +31,7 @@ const deleteTeam = async (req, res, next) => { message: 'Team이 정상적으로 삭제되었습니다.' }); } - catch{ + catch(err){ console.error(err); await res.status(500).json({ code: '5000', @@ -43,6 +44,7 @@ const deleteTeam = async (req, res, next) => { const updateTeam = async (req, res, next) => { try{ const teamId = req.params['teamId']; + if(req.body['userIds'] !== undefined) throw new Error("userIds는 접근할 수 없습니다."); await Team.findByIdAndUpdate(teamId,{...req.body}); await res.status(200).json({ code: '2000', @@ -50,12 +52,12 @@ const updateTeam = async (req, res, next) => { message: 'Team이 정상적으로 수정되었습니다.' }); } - catch{ + catch(err){ console.error(err); await res.status(500).json({ code: '5000', status: '에러 : 서버 에러', - message : '수정 요청 처리 중 서버에서 문제가 발생했습니다.' + message : `${err}` }); } }; @@ -63,7 +65,7 @@ const updateTeam = async (req, res, next) => { const searchTeams = async (req, res, next) => { try{ let title = req.query["title"]; - if(title === undefined) title = ''; + if(title === undefined) title = ''; const teams = await Team.find({title: new RegExp(`${title}`,'i')}).exec(); await res.status(200).json({ @@ -73,7 +75,7 @@ const searchTeams = async (req, res, next) => { study: teams }); } - catch{ + catch(err){ console.error(err); await res.status(500).json({ code: '5000',