2019-05-18 19:00:13 +02:00
|
|
|
from flask import request
|
|
|
|
from flask_accepts import accepts, responds
|
2020-01-22 18:05:43 +01:00
|
|
|
from flask_restx import Namespace, Resource
|
2019-05-18 19:00:13 +02:00
|
|
|
from flask.wrappers import Response
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
from .schema import FizzbazSchema
|
|
|
|
from .service import FizzbazService
|
|
|
|
from .model import Fizzbaz
|
|
|
|
from .interface import FizzbazInterface
|
|
|
|
|
2019-08-03 18:55:38 +02:00
|
|
|
api = Namespace("Fizzbaz", 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 FizzbazResource(Resource):
|
2019-08-03 18:55:38 +02:00
|
|
|
"""Fizzbaz"""
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
@responds(schema=FizzbazSchema, many=True)
|
|
|
|
def get(self) -> List[Fizzbaz]:
|
2019-08-03 18:55:38 +02:00
|
|
|
"""Get all Fizzbaz"""
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
return FizzbazService.get_all()
|
|
|
|
|
|
|
|
@accepts(schema=FizzbazSchema, api=api)
|
|
|
|
@responds(schema=FizzbazSchema)
|
|
|
|
def post(self) -> Fizzbaz:
|
2019-08-03 18:55:38 +02:00
|
|
|
"""Create a Single Fizzbaz"""
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
return FizzbazService.create(request.parsed_obj)
|
|
|
|
|
|
|
|
|
2019-08-03 18:55:38 +02:00
|
|
|
@api.route("/<int:fizzbazId>")
|
|
|
|
@api.param("fizzbazId", "Fizzbaz database ID")
|
2019-05-18 19:00:13 +02:00
|
|
|
class FizzbazIdResource(Resource):
|
|
|
|
@responds(schema=FizzbazSchema)
|
|
|
|
def get(self, fizzbazId: int) -> Fizzbaz:
|
2019-08-03 18:55:38 +02:00
|
|
|
"""Get Single Fizzbaz"""
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
return FizzbazService.get_by_id(fizzbazId)
|
|
|
|
|
|
|
|
def delete(self, fizzbazId: int) -> Response:
|
2019-08-03 18:55:38 +02:00
|
|
|
"""Delete Single Fizzbaz"""
|
2019-05-18 19:00:13 +02:00
|
|
|
from flask import jsonify
|
|
|
|
|
|
|
|
id = FizzbazService.delete_by_id(fizzbazId)
|
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=FizzbazSchema, api=api)
|
|
|
|
@responds(schema=FizzbazSchema)
|
|
|
|
def put(self, fizzbazId: int) -> Fizzbaz:
|
2019-08-03 18:55:38 +02:00
|
|
|
"""Update Single Fizzbaz"""
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
changes: FizzbazInterface = request.parsed_obj
|
|
|
|
Fizzbaz = FizzbazService.get_by_id(fizzbazId)
|
|
|
|
return FizzbazService.update(Fizzbaz, changes)
|