поправил удаление и изменение содержимого набора
This commit is contained in:
parent
033776deb6
commit
61a315d047
@ -51,6 +51,8 @@ class SetContentRepository:
|
||||
return set_content
|
||||
|
||||
async def delete_list_sets(self, sets_content: list[SetContent]) -> list[SetContent]:
|
||||
await self.db.delete(sets_content)
|
||||
for set_content in sets_content:
|
||||
await self.db.delete(set_content)
|
||||
|
||||
await self.db.commit()
|
||||
return sets_content
|
||||
|
||||
@ -16,4 +16,4 @@ class SetContentEntity(BaseModel):
|
||||
count: int
|
||||
|
||||
type_id: int
|
||||
set_id: int
|
||||
set_id: Optional[int] = None
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey, Enum
|
||||
from sqlalchemy import Column, Integer, ForeignKey, Enum, Float
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models.base import BaseModel
|
||||
@ -8,13 +8,13 @@ from app.domain.models.lens import SideEnum
|
||||
class SetContent(BaseModel):
|
||||
__tablename__ = 'set_contents'
|
||||
|
||||
tor = Column(Integer, nullable=False)
|
||||
trial = Column(Integer, nullable=False)
|
||||
esa = Column(Integer, nullable=False)
|
||||
fvc = Column(Integer, nullable=False)
|
||||
preset_refraction = Column(Integer, nullable=False)
|
||||
diameter = Column(Integer, nullable=False)
|
||||
periphery_toricity = Column(Integer, nullable=False)
|
||||
tor = Column(Float, nullable=False)
|
||||
trial = Column(Float, nullable=False)
|
||||
esa = Column(Float, nullable=False)
|
||||
fvc = Column(Float, nullable=False)
|
||||
preset_refraction = Column(Float, nullable=False)
|
||||
diameter = Column(Float, nullable=False)
|
||||
periphery_toricity = Column(Float, nullable=False)
|
||||
side = Column(Enum(SideEnum), nullable=False)
|
||||
count = Column(Integer, nullable=False)
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ class SetContentService:
|
||||
)
|
||||
|
||||
sets_content_models.append(
|
||||
self.entity_to_model(content, set_id)
|
||||
self.entity_to_model(content, set_id, skip_id=True)
|
||||
)
|
||||
|
||||
await self.set_content_repository.create_list(sets_content_models)
|
||||
@ -124,7 +124,7 @@ class SetContentService:
|
||||
result = []
|
||||
|
||||
for content in sets_content:
|
||||
model_content = self.entity_to_model(content)
|
||||
model_content = self.entity_to_model(content, set_id, skip_id=True)
|
||||
model_content = await self.set_content_repository.create(model_content)
|
||||
result.append(model_content)
|
||||
|
||||
@ -184,7 +184,7 @@ class SetContentService:
|
||||
return self.model_to_entity(result)
|
||||
|
||||
@staticmethod
|
||||
def entity_to_model(set_content: SetContentEntity, set_id=None) -> SetContent:
|
||||
def entity_to_model(set_content: SetContentEntity, set_id=None, skip_id=False) -> SetContent:
|
||||
|
||||
if set_id is None:
|
||||
set_id = set_content.set_id
|
||||
@ -211,7 +211,7 @@ class SetContentService:
|
||||
set_id=set_id,
|
||||
)
|
||||
|
||||
if set_content.id is not None:
|
||||
if set_content.id is not None and not skip_id:
|
||||
set_content_model.id = set_content.id
|
||||
|
||||
return set_content_model
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user