Newer
Older
from app.apis import check_jwt, item_response, list_response
from app.core.dto import SlideDTO
from app.core.parsers import slide_parser
from app.database.models import Competition, Slide
from flask_jwt_extended import jwt_required
from flask_restx import Resource
schema = SlideDTO.schema
list_schema = SlideDTO.list_schema
def get(self, competition_id):
items = dbc.get.slide_list(competition_id)
def post(self, competition_id):
item_slide = dbc.add.slide(competition_id)
return item_response(schema.dump(item_slide))
@api.route("/<slide_id>")
@api.param("competition_id,slide_id")
def get(self, competition_id, slide_id):
item_slide = dbc.get.slide(competition_id, slide_id)
return item_response(schema.dump(item_slide))
def put(self, competition_id, slide_id):
args = slide_parser.parse_args(strict=True)
item_slide = dbc.get.slide(competition_id, slide_id)
item_slide = dbc.edit.default(item_slide, **args)
return item_response(schema.dump(item_slide))
def delete(self, competition_id, slide_id):
item_slide = dbc.get.slide(competition_id, slide_id)
@api.route("/<slide_id>/order")
@api.param("competition_id,slide_id")
class SlideOrder(Resource):
def put(self, competition_id, slide_id):
args = slide_parser.parse_args(strict=True)
order = args.get("order")
item_slide = dbc.get.slide(competition_id, slide_id)
order_count = dbc.get.slide_count(competition_id)
if order < 0:
order = 0
elif order >= order_count - 1:
order = order_count - 1
# get slide at the requested order
item_slide_id = dbc.get.slide(competition_id, order)
item_slide = dbc.edit.switch_order(item_slide, item_slide_id)
return item_response(schema.dump(item_slide))
@api.route("/<slide_id>/copy")
@api.param("competition_id,slide_id")
class SlideCopy(Resource):
def post(self, competition_id, slide_id):
item_slide = dbc.get.slide(competition_id, slide_id)
item_slide_copy = dbc.copy.slide(item_slide)
return item_response(schema.dump(item_slide_copy))