diff --git a/server/app/apis/slides.py b/server/app/apis/slides.py index 945e1084018b2df451aaba310014b96262929671..ee9689b51ad13a95941b7b9033ec3556d33f74b6 100644 --- a/server/app/apis/slides.py +++ b/server/app/apis/slides.py @@ -26,7 +26,7 @@ slide_parser_edit.add_argument("background_image_id", default=sentinel, type=int class SlidesList(Resource): @protect_route(allowed_roles=["*"]) def get(self, competition_id): - """ Gets the all slides from the specified competition. """ + """ Gets all slides from the specified competition. """ items = dbc.get.slide_list(competition_id) return list_response(list_schema.dump(items)) diff --git a/server/app/apis/teams.py b/server/app/apis/teams.py index 82b8856738c931a5fb2e7985d685c5e859337046..913deeb789340939c3dcb37f4a3edefbd7d06e95 100644 --- a/server/app/apis/teams.py +++ b/server/app/apis/teams.py @@ -26,7 +26,7 @@ team_parser_edit.add_argument("name", type=str, default=sentinel, location="json class TeamsList(Resource): @protect_route(allowed_roles=["*"]) def get(self, competition_id): - """ Gets the all teams to the specified competition. """ + """ Gets all teams to the specified competition. """ items = dbc.get.team_list(competition_id) return list_response(list_schema.dump(items)) diff --git a/server/app/apis/users.py b/server/app/apis/users.py index dc26ac5b64e9a4270215374de84f3c71cae66f9e..7cff57c8118a8b854944042a5c8ea6aad2fe11da 100644 --- a/server/app/apis/users.py +++ b/server/app/apis/users.py @@ -1,11 +1,15 @@ +""" +All API calls concerning question alternatives. +Default route: /api/users +""" + import app.core.http_codes as codes import app.database.controller as dbc from app.apis import item_response, list_response, protect_route from app.core.dto import UserDTO -from flask_jwt_extended import get_jwt_identity -from flask_restx import Resource -from flask_restx import inputs, reqparse from app.core.parsers import search_parser, sentinel +from flask_jwt_extended import get_jwt_identity +from flask_restx import Resource, inputs, reqparse api = UserDTO.api schema = UserDTO.schema @@ -25,13 +29,14 @@ user_search_parser.add_argument("role_id", type=int, default=sentinel, location= def _edit_user(item_user, args): + """ Edits a user using the provided arguments. """ + email = args.get("email") name = args.get("name") if email: if dbc.get.user_exists(email): api.abort(codes.BAD_REQUEST, "Email is already in use") - if name: args["name"] = args["name"].title() @@ -42,11 +47,15 @@ def _edit_user(item_user, args): class UsersList(Resource): @protect_route(allowed_roles=["*"]) def get(self): + """ Gets all users. """ + item = dbc.get.user(get_jwt_identity()) return item_response(schema.dump(item)) @protect_route(allowed_roles=["*"]) def put(self): + """ Posts a new user using the specified arguments. """ + args = user_parser_edit.parse_args(strict=True) item = dbc.get.user(get_jwt_identity()) item = _edit_user(item, args) @@ -58,11 +67,15 @@ class UsersList(Resource): class Users(Resource): @protect_route(allowed_roles=["*"]) def get(self, ID): + """ Gets the specified user. """ + item = dbc.get.user(ID) return item_response(schema.dump(item)) @protect_route(allowed_roles=["Admin"]) def put(self, ID): + """ Edits the specified team using the provided arguments. """ + args = user_parser_edit.parse_args(strict=True) item = dbc.get.user(ID) item = _edit_user(item, args) @@ -73,6 +86,8 @@ class Users(Resource): class UserSearch(Resource): @protect_route(allowed_roles=["*"]) def get(self): + """ Finds a specific user based on the provided arguments. """ + args = user_search_parser.parse_args(strict=True) items, total = dbc.search.user(**args) return list_response(list_schema.dump(items), total)