Skip to content
Snippets Groups Projects
Commit b9fc5689 authored by Victor Löfgren's avatar Victor Löfgren
Browse files

Add team edit api

parent 082a32fd
No related branches found
No related tags found
1 merge request!55Resolve "Add more api calls"
...@@ -54,7 +54,7 @@ class Questions(Resource): ...@@ -54,7 +54,7 @@ class Questions(Resource):
@jwt_required @jwt_required
def delete(self, CID, QID): def delete(self, CID, QID):
item_question = dbc.get.question(CID, QID).first() item_question = dbc.get.question(CID, QID)
if not item_question: if not item_question:
return {"response": "No content found"}, codes.NOT_FOUND return {"response": "No content found"}, codes.NOT_FOUND
......
...@@ -3,6 +3,7 @@ import app.core.http_codes as codes ...@@ -3,6 +3,7 @@ import app.core.http_codes as codes
from app.apis import admin_required, item_response, list_response from app.apis import admin_required, item_response, list_response
from app.core.dto import TeamDTO from app.core.dto import TeamDTO
from app.core.models import Competition, Team from app.core.models import Competition, Team
from app.core.parsers import team_parser
from flask_jwt_extended import get_jwt_identity, jwt_required from flask_jwt_extended import get_jwt_identity, jwt_required
from flask_restx import Namespace, Resource, reqparse from flask_restx import Namespace, Resource, reqparse
...@@ -25,14 +26,10 @@ class TeamsList(Resource): ...@@ -25,14 +26,10 @@ class TeamsList(Resource):
@jwt_required @jwt_required
def post(self, CID): def post(self, CID):
parser = reqparse.RequestParser() args = team_parser.parse_args(strict=True)
parser.add_argument("name", type=str, location="json")
args = parser.parse_args(strict=True)
item_comp = get_comp(CID) item_comp = get_comp(CID)
dbc.add.team(args["name"], item_comp) item_team = dbc.add.team(args["name"], item_comp)
dbc.refresh(item_comp) return item_response(schema.dump(item_team))
return list_response(list_schema.dump(item_comp.teams))
@api.route("/<TID>") @api.route("/<TID>")
...@@ -46,5 +43,22 @@ class Teams(Resource): ...@@ -46,5 +43,22 @@ class Teams(Resource):
@jwt_required @jwt_required
def delete(self, CID, TID): def delete(self, CID, TID):
item_team = dbc.get.team(CID, TID) item_team = dbc.get.team(CID, TID)
if not item_team:
api.abort(codes.NOT_FOUND, f"Could not find team with id {TID} in competition with id {CID}.")
dbc.delete.team(item_team) dbc.delete.team(item_team)
return "deleted" return {}, codes.NO_CONTENT
@jwt_required
def put(self, CID, TID):
args = team_parser.parse_args(strict=True)
name = args.get("name")
competition_id = args.get("competition_id")
item_team = dbc.get.team(CID, TID)
if not item_team:
api.abort(codes.NOT_FOUND, f"Could not find team with id {TID} in competition with id {CID}.")
item_team = dbc.edit.team(item_team, name=name, competition_id=competition_id)
return item_response(schema.dump(item_team))
...@@ -31,6 +31,17 @@ def slide(item, title=None, timer=None): ...@@ -31,6 +31,17 @@ def slide(item, title=None, timer=None):
return item return item
def team(item_team, name=None, competition_id=None):
if name:
item_team.name = name
if competition_id:
item_team.competition_id = competition_id
db.session.commit()
db.session.refresh(item_team)
return item_team
def competition(item, name=None, year=None, city_id=None): def competition(item, name=None, year=None, city_id=None):
if name: if name:
item.name = name item.name = name
......
...@@ -17,7 +17,7 @@ def question(CID, QID): ...@@ -17,7 +17,7 @@ def question(CID, QID):
slide_ids = set( slide_ids = set(
[x.id for x in Slide.query.filter(Slide.competition_id == CID).all()] [x.id for x in Slide.query.filter(Slide.competition_id == CID).all()]
) # TODO: Filter using database instead of creating a set of slide_ids ) # TODO: Filter using database instead of creating a set of slide_ids
return Question.query.filter(Question.slide_id.in_(slide_ids) & (Question.id == QID)) return Question.query.filter(Question.slide_id.in_(slide_ids) & (Question.id == QID)).first()
def _search(query, order_column, page=0, page_size=15, order=1): def _search(query, order_column, page=0, page_size=15, order=1):
......
...@@ -69,3 +69,8 @@ question_search_parser.add_argument("name", type=str, default=None, location="js ...@@ -69,3 +69,8 @@ question_search_parser.add_argument("name", type=str, default=None, location="js
question_search_parser.add_argument("slide_id", type=int, default=None, location="json") question_search_parser.add_argument("slide_id", type=int, default=None, location="json")
question_search_parser.add_argument("type_id", type=int, default=None, location="json") question_search_parser.add_argument("type_id", type=int, default=None, location="json")
question_search_parser.add_argument("competition_id", type=int, default=None, location="json") question_search_parser.add_argument("competition_id", type=int, default=None, location="json")
###TEAM####
team_parser = reqparse.RequestParser()
team_parser.add_argument("name", type=str, location="json")
team_parser.add_argument("competition_id", type=int, location="json")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment