2019-05-18 19:00:13 +02:00
|
|
|
from app import db
|
|
|
|
from typing import List
|
|
|
|
from .model import Fizzbar
|
|
|
|
from .interface import FizzbarInterface
|
|
|
|
|
|
|
|
|
2019-08-03 18:55:38 +02:00
|
|
|
class FizzbarService:
|
2019-05-18 19:00:13 +02:00
|
|
|
@staticmethod
|
|
|
|
def get_all() -> List[Fizzbar]:
|
|
|
|
return Fizzbar.query.all()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_by_id(fizzbar_id: int) -> Fizzbar:
|
|
|
|
return Fizzbar.query.get(fizzbar_id)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def update(fizzbar: Fizzbar, Fizzbar_change_updates: FizzbarInterface) -> Fizzbar:
|
|
|
|
fizzbar.update(Fizzbar_change_updates)
|
|
|
|
db.session.commit()
|
|
|
|
return fizzbar
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def delete_by_id(fizzbar_id: int) -> List[int]:
|
|
|
|
fizzbar = Fizzbar.query.filter(Fizzbar.fizzbar_id == fizzbar_id).first()
|
|
|
|
if not fizzbar:
|
|
|
|
return []
|
|
|
|
db.session.delete(fizzbar)
|
|
|
|
db.session.commit()
|
|
|
|
return [fizzbar_id]
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create(new_attrs: FizzbarInterface) -> Fizzbar:
|
2019-08-03 18:55:38 +02:00
|
|
|
new_fizzbar = Fizzbar(name=new_attrs["name"], purpose=new_attrs["purpose"])
|
2019-05-18 19:00:13 +02:00
|
|
|
|
|
|
|
db.session.add(new_fizzbar)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
return new_fizzbar
|