송용우

Merge commit '2cd393eb' into develop

...@@ -26,17 +26,18 @@ POST http://facerain.dcom.club/profile/getprofile ...@@ -26,17 +26,18 @@ POST http://facerain.dcom.club/profile/getprofile
26 26
27 ## API Table 27 ## API Table
28 28
29 -| group | description | method | URL | Detail | Auth | 29 +| group | description | method | URL | Detail | Auth |
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 TOKEN |
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 TOKEN |
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 Token |
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 Token |
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 |
......
1 const Joi = require("joi"); 1 const Joi = require("joi");
2 const User = require("../../models/user"); 2 const User = require("../../models/user");
3 -const Profile = require("../../models/profile");
4 /* 3 /*
5 POST /api/auth/register 4 POST /api/auth/register
6 { 5 {
...@@ -28,14 +27,10 @@ exports.register = async (ctx) => { ...@@ -28,14 +27,10 @@ exports.register = async (ctx) => {
28 ctx.status = 409; 27 ctx.status = 409;
29 return; 28 return;
30 } 29 }
31 - const profile = new Profile({
32 - username,
33 - });
34 const user = new User({ 30 const user = new User({
35 username, 31 username,
36 }); 32 });
37 await user.setPassword(password); 33 await user.setPassword(password);
38 - await profile.save();
39 await user.save(); 34 await user.save();
40 ctx.body = user.serialize(); 35 ctx.body = user.serialize();
41 36
......
1 +const Challenge = require("../../models/challenge");
2 +const Joi = require("joi");
3 +/*POST /api/challenge/getChallenge
4 +{
5 + challengeName: "challengeName"
6 +}
7 +*/
8 +exports.getChallenge = async (ctx) => {
9 + try {
10 + const { challengeName } = ctx.request.body;
11 + const challenge = await Challenge.findByChallengeName(challengeName);
12 + if (!challenge) {
13 + ctx.status = 401;
14 + return;
15 + }
16 + ctx.body = challenge;
17 + } catch (e) {
18 + ctx.throw(500, e);
19 + }
20 +};
21 +/*POST /api/challenge/addChallenge
22 +{
23 + challengeName: "challengeName",
24 + startDate: Date Object,
25 + endDate: Date Object,
26 + durationPerSession: "2w", // '1d' means one day per session, '2w' means 2 weeks per session, '3m' means 3 months per session.
27 + goalPerSession: 3,
28 + groups: [{'name1', 'name2'}]
29 +}
30 +*/
31 +exports.addChallenge = async (ctx) => {
32 + const schema = Joi.object()
33 + .keys({
34 + challengeName: Joi.string(),
35 + startDate: Joi.date(),
36 + endDate: Joi.date(),
37 + durationPerSession: Joi.string(),
38 + goalPerSession: Joi.number(),
39 + groups: Joi.array().items(Joi.string()),
40 + })
41 + .unknown();
42 + const result = Joi.validate(ctx.request.body, schema);
43 +
44 + if (result.error) {
45 + ctx.status = 400;
46 + ctx.body = result.error;
47 + return;
48 + }
49 + const {
50 + challengeName,
51 + startDate,
52 + endDate,
53 + durationPerSession,
54 + goalPerSession,
55 + } = ctx.request.body;
56 +
57 + try {
58 + const isChallengeExist = await Challenge.findByChallengeName(challengeName);
59 +
60 + if (isChallengeExist) {
61 + ctx.status = 409;
62 + return;
63 + }
64 + const challenge = new Challenge({
65 + challengeName,
66 + startDate,
67 + endDate,
68 + durationPerSession,
69 + goalPerSession,
70 + });
71 +
72 + await challenge.save();
73 + ctx.body = challenge();
74 + } catch (e) {
75 + ctx.throw(500, e);
76 + }
77 + /*
78 + TODO: How to handle group?
79 + */
80 +};
1 -const Profile = require("../../models/profile"); 1 +const User = require("../../models/user");
2 const mongoose = require("mongoose"); 2 const mongoose = require("mongoose");
3 const getBJ = require("../../util/getBJ"); 3 const getBJ = require("../../util/getBJ");
4 const Joi = require("joi"); 4 const Joi = require("joi");
...@@ -16,6 +16,7 @@ exports.checkObjectId = (ctx, next) => { ...@@ -16,6 +16,7 @@ exports.checkObjectId = (ctx, next) => {
16 } 16 }
17 return next(); 17 return next();
18 }; 18 };
19 +
19 /*POST /api/profile/getprofile 20 /*POST /api/profile/getprofile
20 { 21 {
21 username: "username" 22 username: "username"
...@@ -24,7 +25,7 @@ exports.checkObjectId = (ctx, next) => { ...@@ -24,7 +25,7 @@ exports.checkObjectId = (ctx, next) => {
24 exports.getProfile = async (ctx) => { 25 exports.getProfile = async (ctx) => {
25 try { 26 try {
26 const { username } = ctx.request.body; 27 const { username } = ctx.request.body;
27 - const profile = await Profile.findByUsername(username); 28 + const profile = await User.findByUsername(username);
28 if (!profile) { 29 if (!profile) {
29 ctx.status = 401; 30 ctx.status = 401;
30 return; 31 return;
...@@ -50,7 +51,6 @@ exports.setProfile = async (ctx) => { ...@@ -50,7 +51,6 @@ exports.setProfile = async (ctx) => {
50 //freindList: Joi.array().items(Joi.string()), 51 //freindList: Joi.array().items(Joi.string()),
51 }) 52 })
52 .unknown(); 53 .unknown();
53 - console.log(ctx.request.body);
54 const result = Joi.validate(ctx.request.body, schema); 54 const result = Joi.validate(ctx.request.body, schema);
55 if (result.error) { 55 if (result.error) {
56 ctx.status = 400; 56 ctx.status = 400;
...@@ -59,7 +59,7 @@ exports.setProfile = async (ctx) => { ...@@ -59,7 +59,7 @@ exports.setProfile = async (ctx) => {
59 } 59 }
60 60
61 try { 61 try {
62 - const profile = await Profile.findOneAndUpdate( 62 + const profile = await User.findOneAndUpdate(
63 { username: ctx.request.body.username }, 63 { username: ctx.request.body.username },
64 ctx.request.body, 64 ctx.request.body,
65 { 65 {
...@@ -91,7 +91,7 @@ exports.syncBJ = async function (ctx) { ...@@ -91,7 +91,7 @@ exports.syncBJ = async function (ctx) {
91 } 91 }
92 92
93 try { 93 try {
94 - const profile = await Profile.findByUsername(username); 94 + const profile = await User.findByUsername(username);
95 if (!profile) { 95 if (!profile) {
96 ctx.status = 401; 96 ctx.status = 401;
97 return; 97 return;
...@@ -99,7 +99,7 @@ exports.syncBJ = async function (ctx) { ...@@ -99,7 +99,7 @@ exports.syncBJ = async function (ctx) {
99 const BJID = await profile.getBJID(); 99 const BJID = await profile.getBJID();
100 let BJdata = await getBJ.getBJ(BJID); 100 let BJdata = await getBJ.getBJ(BJID);
101 let BJdata_date = await analyzeBJ.analyzeBJ(BJdata); 101 let BJdata_date = await analyzeBJ.analyzeBJ(BJdata);
102 - const updateprofile = await Profile.findOneAndUpdate( 102 + const updateprofile = await User.findOneAndUpdate(
103 { username: username }, 103 { username: username },
104 { solvedBJ: BJdata, solvedBJ_date: BJdata_date }, 104 { solvedBJ: BJdata, solvedBJ_date: BJdata_date },
105 { new: true } 105 { new: true }
...@@ -124,7 +124,7 @@ exports.recommend = async (ctx) => { ...@@ -124,7 +124,7 @@ exports.recommend = async (ctx) => {
124 return; 124 return;
125 } 125 }
126 try { 126 try {
127 - const profile = await Profile.findByUsername(username); 127 + const profile = await User.findByUsername(username);
128 if (!profile) { 128 if (!profile) {
129 ctx.status = 401; 129 ctx.status = 401;
130 return; 130 return;
......