diff --git a/server/app/apis/__init__.py b/server/app/apis/__init__.py index f79bacffa8e964fb935b7d0f1e5babc2c2b876e5..1be8ff47cbb48164187c170137267bc726d33cd5 100644 --- a/server/app/apis/__init__.py +++ b/server/app/apis/__init__.py @@ -2,9 +2,8 @@ from functools import wraps from flask_jwt_extended import verify_jwt_in_request from flask_jwt_extended.utils import get_jwt -from flask_jwt_extended.view_decorators import jwt_required from flask_smorest import Blueprint, abort -from marshmallow import Schema, fields +from flask_smorest.error_handler import ErrorSchema Blueprint.PAGINATION_HEADER_FIELD_NAME = "pagination" @@ -44,7 +43,7 @@ class ExtendedBlueprint(Blueprint): def decorator(func): # func = self.arguments(AuthorizationHeadersSchema, location="headers")(func) - func = self.alt_response(http_codes.UNAUTHORIZED, None, description="Unauthorized")(func) + func = self.alt_response(http_codes.UNAUTHORIZED, ErrorSchema, description="Unauthorized")(func) @wraps(func) def wrapper(*args, **kwargs): diff --git a/server/app/apis/alternatives.py b/server/app/apis/alternatives.py index 58caf1283820ff63f60c526abff8fe3565ffd03d..d4db80fc3405374f10b53665544714d9f97ad41e 100644 --- a/server/app/apis/alternatives.py +++ b/server/app/apis/alternatives.py @@ -11,6 +11,7 @@ from app.database import models from app.database.models import Question, QuestionAlternative from flask.views import MethodView from flask_smorest import abort +from flask_smorest.error_handler import ErrorSchema from . import ALL, ExtendedBlueprint, http_codes @@ -51,7 +52,7 @@ class Alternatives(MethodView): @blp.authorization(allowed_roles=ALL) @blp.arguments(AlternativeAddArgsSchema) @blp.response(http_codes.OK, QuestionAlternativeSchema) - @blp.alt_response(http_codes.CONFLICT, None, description="Could not add alternative") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Could not add alternative") def post(self, args, competition_id, slide_id, question_id): """ Posts a new question alternative to the specified @@ -64,7 +65,7 @@ class Alternatives(MethodView): class QuestionAlternatives(MethodView): @blp.authorization(allowed_roles=ALL, allowed_views=ALL) @blp.response(http_codes.OK, QuestionAlternativeSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Could not find alternative") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Could not find alternative") def get(self, competition_id, slide_id, question_id, alternative_id): """ Gets the specified question alternative. """ return dbc.get.question_alternative(competition_id, slide_id, question_id, alternative_id) @@ -72,9 +73,11 @@ class QuestionAlternatives(MethodView): @blp.authorization(allowed_roles=ALL) @blp.arguments(AlternativeEditArgsSchema) @blp.response(http_codes.OK, QuestionAlternativeSchema) - @blp.alt_response(http_codes.BAD_REQUEST, None, description="Paramters to edit alternative with is incorrect") - @blp.alt_response(http_codes.NOT_FOUND, None, description="Could not find alternative") - @blp.alt_response(http_codes.CONFLICT, None, description="Could not edit alternative with the given values") + @blp.alt_response( + http_codes.BAD_REQUEST, ErrorSchema, description="Paramters to edit alternative with is incorrect" + ) + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Could not find alternative") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Could not edit alternative with the given values") def put(self, args, competition_id, slide_id, question_id, alternative_id): """ Edits the specified question alternative using the provided arguments. @@ -112,8 +115,8 @@ class QuestionAlternatives(MethodView): @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.NO_CONTENT, None) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Could not find alternative") - @blp.alt_response(http_codes.CONFLICT, None, description="Could not delete alternative") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Could not find alternative") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Could not delete alternative") def delete(self, competition_id, slide_id, question_id, alternative_id): """ Deletes the specified question alternative. """ dbc.delete.default(dbc.get.question_alternative(competition_id, slide_id, question_id, alternative_id)) diff --git a/server/app/apis/auth.py b/server/app/apis/auth.py index 137abd40626a1bd5a7571e3d2921153eae19d178..cf3f78dab3992b859e096b4cdc01fa70e702f522 100644 --- a/server/app/apis/auth.py +++ b/server/app/apis/auth.py @@ -16,6 +16,7 @@ from flask.views import MethodView from flask_jwt_extended import create_access_token, get_jti from flask_jwt_extended.utils import get_jti, get_jwt from flask_smorest import abort +from flask_smorest.error_handler import ErrorSchema from . import ALL, ExtendedBlueprint, http_codes @@ -58,7 +59,7 @@ def get_code_claims(item_code): @blp.route("/test") class AuthSignup(MethodView): - @blp.authorization(allowed_roles=["Admin"], allowed_views=ALL) + @blp.authorization(allowed_roles=["Admin"], allowed_views=["*"]) @blp.response(http_codes.NO_CONTENT, None) def get(self): """ Tests that the user is admin or is in a competition. """ @@ -118,7 +119,7 @@ class AuthLogin(MethodView): @blp.route("/logout") class AuthLogout(MethodView): - @blp.authorization(allowed_roles=ALL, allowed_views=ALL) + @blp.authorization(allowed_roles="*", allowed_views=["*"]) @blp.response(http_codes.NO_CONTENT, None) def post(self): """ Logs out. """ @@ -141,8 +142,8 @@ class CodeResponseSchema(ma.Schema): class AuthLoginCode(MethodView): @blp.arguments(CodeArgsSchema) @blp.response(http_codes.OK, CodeResponseSchema) - @blp.alt_response(http_codes.UNAUTHORIZED, None, description="Incorrect code or competition is not active") - @blp.alt_response(http_codes.NOT_FOUND, None, description="The code doesn't exist") + @blp.alt_response(http_codes.UNAUTHORIZED, ErrorSchema, description="Incorrect code or competition is not active") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="The code doesn't exist") def post(self, args): """ Logs in using the provided competition code. """ diff --git a/server/app/apis/codes.py b/server/app/apis/codes.py index 3da6a86178732de276d9dd53373e93f33ff31b5c..8ea7901763bf85e01417ecabadeb843c3b7d1dcc 100644 --- a/server/app/apis/codes.py +++ b/server/app/apis/codes.py @@ -7,6 +7,7 @@ import app.database.controller as dbc from app.core.schemas import CodeSchema from app.database.models import Code from flask.views import MethodView +from flask_smorest.error_handler import ErrorSchema from . import ALL, ExtendedBlueprint, http_codes @@ -28,7 +29,7 @@ class CodesList(MethodView): class CodesById(MethodView): @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.OK, CodeSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Code not found") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Code not found") def put(self, competition_id, code_id): """ Generates a new competition code. """ return dbc.edit.default(dbc.get.one(Code, code_id), code=dbc.utils.generate_unique_code()) diff --git a/server/app/apis/competitions.py b/server/app/apis/competitions.py index 001ce8b3d90fddf6716f38cd15dda6478d8128ac..4f31c8b6338d5335fc85e6b091694d08ba59fc4d 100644 --- a/server/app/apis/competitions.py +++ b/server/app/apis/competitions.py @@ -10,6 +10,7 @@ from app.core.schemas import BaseSchema, CompetitionSchema from app.database import models from app.database.models import Competition from flask.views import MethodView +from flask_smorest.error_handler import ErrorSchema from . import ALL, ExtendedBlueprint, http_codes @@ -52,7 +53,7 @@ class Competitions(MethodView): @blp.authorization(allowed_roles=ALL) @blp.arguments(CompetitionAddArgsSchema) @blp.response(http_codes.OK, CompetitionSchema) - @blp.alt_response(http_codes.CONFLICT, None, description="Competition could not be added") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Competition could not be added") def post(self, args): """ Adds a new competition. """ return dbc.add.competition(**args) @@ -62,7 +63,7 @@ class Competitions(MethodView): class CompetitionById(MethodView): @blp.authorization(allowed_roles=ALL, allowed_views=ALL) @blp.response(http_codes.OK, CompetitionSchemaRich) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Competition not found") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Competition not found") def get(self, competition_id): """ Gets the specified competition. """ return dbc.get.competition(competition_id) @@ -70,16 +71,16 @@ class CompetitionById(MethodView): @blp.authorization(allowed_roles=ALL) @blp.arguments(CompetitionEditArgsSchema) @blp.response(http_codes.OK, CompetitionSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Competition not found") - @blp.alt_response(http_codes.CONFLICT, None, description="Competition could not be updated") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Competition not found") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Competition could not be updated") def put(self, args, competition_id): """ Edits the specified competition with the specified arguments. """ return dbc.edit.default(dbc.get.one(Competition, competition_id), **args) @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.NO_CONTENT, None) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Competition not found") - @blp.alt_response(http_codes.CONFLICT, None, description="Competition could not be deleted") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Competition not found") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Competition could not be deleted") def delete(self, competition_id): """ Deletes the specified competition. """ dbc.delete.competition(dbc.get.one(Competition, competition_id)) @@ -101,8 +102,8 @@ class CompetitionSearch(MethodView): class SlidesOrder(MethodView): @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.OK, CompetitionSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Competition not found") - @blp.alt_response(http_codes.CONFLICT, None, description="Competition could not be copied") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Competition not found") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Competition could not be copied") def post(self, competition_id): """ Creates a deep copy of the specified competition. """ return dbc.copy.competition(dbc.get.competition(competition_id)) diff --git a/server/app/apis/components.py b/server/app/apis/components.py index 2d4099b10fb6aaac29a58272bc5d999ab455b37a..b72053fa8b861dec25c658295f43de4fc862ad49 100644 --- a/server/app/apis/components.py +++ b/server/app/apis/components.py @@ -6,6 +6,7 @@ Default route: /api/competitions/<competition_id>/slides/<slide_id>/components import app.database.controller as dbc from app.core.schemas import BaseSchema, ComponentSchema from flask.views import MethodView +from flask_smorest.error_handler import ErrorSchema from marshmallow import fields from . import ALL, ExtendedBlueprint, http_codes @@ -68,7 +69,7 @@ class Components(MethodView): class ComponentById(MethodView): @blp.authorization(allowed_roles=ALL, allowed_views=ALL) @blp.response(http_codes.OK, ComponentSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Could not find component") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Could not find component") def get(self, competition_id, slide_id, component_id): """ Gets the specified component. """ return dbc.get.component(competition_id, slide_id, component_id) @@ -76,16 +77,16 @@ class ComponentById(MethodView): @blp.authorization(allowed_roles=ALL) @blp.arguments(ComponentEditArgsSchema) @blp.response(http_codes.OK, ComponentSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Could not find component") - @blp.alt_response(http_codes.CONFLICT, None, description="Could not update component with given values") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Could not find component") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Could not update component with given values") def put(self, args, competition_id, slide_id, component_id): """ Edits the specified component using the provided arguments. """ return dbc.edit.default(dbc.get.component(competition_id, slide_id, component_id), **args) @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.NO_CONTENT, None) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Could not find component") - @blp.alt_response(http_codes.CONFLICT, None, description="Could not delete component") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Could not find component") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Could not delete component") def delete(self, competition_id, slide_id, component_id): """ Deletes the specified component. """ dbc.delete.component(dbc.get.component(competition_id, slide_id, component_id)) diff --git a/server/app/apis/media.py b/server/app/apis/media.py index d9fc8e7123ba7b7b1c51df0c6d2b507ab3c7f6ef..a20cd1b0bdba88518be7a430f5ea71f910d71adc 100644 --- a/server/app/apis/media.py +++ b/server/app/apis/media.py @@ -12,6 +12,7 @@ from flask import request from flask.views import MethodView from flask_jwt_extended import get_jwt_identity from flask_smorest import abort +from flask_smorest.error_handler import ErrorSchema from flask_uploads import UploadNotAllowed from sqlalchemy import exc @@ -40,8 +41,8 @@ class Images(MethodView): @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.OK, MediaSchema) - @blp.alt_response(http_codes.BAD_REQUEST, None, description="Could not save image") - @blp.alt_response(http_codes.INTERNAL_SERVER_ERROR, None, description="Could not save image") + @blp.alt_response(http_codes.BAD_REQUEST, ErrorSchema, description="Could not save image") + @blp.alt_response(http_codes.INTERNAL_SERVER_ERROR, ErrorSchema, description="Could not save image") def post(self): """ Posts the specified image. """ @@ -73,7 +74,7 @@ class ImageById(MethodView): @blp.response(http_codes.NO_CONTENT, None) @blp.response(http_codes.CONFLICT, None, description="Could not delete image it is used by something") @blp.response(http_codes.BAD_REQUEST, None, description="Failed to delete image") - @blp.response(http_codes.INTERNAL_SERVER_ERROR, None, description="Somehting very serious went wrong") + @blp.response(http_codes.INTERNAL_SERVER_ERROR, ErrorSchema, description="Somehting very serious went wrong") def delete(self, media_id): """ Deletes the specified image. """ item = dbc.get.one(models.Media, media_id) diff --git a/server/app/apis/misc.py b/server/app/apis/misc.py index e13982ac9b41c05da736b55bf4c2874cec02aaba..713a707db73f56cf5d8e332f615c4a3c558ba52d 100644 --- a/server/app/apis/misc.py +++ b/server/app/apis/misc.py @@ -17,6 +17,7 @@ from app.core.schemas import ( from app.database import models from app.database.models import City, Competition, ComponentType, MediaType, QuestionType, Role, User, ViewType from flask.views import MethodView +from flask_smorest.error_handler import ErrorSchema from marshmallow_sqlalchemy import auto_field from . import ALL, ExtendedBlueprint, http_codes @@ -82,8 +83,10 @@ class Cities(MethodView): @blp.authorization(allowed_roles=["Admin"]) @blp.arguments(CitySchema) @blp.response(http_codes.OK, CitySchema(many=True)) - @blp.alt_response(http_codes.NOT_FOUND, None, description="City not found") - @blp.alt_response(http_codes.CONFLICT, None, description="The city can't be updated with the provided values") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="City not found") + @blp.alt_response( + http_codes.CONFLICT, ErrorSchema, description="The city can't be updated with the provided values" + ) def put(self, args, city_id): """ Edits the specified city with the provided arguments. """ dbc.edit.default(dbc.get.one(City, city_id), **args) @@ -91,8 +94,10 @@ class Cities(MethodView): @blp.authorization(allowed_roles=["Admin"]) @blp.response(http_codes.OK, CitySchema(many=True)) - @blp.alt_response(http_codes.NOT_FOUND, None, description="City not found") - @blp.alt_response(http_codes.CONFLICT, None, description="The city can't be updated with the provided values") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="City not found") + @blp.alt_response( + http_codes.CONFLICT, ErrorSchema, description="The city can't be updated with the provided values" + ) def delete(self, city_id): """ Deletes the specified city. """ dbc.delete.default(dbc.get.one(City, city_id)) diff --git a/server/app/apis/questions.py b/server/app/apis/questions.py index 5b92156fd85f05fd96b0585675a9b1d5d24eb059..092c91d5460fbc877d05d2f67bf00130151eb4e3 100644 --- a/server/app/apis/questions.py +++ b/server/app/apis/questions.py @@ -8,6 +8,7 @@ from app.core import ma from app.core.schemas import BaseSchema, QuestionSchema from app.database import models from flask.views import MethodView +from flask_smorest.error_handler import ErrorSchema from . import ALL, ExtendedBlueprint, http_codes @@ -50,7 +51,7 @@ class Questions(MethodView): @blp.authorization(allowed_roles=ALL) @blp.arguments(QuestionAddArgsSchema) @blp.response(http_codes.OK, QuestionSchema) - @blp.alt_response(http_codes.CONFLICT, None, description="Could not add question") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Could not add question") def post(self, args, competition_id, slide_id): """ Posts a new question to the specified slide using the provided arguments. """ return dbc.add.question(slide_id=slide_id, **args) @@ -60,7 +61,7 @@ class Questions(MethodView): class QuestionById(MethodView): @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.OK, QuestionSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Could not find question") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Could not find question") def get(self, competition_id, slide_id, question_id): """ Gets the specified question using the specified competition and slide. @@ -70,16 +71,16 @@ class QuestionById(MethodView): @blp.authorization(allowed_roles=ALL) @blp.arguments(QuestionEditArgsSchema) @blp.response(http_codes.OK, QuestionSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Could not find question") - @blp.alt_response(http_codes.CONFLICT, None, description="Could not edit question") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Could not find question") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Could not edit question") def put(self, args, competition_id, slide_id, question_id): """ Edits the specified question with the provided arguments. """ return dbc.edit.default(dbc.get.question(competition_id, slide_id, question_id), **args) @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.NO_CONTENT, None) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Could not find question") - @blp.alt_response(http_codes.CONFLICT, None, description="Could not delete question") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Could not find question") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Could not delete question") def delete(self, competition_id, slide_id, question_id): """ Deletes the specified question. """ dbc.delete.question(dbc.get.question(competition_id, slide_id, question_id)) diff --git a/server/app/apis/scores.py b/server/app/apis/scores.py index b5baf7a28fbc58e677a1deec5cd619938c017866..8e7208d685538b0e83970cb2accff3f5caa93938 100644 --- a/server/app/apis/scores.py +++ b/server/app/apis/scores.py @@ -8,6 +8,7 @@ from app.core import ma from app.core.schemas import BaseSchema, QuestionScoreSchema from app.database import models from flask.views import MethodView +from flask_smorest.error_handler import ErrorSchema from . import ALL, ExtendedBlueprint, http_codes @@ -39,7 +40,7 @@ class QuestionScoreList(MethodView): class QuestionScores(MethodView): @blp.authorization(allowed_roles=ALL, allowed_views=ALL) @blp.response(http_codes.OK, QuestionScoreSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Cant find answer") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Cant find answer") def get(self, competition_id, team_id, question_id): """ Gets the score for the provided team on the provided question. """ return dbc.get.question_score(competition_id, team_id, question_id) @@ -47,8 +48,8 @@ class QuestionScores(MethodView): @blp.authorization(allowed_roles=ALL, allowed_views=ALL) @blp.arguments(ScoreAddArgsSchema) @blp.response(http_codes.OK, QuestionScoreSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Cant find score") - @blp.alt_response(http_codes.CONFLICT, None, description="Can't add or edit score with provided values") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Cant find score") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Can't add or edit score with provided values") def put(self, args, competition_id, team_id, question_id): """ Add or edit specified quesiton_answer. """ diff --git a/server/app/apis/slides.py b/server/app/apis/slides.py index b12386ce71194b6438a40866239e5e35629adc27..86854efc9cf764250bc34d7791503c2362de8a5f 100644 --- a/server/app/apis/slides.py +++ b/server/app/apis/slides.py @@ -10,6 +10,7 @@ from app.database import models from app.database.models import Competition, Slide from flask.views import MethodView from flask_smorest import abort +from flask_smorest.error_handler import ErrorSchema from . import ALL, ExtendedBlueprint, http_codes @@ -41,7 +42,7 @@ class Slides(MethodView): @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.OK, SlideSchema) - @blp.alt_response(http_codes.CONFLICT, None, description="Can't add slide") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Can't add slide") def post(self, competition_id): """ Posts a new slide to the specified competition. """ return dbc.add.slide(competition_id) @@ -51,7 +52,7 @@ class Slides(MethodView): class Slides(MethodView): @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.OK, SlideSchema) - @blp.alt_response(http_codes.NOT_FOUND, None) + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema) def get(self, competition_id, slide_id): """ Gets the specified slide. """ return dbc.get.slide(competition_id, slide_id) @@ -59,8 +60,8 @@ class Slides(MethodView): @blp.authorization(allowed_roles=ALL) @blp.arguments(SlideEditArgsSchema) @blp.response(http_codes.OK, SlideSchema) - @blp.alt_response(http_codes.CONFLICT, None, description="Can't edit slide") - @blp.alt_response(http_codes.BAD_REQUEST, None, description="Can't edit slide with the provided arguments") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Can't edit slide") + @blp.alt_response(http_codes.BAD_REQUEST, ErrorSchema, description="Can't edit slide with the provided arguments") def put(self, args, competition_id, slide_id): """ Edits the specified slide using the provided arguments. """ @@ -78,8 +79,8 @@ class Slides(MethodView): @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.NO_CONTENT, None) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Slide not found") - @blp.alt_response(http_codes.CONFLICT, None, description="Can't delete slide") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Slide not found") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Can't delete slide") def delete(self, competition_id, slide_id): """ Deletes the specified slide. """ dbc.delete.slide(dbc.get.slide(competition_id, slide_id)) @@ -90,7 +91,7 @@ class Slides(MethodView): class SlideCopy(MethodView): @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.OK, SlideSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Can't find slide") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Can't find slide") def post(self, competition_id, slide_id): """ Creates a deep copy of the specified slide. """ return dbc.copy.slide(dbc.get.slide(competition_id, slide_id)) diff --git a/server/app/apis/teams.py b/server/app/apis/teams.py index c9c5b669d44215f42c4e725dd34c31057c1aae17..7a1b4841f1a327f006abf5675a326b13f12f4028 100644 --- a/server/app/apis/teams.py +++ b/server/app/apis/teams.py @@ -3,6 +3,7 @@ All API calls concerning question alternatives. Default route: /api/competitions/<competition_id>/teams """ +from flask_smorest.error_handler import ErrorSchema import app.database.controller as dbc from app.core import ma from app.core.schemas import BaseSchema, TeamSchema @@ -44,7 +45,7 @@ class Teams(MethodView): @blp.authorization(allowed_roles=ALL) @blp.arguments(TeamAddArgsSchema) @blp.response(http_codes.OK, TeamSchema) - @blp.alt_response(http_codes.CONFLICT, None, description="Could not add team") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="Could not add team") def post(self, args, competition_id): """ Posts a new team to the specified competition. """ return dbc.add.team(args["name"], competition_id) @@ -54,7 +55,7 @@ class Teams(MethodView): class TeamsById(MethodView): @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.OK, TeamSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Could not find team") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Could not find team") def get(self, competition_id, team_id): """ Gets the specified team. """ return dbc.get.team(competition_id, team_id) @@ -62,14 +63,14 @@ class TeamsById(MethodView): @blp.authorization(allowed_roles=ALL) @blp.arguments(TeamEditArgsSchema) @blp.response(http_codes.OK, TeamSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Could not find team") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Could not find team") def put(self, args, competition_id, team_id): """ Edits the specified team using the provided arguments. """ return dbc.edit.default(dbc.get.team(competition_id, team_id), **args) @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.NO_CONTENT, None) - @blp.alt_response(http_codes.NOT_FOUND, None, description="Could not find team") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="Could not find team") def delete(self, competition_id, team_id): """ Deletes the specified team. """ dbc.delete.team(dbc.get.team(competition_id, team_id)) diff --git a/server/app/apis/users.py b/server/app/apis/users.py index 54001495345bc55ea802c77ebd994f0591efdd20..9617cd4543bbe0ff97eead8d0a34d9f2bfed86fe 100644 --- a/server/app/apis/users.py +++ b/server/app/apis/users.py @@ -12,6 +12,7 @@ from app.database.models import User, Whitelist from flask.views import MethodView from flask_jwt_extended.utils import get_jwt_identity from flask_smorest import abort +from flask_smorest.error_handler import ErrorSchema from marshmallow import fields from . import ALL, ExtendedBlueprint, http_codes @@ -79,7 +80,7 @@ class Users(MethodView): class UsersById(MethodView): @blp.authorization(allowed_roles=ALL) @blp.response(http_codes.OK, UserSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="User not found") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="User not found") def get(self, user_id): """ Get user with <user_id> """ return dbc.get.one(User, user_id) @@ -87,16 +88,18 @@ class UsersById(MethodView): @blp.authorization(allowed_roles=["Admin"]) @blp.arguments(UserEditArgsSchema) @blp.response(http_codes.OK, UserSchema) - @blp.alt_response(http_codes.NOT_FOUND, None, description="User not found") - @blp.alt_response(http_codes.CONFLICT, None, description="The user can't be updated with the provided values") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="User not found") + @blp.alt_response( + http_codes.CONFLICT, ErrorSchema, description="The user can't be updated with the provided values" + ) def put(self, args, user_id): """ Edits user with <user_id> """ return _edit_user(dbc.get.one(User, user_id), args) @blp.authorization(allowed_roles=["Admin"]) @blp.response(http_codes.NO_CONTENT, None) - @blp.alt_response(http_codes.NOT_FOUND, None, description="User not found") - @blp.alt_response(http_codes.CONFLICT, None, description="The user can't be deleted") + @blp.alt_response(http_codes.NOT_FOUND, ErrorSchema, description="User not found") + @blp.alt_response(http_codes.CONFLICT, ErrorSchema, description="The user can't be deleted") def delete(self, user_id): """ Deletes the specified user and adds their token to the blacklist. """ item_user = dbc.get.one(User, user_id)