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
JuWon Seo
2020-09-03 17:41:16 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Committed by
GitHub
2020-09-03 17:41:16 +0900
Commit
b76a7c9a150846d1650ddab22b393581eca71103
b76a7c9a
2 parents
3f1264d4
01b86f47
Merge pull request #28 from FacerAin/feature/rest_api
Feature/rest api
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
52 deletions
jaksimsamil-server/src/api/challenge/challege.ctrl.js
jaksimsamil-server/src/api/session/session.ctrl.js
jaksimsamil-server/src/models/challenge.js
jaksimsamil-server/src/api/challenge/challege.ctrl.js
View file @
b76a7c9
...
...
@@ -132,10 +132,10 @@ exports.list = async (ctx) => {
const
status
=
ctx
.
params
.
status
;
if
(
status
!==
"all"
)
{
const
challenges
=
await
Challenge
.
find
({
status
:
status
});
ctx
.
body
=
challenges
.
serialize
()
;
ctx
.
body
=
challenges
;
}
else
{
const
challenges
=
await
Challenge
.
find
({});
ctx
.
body
=
challenges
.
serialize
()
;
ctx
.
body
=
challenges
;
}
}
catch
(
e
)
{
ctx
.
throw
(
500
,
e
);
...
...
jaksimsamil-server/src/api/session/session.ctrl.js
View file @
b76a7c9
const
Participation
=
require
(
"../../models/participation"
);
const
Session
=
require
(
"../../models/session"
);
const
Group
=
require
(
"../../models/group"
);
const
User
=
require
(
"../../models/user"
);
const
mongoose
=
require
(
"mongoose"
);
const
{
ObjectId
}
=
mongoose
.
Types
;
/* POST /api/session/createproblem/:how
{
problemList:[Number]
{
sessionId: ObjectId,
groupId: ObjectId,
problemList:[Number],
}
*/
exports
.
createProblem
=
async
(
ctx
)
=>
{
try
{
let
{
sessionId
,
groupId
,
problemList
}
=
ctx
.
request
.
body
;
if
(
typeof
(
sessionId
)
===
'string'
){
sessionId
=
new
ObjectId
(
sessionId
);
}
if
(
typeof
(
groupId
)
===
'string'
){
groupId
=
new
ObjectId
(
groupId
);
}
if
(
typeof
(
problemList
)
===
'string'
){
problemList
=
JSON
.
parse
(
problemList
);
}
const
participation
=
await
Participation
.
findOne
({
sessionId
:
sessionId
,
groupId
:
groupId
});
const
group
=
await
Group
.
findById
(
groupId
);
const
how
=
ctx
.
params
.
how
;
if
(
how
===
'self'
){
let
check
=
true
;
for
(
let
i
=
0
;
i
<
group
.
members
.
length
;
i
++
){
const
user
=
await
User
.
findById
(
group
.
members
[
i
]);
console
.
log
(
user
);
console
.
log
(
typeof
(
user
.
solvedBJ_date
.
solvedBJbyDATE
));
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
<
problemList
.
length
;
j
++
){
if
(
userProblemList
.
includes
(
problemList
[
j
])){
check
=
false
;
break
;
}
}
}
if
(
!
check
){
ctx
.
throw
(
'그룹원이 이미 푼 문제는 등록할 수 없습니다.'
);
return
;
}
else
{
problemList
.
map
(
async
problemNum
=>
await
participation
.
addProblem
({
problemNum
:
problemNum
,
isSolved
:
false
}));
ctx
.
body
=
participation
.
serialize
();
}
}
else
if
(
how
===
'recommend'
){
//TODO
}
}
catch
(
e
){
...
...
jaksimsamil-server/src/models/challenge.js
View file @
b76a7c9
...
...
@@ -2,49 +2,52 @@ const mongoose = require("mongoose");
const
{
Schema
}
=
mongoose
;
const
ChallengeSchema
=
new
Schema
({
challengeName
:
{
type
:
String
,
required
:
true
},
startDate
:
{
type
:
Object
,
required
:
true
},
endDate
:
{
type
:
Object
,
required
:
true
},
durationPerSession
:
{
type
:
String
,
required
:
true
},
// '1d' means one day per session, '2w' means 2 weeks per session, '3m' means 3 months per session.
goalPerSession
:
{
type
:
Number
,
required
:
true
},
// number of problems for one session
status
:
{
type
:
String
}
},{
collection
:
'challenge'
});
ChallengeSchema
.
statics
.
findByChallengeName
=
function
(
challengeName
){
return
this
.
findOne
({
challengeName
:
challengeName
});
}
ChallengeSchema
.
methods
.
getChallengeName
=
function
(){
return
this
.
challengeName
;
}
ChallengeSchema
.
methods
.
getStartDate
=
function
(){
return
this
.
startDate
;
}
ChallengeSchema
.
methods
.
getEndDate
=
function
(){
return
this
.
endDate
;
}
ChallengeSchema
.
method
.
getDurationPerSession
=
function
(){
return
this
.
durationPerSession
;
}
ChallengeSchema
.
methods
.
getGoalPerSession
=
function
(){
return
this
.
goalPerSession
;
}
ChallengeSchema
.
methods
.
getStatus
=
function
(){
return
this
.
status
;
}
ChallengeSchema
.
methods
.
serialize
=
function
(){
let
challengeJSON
=
this
.
toJSON
();
return
challengeJSON
;
}
const
Challenge
=
mongoose
.
model
(
'Challenge'
,
ChallengeSchema
);
module
.
exports
=
Challenge
;
\ No newline at end of file
const
ChallengeSchema
=
new
Schema
(
{
challengeName
:
{
type
:
String
,
required
:
true
},
startDate
:
{
type
:
Object
,
required
:
true
},
endDate
:
{
type
:
Object
,
required
:
true
},
durationPerSession
:
{
type
:
String
,
required
:
true
},
// '1d' means one day per session, '2w' means 2 weeks per session, '3m' means 3 months per session.
goalPerSession
:
{
type
:
Number
,
required
:
true
},
// number of problems for one session
status
:
{
type
:
String
},
},
{
collection
:
"challenge"
,
}
);
ChallengeSchema
.
statics
.
findByChallengeName
=
function
(
challengeName
)
{
return
this
.
findOne
({
challengeName
:
challengeName
});
};
ChallengeSchema
.
methods
.
getChallengeName
=
function
()
{
return
this
.
challengeName
;
};
ChallengeSchema
.
methods
.
getStartDate
=
function
()
{
return
this
.
startDate
;
};
ChallengeSchema
.
methods
.
getEndDate
=
function
()
{
return
this
.
endDate
;
};
ChallengeSchema
.
methods
.
getDurationPerSession
=
function
()
{
return
this
.
durationPerSession
;
};
ChallengeSchema
.
methods
.
getGoalPerSession
=
function
()
{
return
this
.
goalPerSession
;
};
ChallengeSchema
.
methods
.
getStatus
=
function
()
{
return
this
.
status
;
};
ChallengeSchema
.
methods
.
serialize
=
function
()
{
let
challengeJSON
=
this
.
toJSON
();
return
challengeJSON
;
};
const
Challenge
=
mongoose
.
model
(
"Challenge"
,
ChallengeSchema
);
module
.
exports
=
Challenge
;
...
...
Please
register
or
login
to post a comment