lavkach3
1from sqlalchemy import select2from starlette.requests import Request3
4from app.basic.uom.models.uom_models import Uom5from app.basic.uom.schemas.uom_schemas import UomCreateScheme, UomUpdateScheme, UomFilter, ConvertSchema6from core.service.base import BaseService7
8
9class UomService(BaseService[Uom, UomCreateScheme, UomUpdateScheme, UomFilter]):10def __init__(self, request: Request):11super(UomService, self).__init__(request, Uom, UomCreateScheme, UomUpdateScheme)12
13async def convert(self, objs: list[ConvertSchema]):14ids = []15for o in objs:16ids.append(o.uom_id_in)17ids.append(o.uom_id_out)18query = select(self.model).filter(self.model.id.in_(ids))19result = self.session.execute(query)20result = {i.id: i for i in result}21# for obj in objs:22#23# uom_id_in_entity = await self.get(obj)24# uom_id_out_entity = await self.get(uom_id_out)25#26# await self.session.delete(entity)27# try:28# await self.session.commit()29# except IntegrityError as e:30# await self.session.rollback()31# if "duplicate key" in str(e):32# raise HTTPException(status_code=409, detail=f"Conflict Error entity {str(e)}")33# else:34# raise HTTPException(status_code=500, detail=f"ERROR: {str(e)}")35# except Exception as e:36# raise HTTPException(status_code=500, detail=f"ERROR: {str(e)}")37return True38