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

Comment user API

parent 8053980f
No related branches found
No related tags found
1 merge request!130Resolve "Comment apis"
Pipeline #44256 passed
This commit is part of merge request !130. Comments created here will be created in the context of that merge request.
...@@ -26,7 +26,7 @@ slide_parser_edit.add_argument("background_image_id", default=sentinel, type=int ...@@ -26,7 +26,7 @@ slide_parser_edit.add_argument("background_image_id", default=sentinel, type=int
class SlidesList(Resource): class SlidesList(Resource):
@protect_route(allowed_roles=["*"]) @protect_route(allowed_roles=["*"])
def get(self, competition_id): 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) items = dbc.get.slide_list(competition_id)
return list_response(list_schema.dump(items)) return list_response(list_schema.dump(items))
......
...@@ -26,7 +26,7 @@ team_parser_edit.add_argument("name", type=str, default=sentinel, location="json ...@@ -26,7 +26,7 @@ team_parser_edit.add_argument("name", type=str, default=sentinel, location="json
class TeamsList(Resource): class TeamsList(Resource):
@protect_route(allowed_roles=["*"]) @protect_route(allowed_roles=["*"])
def get(self, competition_id): 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) items = dbc.get.team_list(competition_id)
return list_response(list_schema.dump(items)) return list_response(list_schema.dump(items))
......
"""
All API calls concerning question alternatives.
Default route: /api/users
"""
import app.core.http_codes as codes import app.core.http_codes as codes
import app.database.controller as dbc import app.database.controller as dbc
from app.apis import item_response, list_response, protect_route from app.apis import item_response, list_response, protect_route
from app.core.dto import UserDTO 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 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 api = UserDTO.api
schema = UserDTO.schema schema = UserDTO.schema
...@@ -25,13 +29,14 @@ user_search_parser.add_argument("role_id", type=int, default=sentinel, location= ...@@ -25,13 +29,14 @@ user_search_parser.add_argument("role_id", type=int, default=sentinel, location=
def _edit_user(item_user, args): def _edit_user(item_user, args):
""" Edits a user using the provided arguments. """
email = args.get("email") email = args.get("email")
name = args.get("name") name = args.get("name")
if email: if email:
if dbc.get.user_exists(email): if dbc.get.user_exists(email):
api.abort(codes.BAD_REQUEST, "Email is already in use") api.abort(codes.BAD_REQUEST, "Email is already in use")
if name: if name:
args["name"] = args["name"].title() args["name"] = args["name"].title()
...@@ -42,11 +47,15 @@ def _edit_user(item_user, args): ...@@ -42,11 +47,15 @@ def _edit_user(item_user, args):
class UsersList(Resource): class UsersList(Resource):
@protect_route(allowed_roles=["*"]) @protect_route(allowed_roles=["*"])
def get(self): def get(self):
""" Gets all users. """
item = dbc.get.user(get_jwt_identity()) item = dbc.get.user(get_jwt_identity())
return item_response(schema.dump(item)) return item_response(schema.dump(item))
@protect_route(allowed_roles=["*"]) @protect_route(allowed_roles=["*"])
def put(self): def put(self):
""" Posts a new user using the specified arguments. """
args = user_parser_edit.parse_args(strict=True) args = user_parser_edit.parse_args(strict=True)
item = dbc.get.user(get_jwt_identity()) item = dbc.get.user(get_jwt_identity())
item = _edit_user(item, args) item = _edit_user(item, args)
...@@ -58,11 +67,15 @@ class UsersList(Resource): ...@@ -58,11 +67,15 @@ class UsersList(Resource):
class Users(Resource): class Users(Resource):
@protect_route(allowed_roles=["*"]) @protect_route(allowed_roles=["*"])
def get(self, ID): def get(self, ID):
""" Gets the specified user. """
item = dbc.get.user(ID) item = dbc.get.user(ID)
return item_response(schema.dump(item)) return item_response(schema.dump(item))
@protect_route(allowed_roles=["Admin"]) @protect_route(allowed_roles=["Admin"])
def put(self, ID): def put(self, ID):
""" Edits the specified team using the provided arguments. """
args = user_parser_edit.parse_args(strict=True) args = user_parser_edit.parse_args(strict=True)
item = dbc.get.user(ID) item = dbc.get.user(ID)
item = _edit_user(item, args) item = _edit_user(item, args)
...@@ -73,6 +86,8 @@ class Users(Resource): ...@@ -73,6 +86,8 @@ class Users(Resource):
class UserSearch(Resource): class UserSearch(Resource):
@protect_route(allowed_roles=["*"]) @protect_route(allowed_roles=["*"])
def get(self): def get(self):
""" Finds a specific user based on the provided arguments. """
args = user_search_parser.parse_args(strict=True) args = user_search_parser.parse_args(strict=True)
items, total = dbc.search.user(**args) items, total = dbc.search.user(**args)
return list_response(list_schema.dump(items), total) return list_response(list_schema.dump(items), total)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment