transfer_tdms_tcs/backend/backend_transfer_tdms_tcs/app/crud.py
2026-02-11 20:49:50 +03:00

75 lines
No EOL
2.3 KiB
Python

from sqlalchemy.orm import Session
from . import models, schemas
from typing import Optional, List
import uuid
def create_unloading(db: Session, unloading: schemas.UnloadingCreate):
db_unloading = models.Unloading(
guid=unloading.guid or str(uuid.uuid4()).upper(),
name=unloading.name,
unloading_time_seconds=unloading.unloading_time_seconds,
warnings=unloading.warnings,
row_count=unloading.row_count,
file_count=unloading.file_count,
computer_name=unloading.computer_name
)
db.add(db_unloading)
db.commit()
db.refresh(db_unloading)
return db_unloading
def get_unloadings(db: Session, skip: int = 0, limit: int = 100):
return db.query(models.Unloading).offset(skip).limit(limit).all()
def get_unloading(db: Session, guid: str):
return db.query(models.Unloading).filter(models.Unloading.guid == guid).first()
def get_products(db: Session, skip: int = 0, limit: int = 100):
return db.query(models.Product).offset(skip).limit(limit).all()
def get_product(db: Session, guid: str):
return db.query(models.Product).filter(models.Product.guid == guid).first()
def add_unload_check(db: Session, product_guid: str, stage: schemas.UnloadCheckCreate):
db_stage = models.UnloadCheck(
product_guid=product_guid,
fio=stage.fio,
is_completed=stage.is_completed
)
db.add(db_stage)
db.commit()
db.refresh(db_stage)
return db_stage
def add_test_load(db: Session, product_guid: str, stage: schemas.TestLoadCreate):
db_stage = models.TestLoad(
product_guid=product_guid,
fio=stage.fio,
is_completed=stage.is_completed
)
db.add(db_stage)
db.commit()
db.refresh(db_stage)
return db_stage
def add_test_check(db: Session, product_guid: str, stage: schemas.TestCheckCreate):
db_stage = models.TestCheck(
product_guid=product_guid,
fio=stage.fio,
is_completed=stage.is_completed
)
db.add(db_stage)
db.commit()
db.refresh(db_stage)
return db_stage
def add_prod_transfer(db: Session, product_guid: str, stage: schemas.ProdTransferCreate):
db_stage = models.ProdTransfer(
product_guid=product_guid,
fio=stage.fio,
is_completed=stage.is_completed
)
db.add(db_stage)
db.commit()
db.refresh(db_stage)
return db_stage