CICD/app/other_api/doodad/service.py

39 lines
1.0 KiB
Python
Raw Normal View History

2019-05-18 19:47:47 +02:00
from app import db
from typing import List
from .model import Doodad
from .interface import DoodadInterface
2019-08-03 18:55:38 +02:00
class DoodadService:
2019-05-18 19:47:47 +02:00
@staticmethod
def get_all() -> List[Doodad]:
return Doodad.query.all()
@staticmethod
def get_by_id(doodad_id: int) -> Doodad:
return Doodad.query.get(doodad_id)
@staticmethod
def update(doodad: Doodad, Doodad_change_updates: DoodadInterface) -> Doodad:
doodad.update(Doodad_change_updates)
db.session.commit()
return doodad
@staticmethod
def delete_by_id(doodad_id: int) -> List[int]:
doodad = Doodad.query.filter(Doodad.doodad_id == doodad_id).first()
if not doodad:
return []
db.session.delete(doodad)
db.session.commit()
return [doodad_id]
@staticmethod
def create(new_attrs: DoodadInterface) -> Doodad:
2019-08-03 18:55:38 +02:00
new_doodad = Doodad(name=new_attrs["name"], purpose=new_attrs["purpose"])
2019-05-18 19:47:47 +02:00
db.session.add(new_doodad)
db.session.commit()
return new_doodad