2019-05-18 19:00:13 +02:00
|
|
|
from flask import request
|
|
|
|
from flask_accepts import accepts, responds
|
|
|
|
from flask_restplus import Namespace, Resource
|
|
|
|
from flask.wrappers import Response
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
from .schema import FizzbarSchema
|
|
|
|
from .service import FizzbarService
|
|
|
|
from .model import Fizzbar
|
|
|
|
from .interface import FizzbarInterface
|
|
|
|
|
2019-08-03 18:55:38 +02:00
|
|
|
api = Namespace("Fizzbar", description="A modular namespace within fizz") # noqa
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
|
2019-08-03 18:55:38 +02:00
|
|
|
@api.route("/")
|
2019-05-18 19:00:13 +02:00
|
|
|
class FizzbarResource(Resource):
|
2019-08-03 18:55:38 +02:00
|
|
|
"""Fizzbars"""
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
@responds(schema=FizzbarSchema, many=True)
|
|
|
|
def get(self) -> List[Fizzbar]:
|
2019-08-03 18:55:38 +02:00
|
|
|
"""Get all Fizzbars"""
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
return FizzbarService.get_all()
|
|
|
|
|
|
|
|
@accepts(schema=FizzbarSchema, api=api)
|
|
|
|
@responds(schema=FizzbarSchema)
|
|
|
|
def post(self) -> Fizzbar:
|
2019-08-03 18:55:38 +02:00
|
|
|
"""Create a Single Fizzbar"""
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
return FizzbarService.create(request.parsed_obj)
|
|
|
|
|
|
|
|
|
2019-08-03 18:55:38 +02:00
|
|
|
@api.route("/<int:fizzbarId>")
|
|
|
|
@api.param("fizzbarId", "Fizzbar database ID")
|
2019-05-18 19:00:13 +02:00
|
|
|
class FizzbarIdResource(Resource):
|
|
|
|
@responds(schema=FizzbarSchema)
|
|
|
|
def get(self, fizzbarId: int) -> Fizzbar:
|
2019-08-03 18:55:38 +02:00
|
|
|
"""Get Single Fizzbar"""
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
return FizzbarService.get_by_id(fizzbarId)
|
|
|
|
|
|
|
|
def delete(self, fizzbarId: int) -> Response:
|
2019-08-03 18:55:38 +02:00
|
|
|
"""Delete Single Fizzbar"""
|
2019-05-18 19:00:13 +02:00
|
|
|
from flask import jsonify
|
2019-08-03 18:55:38 +02:00
|
|
|
|
|
|
|
print("fizzbarId = ", fizzbarId)
|
2019-05-18 19:00:13 +02:00
|
|
|
id = FizzbarService.delete_by_id(fizzbarId)
|
2019-08-03 18:55:38 +02:00
|
|
|
return jsonify(dict(status="Success", id=id))
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
@accepts(schema=FizzbarSchema, api=api)
|
|
|
|
@responds(schema=FizzbarSchema)
|
|
|
|
def put(self, fizzbarId: int) -> Fizzbar:
|
2019-08-03 18:55:38 +02:00
|
|
|
"""Update Single Fizzbar"""
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
changes: FizzbarInterface = request.parsed_obj
|
|
|
|
Fizzbar = FizzbarService.get_by_id(fizzbarId)
|
|
|
|
return FizzbarService.update(Fizzbar, changes)
|