Toggle navigation
Toggle navigation
This project
Loading...
Sign in
송용우
/
oss-Jaksimsamil
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
JJuOn
2020-09-10 15:56:39 +0900
1
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5d96fb7ead18c2d1f242bd0e537966e63b8e5d5a
5d96fb7e
1 parent
fc3f94f8
Implement GET /api/chalenge/getchallenge
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
2 deletions
jaksimsamil-server/src/api/challenge/challege.ctrl.js
jaksimsamil-server/src/api/challenge/index.js
jaksimsamil-server/src/api/challenge/challege.ctrl.js
View file @
5d96fb7
...
...
@@ -10,7 +10,7 @@ const Joi = require("joi");
challengeName: "challengeName"
}
*/
exports
.
getChallenge
=
async
(
ctx
)
=>
{
exports
.
getChallenge
POST
=
async
(
ctx
)
=>
{
try
{
const
{
challengeName
}
=
ctx
.
request
.
body
;
const
challenge
=
await
Challenge
.
findByChallengeName
(
challengeName
);
...
...
@@ -189,3 +189,36 @@ exports.participate = async (ctx) => {
ctx
.
throw
(
500
,
e
);
}
};
/*
GET /api/challenge/getchallenge?username
*/
exports
.
getChallengeGET
=
async
(
ctx
)
=>
{
try
{
const
{
username
}
=
ctx
.
request
.
query
;
const
user
=
await
User
.
findByUsername
(
username
);
const
user_id
=
user
.
_id
;
const
groups
=
await
Group
.
find
();
const
userIncludedGroups
=
[];
for
(
let
i
=
0
;
i
<
groups
.
length
;
i
++
){
if
(
groups
[
i
].
members
.
includes
(
user_id
)){
userIncludedGroups
.
push
(
groups
[
i
]);
}
}
const
challengeList
=
[];
for
(
let
i
=
0
;
i
<
userIncludedGroups
.
length
;
i
++
){
const
participations
=
await
Participation
.
findByGroupId
(
userIncludedGroups
[
i
].
_id
);
for
(
let
j
=
0
;
j
<
participations
.
length
;
j
++
){
const
session
=
await
Session
.
findById
(
participations
[
j
].
sessionId
);
const
challenge
=
await
Challenge
.
findById
(
session
.
challengeId
);
if
(
!
challengeList
.
includes
(
challenge
)){
challengeList
.
push
(
challenge
);
}
}
}
ctx
.
body
=
challengeList
.
map
(
c
=>
c
.
serialize
());
}
catch
(
e
){
ctx
.
throw
(
500
,
e
);
}
}
\ No newline at end of file
...
...
jaksimsamil-server/src/api/challenge/index.js
View file @
5d96fb7
...
...
@@ -2,9 +2,10 @@ const Router = require('koa-router');
const
challenge
=
new
Router
();
const
challengeCtrl
=
require
(
'./challege.ctrl'
);
challenge
.
post
(
"/getchallenge"
,
challengeCtrl
.
getChallenge
);
challenge
.
post
(
"/getchallenge"
,
challengeCtrl
.
getChallenge
POST
);
challenge
.
post
(
"/addchallenge"
,
challengeCtrl
.
addChallenge
);
challenge
.
get
(
"/list/:status"
,
challengeCtrl
.
list
);
challenge
.
post
(
"/participate"
,
challengeCtrl
.
participate
);
challenge
.
get
(
"/getchallenge"
,
challengeCtrl
.
getChallengeGET
);
module
.
exports
=
challenge
;
\ No newline at end of file
...
...
송용우
@2019102188
2020-09-26 12:41:26 UTC
Mentioned in commit
c99e3b57
Please
register
or
login
to post a comment