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

Commented code API

parent 5bb5576b
No related branches found
No related tags found
1 merge request!130Resolve "Comment apis"
"""
All API calls concerning competition codes.
Default route: /api/competitions/<competition_id>/codes
"""
import app.database.controller as dbc
from app.apis import item_response, list_response, protect_route
from app.core.dto import CodeDTO
......@@ -14,6 +19,8 @@ list_schema = CodeDTO.list_schema
class CodesList(Resource):
@protect_route(allowed_roles=["*"], allowed_views=["Operator"])
def get(self, competition_id):
""" Gets the all competition codes. """
items = dbc.get.code_list(competition_id)
return list_response(list_schema.dump(items), len(items))
......@@ -23,6 +30,8 @@ class CodesList(Resource):
class CodesById(Resource):
@protect_route(allowed_roles=["*"])
def put(self, competition_id, code_id):
""" Generates a new competition code. """
item = dbc.get.one(Code, code_id)
item.code = dbc.utils.generate_unique_code()
dbc.utils.commit_and_refresh(item)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment