Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
CTF
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grzegorz
CTF
Commits
1b254ac5
Commit
1b254ac5
authored
Mar 20, 2016
by
Grzegorz Pietrusza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor /solutions/my enpoint
parent
43a25a56
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
4 deletions
+46
-4
Task.java
...a/com/telephoners/krakyournet/ctf/objects/tasks/Task.java
+25
-1
SolutionsRepository.java
...ers/krakyournet/ctf/repositories/SolutionsRepository.java
+0
-1
SolutionsResource.java
...ephoners/krakyournet/ctf/resources/SolutionsResource.java
+21
-2
No files found.
service/src/main/java/com/telephoners/krakyournet/ctf/objects/tasks/Task.java
View file @
1b254ac5
...
...
@@ -15,7 +15,6 @@ import java.util.List;
public
abstract
class
Task
{
@Id
//todo: use id to identify task?
protected
ObjectId
id
;
@PublicProperty
protected
String
name
;
...
...
@@ -63,4 +62,29 @@ public abstract class Task
{
this
.
flags
=
flags
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
Task
task
=
(
Task
)
o
;
if
(
level
!=
task
.
level
)
return
false
;
if
(
id
!=
null
?
!
id
.
equals
(
task
.
id
)
:
task
.
id
!=
null
)
return
false
;
if
(
name
!=
null
?
!
name
.
equals
(
task
.
name
)
:
task
.
name
!=
null
)
return
false
;
return
flags
!=
null
?
flags
.
equals
(
task
.
flags
)
:
task
.
flags
==
null
;
}
@Override
public
int
hashCode
()
{
int
result
=
id
!=
null
?
id
.
hashCode
()
:
0
;
result
=
31
*
result
+
(
name
!=
null
?
name
.
hashCode
()
:
0
);
result
=
31
*
result
+
level
;
result
=
31
*
result
+
(
flags
!=
null
?
flags
.
hashCode
()
:
0
);
return
result
;
}
}
service/src/main/java/com/telephoners/krakyournet/ctf/repositories/SolutionsRepository.java
View file @
1b254ac5
...
...
@@ -7,7 +7,6 @@ import org.mongodb.morphia.Datastore;
import
javax.inject.Inject
;
import
javax.inject.Singleton
;
import
java.util.List
;
import
java.util.function.Predicate
;
import
java.util.stream.Collectors
;
@Singleton
...
...
service/src/main/java/com/telephoners/krakyournet/ctf/resources/SolutionsResource.java
View file @
1b254ac5
...
...
@@ -3,6 +3,7 @@ package com.telephoners.krakyournet.ctf.resources;
import
com.telephoners.krakyournet.ctf.objects.Solution
;
import
com.telephoners.krakyournet.ctf.objects.Team
;
import
com.telephoners.krakyournet.ctf.objects.User
;
import
com.telephoners.krakyournet.ctf.objects.tasks.Task
;
import
com.telephoners.krakyournet.ctf.repositories.SolutionsRepository
;
import
com.telephoners.krakyournet.ctf.repositories.TasksRepository
;
import
com.telephoners.krakyournet.ctf.repositories.TeamsRepository
;
...
...
@@ -52,10 +53,28 @@ public class SolutionsResource
@GET
@Path
(
"/my"
)
public
List
<
Solution
>
getTeamSolutions
(
@Auth
User
user
)
public
Map
<
Integer
,
List
<
String
>
>
getTeamSolutions
(
@Auth
User
user
)
{
Optional
<
Team
>
team
=
teamsRepository
.
getTeamByUser
(
user
);
return
solutionsRepository
.
getByTeam
(
team
.
get
());
//todo: per task
List
<
Solution
>
byTeam
=
solutionsRepository
.
getByTeam
(
team
.
get
());
Map
<
Task
,
List
<
Solution
>>
collect
=
byTeam
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
new
Function
<
Solution
,
Task
>()
{
@Override
public
Task
apply
(
Solution
solution
)
{
return
solution
.
getTask
();
}
}));
Map
<
Integer
,
List
<
String
>>
collect1
=
collect
.
entrySet
().
stream
()
.
collect
(
Collectors
.
toMap
(
taskSolutions
->
taskSolutions
.
getKey
().
getLevel
(),
taskSolutions
->
taskSolutions
.
getValue
().
stream
()
.
map
(
solution
->
solution
.
getFlag
().
getDescription
()).
collect
(
Collectors
.
toList
())
));
return
collect1
;
}
@GET
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment