Skip to content
Snippets Groups Projects
Commit 0dfec37b authored by Josef Olsson's avatar Josef Olsson
Browse files

Commented question answer API

parent 9bccf62a
No related branches found
No related tags found
1 merge request!130Resolve "Comment apis"
"""
All API calls concerning question answers.
Default route: /api/competitions/<competition_id>/teams/<team_id>/answers
"""
import app.database.controller as dbc
from app.apis import item_response, list_response, protect_route
from app.core.dto import QuestionAnswerDTO
from flask_restx import Resource
from flask_restx import reqparse
from app.core.parsers import sentinel
from flask_restx import Resource, reqparse
api = QuestionAnswerDTO.api
schema = QuestionAnswerDTO.schema
......@@ -24,11 +28,15 @@ answer_parser_edit.add_argument("score", type=int, default=sentinel, location="j
class QuestionAnswerList(Resource):
@protect_route(allowed_roles=["*"], allowed_views=["*"])
def get(self, competition_id, team_id):
""" Gets the all question answers that the specified team has given. """
items = dbc.get.question_answer_list(competition_id, team_id)
return list_response(list_schema.dump(items))
@protect_route(allowed_roles=["*"], allowed_views=["*"])
def post(self, competition_id, team_id):
""" Posts a new question answer to the specified question. """
args = answer_parser_add.parse_args(strict=True)
item = dbc.add.question_answer(**args, team_id=team_id)
return item_response(schema.dump(item))
......@@ -39,12 +47,19 @@ class QuestionAnswerList(Resource):
class QuestionAnswers(Resource):
@protect_route(allowed_roles=["*"], allowed_views=["*"])
def get(self, competition_id, team_id, answer_id):
""" Gets the specified question answer. """
item = dbc.get.question_answer(competition_id, team_id, answer_id)
return item_response(schema.dump(item))
@protect_route(allowed_roles=["*"], allowed_views=["*"])
def put(self, competition_id, team_id, answer_id):
""" Edits the specified question answer. """
args = answer_parser_edit.parse_args(strict=True)
item = dbc.get.question_answer(competition_id, team_id, answer_id)
item = dbc.edit.default(item, **args)
return item_response(schema.dump(item))
# No need to delete an answer. It only needs to be deleted
# together with the question or the team.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment