Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import uuid
from sqlalchemy.orm import Session
from app.api.v1.endpoints.dough.schemas import DoughCreateSchema
from app.database.models import Dough
def create_dough(schema: DoughCreateSchema, db: Session):
entity = Dough(**schema.dict())
db.add(entity)
db.commit()
return entity
def get_dough_by_id(dough_id: uuid.UUID, db: Session):
entity = db.query(Dough).filter(Dough.id == dough_id).first()
return entity
def get_dough_by_name(dough_name: str, db: Session):
entity = db.query(Dough).filter(Dough.name == dough_name).first()
return entity
def get_all_doughs(db: Session):
return db.query(Dough).all()
def update_dough(dough: Dough, changed_dough: DoughCreateSchema, db: Session):
for key, value in changed_dough.dict().items():
setattr(dough, key, value)
db.commit()
db.refresh(dough)
return dough
def delete_dough_by_id(dough_id: uuid.UUID, db: Session):
entity = get_dough_by_id(dough_id, db)
if entity:
db.delete(entity)
db.commit()