JuWon Seo
Committed by GitHub

Merge pull request #22 from FacerAin/feature/rest_api

Feature/rest api
...@@ -30,14 +30,17 @@ POST http://facerain.dcom.club/profile/getprofile ...@@ -30,14 +30,17 @@ POST http://facerain.dcom.club/profile/getprofile
30 | --------- | -------------------------------------- | ------ | -------------------------- | -------------------------------------- | --------- | 30 | --------- | -------------------------------------- | ------ | -------------------------- | -------------------------------------- | --------- |
31 | profile | 유저가 푼 문제 조회(백준) | GET | api/profile/solvedBJ:id | [바로가기](/src/api/profile/README.md) | None | 31 | profile | 유저가 푼 문제 조회(백준) | GET | api/profile/solvedBJ:id | [바로가기](/src/api/profile/README.md) | None |
32 | profile | 유저가 푼 문제 동기화(백준) | PATCH | api/profile/syncBJ | [바로가기](/src/api/profile/README.md) | None | 32 | profile | 유저가 푼 문제 동기화(백준) | PATCH | api/profile/syncBJ | [바로가기](/src/api/profile/README.md) | None |
33 -| profile | 유저 정보 수정 | POST | api/profile/setprofile | [바로가기](/src/api/profile/README.md) | JWT TOKEN | 33 +| profile | 유저 정보 수정 | POST | api/profile/setprofile | [바로가기](/src/api/profile/README.md) | JWT |
34 | profile | 유저 정보 받아오기 | POST | api/profile/getprofile | [바로가기](/src/api/profile/README.md) | JWT | 34 | profile | 유저 정보 받아오기 | POST | api/profile/getprofile | [바로가기](/src/api/profile/README.md) | JWT |
35 | profile | 추천 문제 조회 | POST | api/profile/recommend | [바로가기](/src/api/profile/README.md) | None | 35 | profile | 추천 문제 조회 | POST | api/profile/recommend | [바로가기](/src/api/profile/README.md) | None |
36 -| profile | 친구 추가 | POST | /api/profile/addfriend | [바로가기](/src/api/profile/README.md) | JWT TOKEN | 36 +| profile | 친구 추가 | POST | api/profile/addfriend | [바로가기](/src/api/profile/README.md) | JWT |
37 -| notify | 슬랙 메시지 전송 요청 (목표 성취 여부) | POST | api/notify/goal | [바로가기](/src/api/notify/README.md) | Jwt Token | 37 +| notify | 슬랙 메시지 전송 요청 (목표 성취 여부) | POST | api/notify/goal | [바로가기](/src/api/notify/README.md) | JWT |
38 | notify | 슬랙 메시지 전송 요청 (문제 추천) | POST | api/notify/recommend | [바로가기](/src/api/notify/README.md) | None | 38 | notify | 슬랙 메시지 전송 요청 (문제 추천) | POST | api/notify/recommend | [바로가기](/src/api/notify/README.md) | None |
39 | auth | 로그인 | POST | api/auth/login | [바로가기](/src/api/auth/README.md) | None | 39 | auth | 로그인 | POST | api/auth/login | [바로가기](/src/api/auth/README.md) | None |
40 -| auth | 로그아웃 | POST | api/auth/logout | [바로가기](/src/api/auth/README.md) | JWT Token | 40 +| auth | 로그아웃 | POST | api/auth/logout | [바로가기](/src/api/auth/README.md) | JWT |
41 | auth | 회원가입 | POST | api/auth/register | [바로가기](/src/api/auth/README.md) | None | 41 | auth | 회원가입 | POST | api/auth/register | [바로가기](/src/api/auth/README.md) | None |
42 | auth | 로그인 확인 | GET | api/auth/check | [바로가기](/src/api/auth/README.md) | None | 42 | auth | 로그인 확인 | GET | api/auth/check | [바로가기](/src/api/auth/README.md) | None |
43 -| challenge | 특정 챌린지 조회(이름) | POST | api/challenge/getChallenge | [바로가기]() | None | 43 +| challenge | 특정 챌린지 조회(이름) | POST | api/challenge/getChallenge | [바로가기](/src/api/challenge/README.md)| None |
44 +| challenge | 챌린지 추가 | POST | api/challenge/addChallenge | [바로가기](/src/api/challenge/README.md) | None |
45 +| challenge | 챌린지 목록 조회 | GET | api/challenge/list | [바로가기](/src/api/challenge/README.md) | None |
46 +| challenge | 챌린지 참가 | POST | api/challenge/participate | [바로가기](/src/api/challenge/README.md) | None |
...\ No newline at end of file ...\ No newline at end of file
......
1 +# API Documentation - Challenge
2 +
3 +1. POST /api/challenge/getChallenge
4 +- 챌린지 상세 정보 조회
5 +- input(body)
6 +```javascript
7 +{
8 + "challengeName": String
9 +}
10 +```
11 +1. POST /api/challenge/addChallenge
12 +- 챌린지 추가
13 +- input(body)
14 +```javascript
15 +{
16 + "challengeName":String,
17 + "startDate":Date,
18 + "endDate":Date,
19 + "durationPerSession": String, // "1d"=1 day, "2w"=2 weeks, "3m"=3 months
20 + "goalPerSession":Number
21 +}
22 +```
23 +1. GET /api/challenge/list/:status
24 +- 챌린지 목록 조회
25 +- input(parameter)
26 +```
27 +status=(one of ["all","enrolled","progress","end"])
28 +```
29 +1. POST /api/challenge/participate
30 +- 챌린지 참가
31 +- input(body)
32 +```javascript
33 +{
34 + "username":String,
35 + "challengeName":String
36 +}
37 +```
...\ No newline at end of file ...\ No newline at end of file
...@@ -13,12 +13,12 @@ const Joi = require("joi"); ...@@ -13,12 +13,12 @@ const Joi = require("joi");
13 exports.getChallenge = async (ctx) => { 13 exports.getChallenge = async (ctx) => {
14 try { 14 try {
15 const { challengeName } = ctx.request.body; 15 const { challengeName } = ctx.request.body;
16 - const challenge = await Challenge.findByChallengeName(challengeName).select('-_id'); 16 + const challenge = await Challenge.findByChallengeName(challengeName);
17 if (!challenge) { 17 if (!challenge) {
18 ctx.status = 401; 18 ctx.status = 401;
19 return; 19 return;
20 } 20 }
21 - ctx.body = challenge; 21 + ctx.body = challenge.serialize();
22 } catch (e) { 22 } catch (e) {
23 ctx.throw(500, e); 23 ctx.throw(500, e);
24 } 24 }
...@@ -58,7 +58,7 @@ exports.addChallenge = async (ctx) => { ...@@ -58,7 +58,7 @@ exports.addChallenge = async (ctx) => {
58 } = ctx.request.body; 58 } = ctx.request.body;
59 59
60 try { 60 try {
61 - const isChallengeExist = await Challenge.findByChallengeName(challengeName).select('-_id'); 61 + const isChallengeExist = await Challenge.findByChallengeName(challengeName);
62 62
63 if (isChallengeExist) { 63 if (isChallengeExist) {
64 ctx.status = 409; 64 ctx.status = 409;
...@@ -122,26 +122,26 @@ exports.addChallenge = async (ctx) => { ...@@ -122,26 +122,26 @@ exports.addChallenge = async (ctx) => {
122 s_date=new Date(e_date); 122 s_date=new Date(e_date);
123 s_date.setMinutes(s_date.getMinutes()+1); 123 s_date.setMinutes(s_date.getMinutes()+1);
124 } 124 }
125 - ctx.body = challenge; 125 + ctx.body = challenge.serialize();
126 } catch (e) { 126 } catch (e) {
127 ctx.throw(500, e); 127 ctx.throw(500, e);
128 } 128 }
129 }; 129 };
130 130
131 131
132 -/* GET /api/challenge/list?status 132 +/* GET /api/challenge/list/:status
133 -query string status can be in ['all','enrolled','progress','end'] 133 +parameter status can be in ['all','enrolled','progress','end']
134 */ 134 */
135 exports.list = async (ctx) => { 135 exports.list = async (ctx) => {
136 try{ 136 try{
137 - const status = ctx.query.status; 137 + const status = ctx.params.status;
138 if (status!=='all'){ 138 if (status!=='all'){
139 - const challenges = await Challenge.find({status:status}).select('-_id'); 139 + const challenges = await Challenge.find({status:status});
140 - ctx.body = challenges; 140 + ctx.body = challenges.serialize();
141 } 141 }
142 else { 142 else {
143 - const challenges = await Challenge.find({}).select('-_id'); 143 + const challenges = await Challenge.find({});
144 - ctx.body = challenges; 144 + ctx.body = challenges.serialize();
145 } 145 }
146 } 146 }
147 catch(e){ 147 catch(e){
...@@ -169,6 +169,7 @@ exports.participate=async (ctx)=>{ ...@@ -169,6 +169,7 @@ exports.participate=async (ctx)=>{
169 const user=await User.findByUsername(username); 169 const user=await User.findByUsername(username);
170 const user_id=user._id; 170 const user_id=user._id;
171 const newGroup=new Group({ 171 const newGroup=new Group({
172 + groupName:`${user.username}${challengeName} 그룹`,
172 members:[user_id], 173 members:[user_id],
173 }); 174 });
174 let newGroup_id="" 175 let newGroup_id=""
...@@ -185,6 +186,7 @@ exports.participate=async (ctx)=>{ ...@@ -185,6 +186,7 @@ exports.participate=async (ctx)=>{
185 problems:[], 186 problems:[],
186 }); 187 });
187 await newParticipation.save(); 188 await newParticipation.save();
189 + ctx.body=newParticipation.serialize();
188 }); 190 });
189 }); 191 });
190 } 192 }
......
...@@ -4,7 +4,7 @@ const challengeCtrl = require('./challege.ctrl'); ...@@ -4,7 +4,7 @@ const challengeCtrl = require('./challege.ctrl');
4 4
5 challenge.post("/getchallenge",challengeCtrl.getChallenge); 5 challenge.post("/getchallenge",challengeCtrl.getChallenge);
6 challenge.post("/addchallenge",challengeCtrl.addChallenge); 6 challenge.post("/addchallenge",challengeCtrl.addChallenge);
7 -challenge.get("/list",challengeCtrl.list); 7 +challenge.get("/list/:status",challengeCtrl.list);
8 challenge.post("/participate",challengeCtrl.participate); 8 challenge.post("/participate",challengeCtrl.participate);
9 9
10 module.exports = challenge; 10 module.exports = challenge;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -7,6 +7,7 @@ const notify = require("./notify"); ...@@ -7,6 +7,7 @@ const notify = require("./notify");
7 const user = require("./user"); 7 const user = require("./user");
8 const profile = require("./profile"); 8 const profile = require("./profile");
9 const challenge = require("./challenge"); 9 const challenge = require("./challenge");
10 +const session = require("./session");
10 11
11 api.use("/auth", auth.routes()); 12 api.use("/auth", auth.routes());
12 api.use("/friend", friend.routes()); 13 api.use("/friend", friend.routes());
...@@ -14,5 +15,6 @@ api.use("/notify", notify.routes()); ...@@ -14,5 +15,6 @@ api.use("/notify", notify.routes());
14 api.use("/user", user.routes()); 15 api.use("/user", user.routes());
15 api.use("/profile", profile.routes()); 16 api.use("/profile", profile.routes());
16 api.use("/challenge",challenge.routes()); 17 api.use("/challenge",challenge.routes());
18 +api.use("/session",session.routes());
17 19
18 module.exports = api; 20 module.exports = api;
......
...@@ -30,7 +30,7 @@ exports.getProfile = async (ctx) => { ...@@ -30,7 +30,7 @@ exports.getProfile = async (ctx) => {
30 ctx.status = 401; 30 ctx.status = 401;
31 return; 31 return;
32 } 32 }
33 - ctx.body = profile; 33 + ctx.body = profile.serialize();
34 } catch (e) { 34 } catch (e) {
35 ctx.throw(500, e); 35 ctx.throw(500, e);
36 } 36 }
...@@ -71,7 +71,7 @@ exports.setProfile = async (ctx) => { ...@@ -71,7 +71,7 @@ exports.setProfile = async (ctx) => {
71 ctx.status = 404; 71 ctx.status = 404;
72 return; 72 return;
73 } 73 }
74 - ctx.body = profile; 74 + ctx.body = profile.serialize();
75 } catch (e) { 75 } catch (e) {
76 ctx.throw(500, e); 76 ctx.throw(500, e);
77 } 77 }
...@@ -104,7 +104,7 @@ exports.syncBJ = async function (ctx) { ...@@ -104,7 +104,7 @@ exports.syncBJ = async function (ctx) {
104 { solvedBJ: BJdata, solvedBJ_date: BJdata_date }, 104 { solvedBJ: BJdata, solvedBJ_date: BJdata_date },
105 { new: true } 105 { new: true }
106 ).exec(); 106 ).exec();
107 - ctx.body = updateprofile; 107 + ctx.body = updateprofile.serialize();
108 } catch (e) { 108 } catch (e) {
109 ctx.throw(500, e); 109 ctx.throw(500, e);
110 } 110 }
......
1 +const Router = require('koa-router');
2 +const session = new Router();
3 +const sessionCtrl = require('./session.ctrl');
4 +
5 +session.post("/createproblem/:how",sessionCtrl.createProblem);
6 +
7 +module.exports = session;
...\ No newline at end of file ...\ No newline at end of file
1 +/* POST /api/session/createproblem/:how
2 +{
3 + problemList:[Number]
4 +}
5 +*/
6 +exports.createProblem = async (ctx)=>{
7 + try{
8 + const how=ctx.params.how;
9 + if(how==='self'){
10 +
11 + }
12 + else if(how==='recommend'){
13 +
14 + }
15 + }
16 + catch(e){
17 + ctx.throw(500,e);
18 + }
19 +};
...\ No newline at end of file ...\ No newline at end of file