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
송용우
2020-09-10 17:47:38 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
c99e3b5717177259fcc629f1c0c3de5748a150ea
c99e3b57
2 parents
72b227ac
5d96fb7e
Merge commit '
5d96fb7e
' into develop
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
3 deletions
jaksimsamil-server/src/api/challenge/challege.ctrl.js
jaksimsamil-server/src/api/challenge/index.js
jaksimsamil-server/src/api/session/session.ctrl.js
jaksimsamil-server/src/api/challenge/challege.ctrl.js
View file @
c99e3b5
...
...
@@ -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 @
c99e3b5
...
...
@@ -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
...
...
jaksimsamil-server/src/api/session/session.ctrl.js
View file @
c99e3b5
...
...
@@ -6,6 +6,7 @@ const User = require("../../models/user");
const
Challenge
=
require
(
"../../models/challenge"
);
const
Problem
=
require
(
"../../models/problem"
);
const
mongoose
=
require
(
"mongoose"
);
require
(
'dotenv'
).
config
();
const
{
ObjectId
}
=
mongoose
.
Types
;
...
...
@@ -127,7 +128,25 @@ exports.status=async (ctx)=>{
}
const
participation
=
await
Participation
.
findOne
({
sessionId
:
sessionId
,
groupId
:
groupId
});
const
group
=
await
Group
.
findById
(
groupId
);
for
(
let
i
=
0
;
i
<
group
.
members
.
length
;
i
++
){
const
user
=
await
User
.
findById
(
group
.
members
[
i
]);
await
axios
.
patch
(
`http://localhost:
${
process
.
env
.
SERVER_PORT
}
/api/profile/syncBJ`
,{
username
:
user
.
username
});
}
for
(
let
i
=
0
;
i
<
group
.
members
.
length
;
i
++
){
const
user
=
await
User
.
findById
(
group
.
members
[
i
]);
let
userProblemList
=
[];
for
(
let
key
in
user
.
solvedBJ_date
.
solvedBJbyDATE
){
userProblemList
.
push
(
user
.
solvedBJ_date
.
solvedBJbyDATE
[
key
]);
}
userProblemList
=
userProblemList
.
flat
().
map
(
elem
=>
elem
.
problem_number
);
for
(
let
j
=
0
;
j
<
participation
.
problems
.
length
;
j
++
){
if
(
userProblemList
.
includes
(
String
(
participation
.
problems
[
i
].
problemNum
))){
participation
.
problems
[
i
].
isSolved
=
true
;
await
participation
.
save
();
}
}
}
ctx
.
body
=
participation
.
serialize
();
}
catch
(
e
){
ctx
.
throw
(
500
,
e
);
...
...
Please
register
or
login
to post a comment