сделал получение всех невыданных линз
This commit is contained in:
parent
9190723abd
commit
e539a9a37b
@ -15,6 +15,11 @@ class LensesRepository:
|
|||||||
result = await self.db.execute(stmt)
|
result = await self.db.execute(stmt)
|
||||||
return result.scalars().all()
|
return result.scalars().all()
|
||||||
|
|
||||||
|
async def get_all_not_issued(self) -> Sequence[Lens]:
|
||||||
|
stmt = select(Lens).filter(Lens.issued == False)
|
||||||
|
result = await self.db.execute(stmt)
|
||||||
|
return result.scalars().all()
|
||||||
|
|
||||||
async def get_by_id(self, lens_id: int) -> Optional[Lens]:
|
async def get_by_id(self, lens_id: int) -> Optional[Lens]:
|
||||||
stmt = select(Lens).filter(Lens.id == lens_id)
|
stmt = select(Lens).filter(Lens.id == lens_id)
|
||||||
result = await self.db.execute(stmt)
|
result = await self.db.execute(stmt)
|
||||||
|
|||||||
@ -23,6 +23,20 @@ async def get_all_lenses(
|
|||||||
return await lenses_service.get_all_lenses()
|
return await lenses_service.get_all_lenses()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get(
|
||||||
|
"/lenses/not_issued/",
|
||||||
|
response_model=list[LensEntity],
|
||||||
|
summary="Get all not issued lenses",
|
||||||
|
description="Returns a list of all not issued lenses",
|
||||||
|
)
|
||||||
|
async def get_all_not_issued_lenses(
|
||||||
|
db: AsyncSession = Depends(get_db),
|
||||||
|
user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
lenses_service = LensesService(db)
|
||||||
|
return await lenses_service.get_all_not_issued_lenses()
|
||||||
|
|
||||||
|
|
||||||
@router.post(
|
@router.post(
|
||||||
"/lenses/",
|
"/lenses/",
|
||||||
response_model=LensEntity,
|
response_model=LensEntity,
|
||||||
|
|||||||
@ -55,10 +55,20 @@ class LensIssuesService:
|
|||||||
detail='The lens with this ID was not found',
|
detail='The lens with this ID was not found',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if lens.issued:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
|
detail='The lens is already issued',
|
||||||
|
)
|
||||||
|
|
||||||
lens_issue_model = self.entity_to_model(lens_issue)
|
lens_issue_model = self.entity_to_model(lens_issue)
|
||||||
|
|
||||||
await self.lens_issues_repository.create(lens_issue_model)
|
await self.lens_issues_repository.create(lens_issue_model)
|
||||||
|
|
||||||
|
lens.issued = True
|
||||||
|
|
||||||
|
await self.lenses_repository.update(lens)
|
||||||
|
|
||||||
return self.model_to_entity(lens_issue_model)
|
return self.model_to_entity(lens_issue_model)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@ -24,6 +24,14 @@ class LensesService:
|
|||||||
for lens in lenses
|
for lens in lenses
|
||||||
]
|
]
|
||||||
|
|
||||||
|
async def get_all_not_issued_lenses(self) -> list[LensEntity]:
|
||||||
|
lenses = await self.lenses_repository.get_all_not_issued()
|
||||||
|
|
||||||
|
return [
|
||||||
|
self.model_to_entity(lens)
|
||||||
|
for lens in lenses
|
||||||
|
]
|
||||||
|
|
||||||
async def create_lens(self, lens: LensEntity) -> LensEntity:
|
async def create_lens(self, lens: LensEntity) -> LensEntity:
|
||||||
lens_type = await self.lens_types_repository.get_by_id(lens.type_id)
|
lens_type = await self.lens_types_repository.get_by_id(lens.type_id)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user