CICD/app/other_api/whatsit/service.py

39 lines
1.1 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 Whatsit
from .interface import WhatsitInterface
2019-08-03 18:55:38 +02:00
class WhatsitService:
2019-05-18 19:47:47 +02:00
@staticmethod
def get_all() -> List[Whatsit]:
return Whatsit.query.all()
@staticmethod
def get_by_id(whatsit_id: int) -> Whatsit:
return Whatsit.query.get(whatsit_id)
@staticmethod
def update(whatsit: Whatsit, Whatsit_change_updates: WhatsitInterface) -> Whatsit:
whatsit.update(Whatsit_change_updates)
db.session.commit()
return whatsit
@staticmethod
def delete_by_id(whatsit_id: int) -> List[int]:
whatsit = Whatsit.query.filter(Whatsit.whatsit_id == whatsit_id).first()
if not whatsit:
return []
db.session.delete(whatsit)
db.session.commit()
return [whatsit_id]
@staticmethod
def create(new_attrs: WhatsitInterface) -> Whatsit:
2019-08-03 18:55:38 +02:00
new_whatsit = Whatsit(name=new_attrs["name"], purpose=new_attrs["purpose"])
2019-05-18 19:47:47 +02:00
db.session.add(new_whatsit)
db.session.commit()
return new_whatsit