Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
MilderJoghurt
rlf-server
Commits
6158f66e
Commit
6158f66e
authored
Jun 22, 2015
by
Fjen Undso
Browse files
move all vote/question specific code to the right controller
parent
7aaddaa0
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/controllers/QuestionController.java
View file @
6158f66e
...
...
@@ -44,4 +44,44 @@ public class QuestionController extends Controller {
return
badRequest
(
"owner missing"
);
}
}
/**
* Gets all {@link QuestionAnswer}s for a {@link Session}
*
* @param sid
* the ID of a Session
* @return list of QuestionAnswers
*/
public
static
Result
getAnswers
(
String
sid
)
{
Session
session
=
Session
.
find
.
byId
(
sid
);
if
(
session
==
null
)
{
return
notFound
(
"session not found"
);
}
else
{
return
ok
(
Json
.
toJson
(
session
.
questionAnswers
));
}
}
/**
* Deletes all {@link QuestionAnswer}s from a {@link Session}
*
* @param sid
* the ID of a Session
* @param owner
* the owner of the Session
* @return HTTP 204 if reseted
*/
public
static
Result
resetAnswers
(
String
sid
,
String
owner
)
{
Session
session
=
Session
.
find
.
byId
(
sid
);
if
(
session
==
null
)
{
return
notFound
(
"session not found"
);
}
if
(
session
.
owner
.
equals
(
owner
))
{
session
.
resetAnswers
();
session
.
save
();
return
noContent
();
}
else
{
return
forbidden
(
"wrong owner"
);
}
}
}
app/controllers/SessionController.java
View file @
6158f66e
...
...
@@ -2,9 +2,7 @@ package controllers;
import
java.util.List
;
import
models.QuestionAnswer
;
import
models.Session
;
import
models.Vote
;
import
play.libs.Json
;
import
play.mvc.BodyParser
;
import
play.mvc.Controller
;
...
...
@@ -121,60 +119,4 @@ public class SessionController extends Controller {
return
forbidden
(
"wrong owner"
);
}
}
/**
* Gets all {@link Vote}s for a {@link Session}
*
* @param sid
* the ID of a Session
* @return list of Votes
*/
public
static
Result
getVotes
(
String
sid
)
{
Session
session
=
Session
.
find
.
byId
(
sid
);
if
(
session
==
null
)
{
return
notFound
(
"session not found"
);
}
else
{
return
ok
(
Json
.
toJson
(
session
.
votes
));
}
}
/**
* Gets all {@link QuestionAnswer}s for a {@link Session}
*
* @param sid
* the ID of a Session
* @return list of QuestionAnswers
*/
public
static
Result
getAnswers
(
String
sid
)
{
Session
session
=
Session
.
find
.
byId
(
sid
);
if
(
session
==
null
)
{
return
notFound
(
"session not found"
);
}
else
{
return
ok
(
Json
.
toJson
(
session
.
questionAnswers
));
}
}
/**
* Deletes all {@link QuestionAnswer}s from a {@link Session}
*
* @param sid
* the ID of a Session
* @param owner
* the owner of the Session
* @return HTTP 204 if reseted
*/
public
static
Result
resetAnswers
(
String
sid
,
String
owner
)
{
Session
session
=
Session
.
find
.
byId
(
sid
);
if
(
session
==
null
)
{
return
notFound
(
"session not found"
);
}
if
(
session
.
owner
.
equals
(
owner
))
{
session
.
resetAnswers
();
session
.
save
();
return
noContent
();
}
else
{
return
forbidden
(
"wrong owner"
);
}
}
}
\ No newline at end of file
}
app/controllers/VoteController.java
View file @
6158f66e
...
...
@@ -42,4 +42,20 @@ public class VoteController extends Controller {
return
badRequest
(
"owner missing"
);
}
}
/**
* Gets all {@link Vote}s for a {@link Session}
*
* @param sid
* the ID of a Session
* @return list of Votes
*/
public
static
Result
getVotes
(
String
sid
)
{
Session
session
=
Session
.
find
.
byId
(
sid
);
if
(
session
==
null
)
{
return
notFound
(
"session not found"
);
}
else
{
return
ok
(
Json
.
toJson
(
session
.
votes
));
}
}
}
conf/routes
View file @
6158f66e
...
...
@@ -9,14 +9,13 @@ GET /sessions/:sid controllers.SessionController.getSession(si
POST /sessions controllers.SessionController.createSession
PUT /sessions/:sid controllers.SessionController.updateSession(sid: String)
DELETE /sessions/:sid/:owner controllers.SessionController.deleteSession(sid: String, owner: String)
GET /sessions/:sid/votes controllers.SessionController.getVotes(sid: String)
GET /sessions/:sid/answers controllers.SessionController.getAnswers(sid: String)
POST /sessions/:sid/resetanswers/:owner controllers.SessionController.resetAnswers(sid: String, owner: String)
# TODO: aggregierte daten abfragen
# Questionsanswer
POST /answers/:sid controllers.QuestionController.createAnswer(sid: String)
GET /sessions/:sid/answers controllers.QuestionController.getAnswers(sid: String)
POST /sessions/:sid/answers controllers.QuestionController.createAnswer(sid: String)
POST /sessions/:sid/resetanswers/:owner controllers.QuestionController.resetAnswers(sid: String, owner: String)
# Vote
POST /votes/:sid controllers.VoteController.createVote(sid: String)
GET /sessions/:sid/votes controllers.VoteController.getVotes(sid: String)
POST /sessions/:sid/votes controllers.VoteController.createVote(sid: String)
# TODO: aggregierte daten abfragen
\ No newline at end of file
test/ControllerTest.java
View file @
6158f66e
...
...
@@ -24,7 +24,9 @@ import com.avaje.ebean.EbeanServer;
import
com.avaje.ebeaninternal.server.ddl.DdlGenerator
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
controllers.QuestionController
;
import
controllers.SessionController
;
import
controllers.VoteController
;
public
class
ControllerTest
{
public
static
FakeApplication
app
;
...
...
@@ -124,7 +126,7 @@ public class ControllerTest {
s1
.
save
();
s2
.
save
();
Result
result
=
Session
Controller
.
getVotes
(
s1
.
id
);
Result
result
=
Vote
Controller
.
getVotes
(
s1
.
id
);
assertEquals
(
OK
,
status
(
result
));
assertEquals
(
"application/json"
,
contentType
(
result
));
...
...
@@ -150,7 +152,7 @@ public class ControllerTest {
s1
.
save
();
s2
.
save
();
Result
result
=
S
es
s
ionController
.
getAnswers
(
s1
.
id
);
Result
result
=
Qu
es
t
ionController
.
getAnswers
(
s1
.
id
);
assertEquals
(
OK
,
status
(
result
));
assertEquals
(
"application/json"
,
contentType
(
result
));
...
...
Write
Preview
Supports
Markdown
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