Newer
Older
from app.apis import item_response, list_response, protect_route
from app.core import http_codes as codes
from app.core.dto import CodeDTO
from flask_restx import Resource
api = CodeDTO.api
schema = CodeDTO.schema
list_schema = CodeDTO.list_schema
@protect_route(allowed_roles=["*"])
def get(self, competition_id):
items = dbc.get.code_list(competition_id)
return list_response(list_schema.dump(items), len(items))
@api.param("competition_id, code_id")
@protect_route(allowed_roles=["*"])
def put(self, competition_id, code_id):
item = dbc.get.one(Code, code_id)
item.code = dbc.utils.generate_unique_code()
dbc.utils.commit_and_refresh(item)
return item_response(schema.dump(item))