изменил метод получения выдач линз, добавил в ответ информацию о пациентах, докторах и линзах, сделал сортировку по дате
This commit is contained in:
parent
fe67771924
commit
321dfd5628
@ -2,6 +2,7 @@ from typing import Optional, Sequence
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
||||
from app.domain.models import LensIssue
|
||||
|
||||
@ -11,7 +12,13 @@ class LensIssuesRepository:
|
||||
self.db = db
|
||||
|
||||
async def get_all(self) -> Sequence[LensIssue]:
|
||||
stmt = select(LensIssue)
|
||||
stmt = (
|
||||
select(LensIssue)
|
||||
.options(joinedload(LensIssue.lens))
|
||||
.options(joinedload(LensIssue.patient))
|
||||
.options(joinedload(LensIssue.doctor))
|
||||
.order_by(LensIssue.issue_date)
|
||||
)
|
||||
result = await self.db.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
|
||||
@ -3,6 +3,10 @@ from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.domain.entities.lens import LensEntity
|
||||
from app.domain.entities.patient import PatientEntity
|
||||
from app.domain.entities.user import UserEntity
|
||||
|
||||
|
||||
class LensIssueEntity(BaseModel):
|
||||
id: Optional[int] = None
|
||||
@ -11,3 +15,7 @@ class LensIssueEntity(BaseModel):
|
||||
patient_id: int
|
||||
doctor_id: Optional[int] = None
|
||||
lens_id: int
|
||||
|
||||
patient: Optional[PatientEntity] = None
|
||||
doctor: Optional[UserEntity] = None
|
||||
lens: Optional[LensEntity] = None
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from starlette import status
|
||||
@ -10,6 +8,9 @@ from app.application.patients_repository import PatientsRepository
|
||||
from app.application.users_repository import UsersRepository
|
||||
from app.domain.entities.lens_issues import LensIssueEntity
|
||||
from app.domain.models import LensIssue
|
||||
from app.infrastructure.lenses_service import LensesService
|
||||
from app.infrastructure.patients_service import PatientsService
|
||||
from app.infrastructure.users_service import UsersService
|
||||
|
||||
|
||||
class LensIssuesService:
|
||||
@ -76,10 +77,21 @@ class LensIssuesService:
|
||||
|
||||
@staticmethod
|
||||
def model_to_entity(lens_issue_model: LensIssue) -> LensIssueEntity:
|
||||
return LensIssueEntity(
|
||||
lens_issue_entity = LensIssueEntity(
|
||||
id=lens_issue_model.id,
|
||||
issue_date=lens_issue_model.issue_date,
|
||||
patient_id=lens_issue_model.patient_id,
|
||||
doctor_id=lens_issue_model.doctor_id,
|
||||
lens_id=lens_issue_model.lens_id,
|
||||
)
|
||||
|
||||
if lens_issue_model.doctor is not None:
|
||||
lens_issue_entity.doctor = UsersService.model_to_entity(lens_issue_model.doctor)
|
||||
|
||||
if lens_issue_model.patient is not None:
|
||||
lens_issue_entity.patient = PatientsService.model_to_entity(lens_issue_model.patient)
|
||||
|
||||
if lens_issue_model.lens is not None:
|
||||
lens_issue_entity.lens = LensesService.model_to_entity(lens_issue_model.lens)
|
||||
|
||||
return lens_issue_entity
|
||||
|
||||
@ -74,3 +74,28 @@ class UsersService:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def entity_to_model(user: UserEntity) -> User:
|
||||
user_model = User(
|
||||
first_name=user.first_name,
|
||||
last_name=user.last_name,
|
||||
patronymic=user.patronymic,
|
||||
login=user.login,
|
||||
)
|
||||
|
||||
if user.id is not None:
|
||||
user_model.id = user.id
|
||||
|
||||
return user_model
|
||||
|
||||
@staticmethod
|
||||
def model_to_entity(user: User) -> UserEntity:
|
||||
return UserEntity(
|
||||
id=user.id,
|
||||
first_name=user.first_name,
|
||||
last_name=user.last_name,
|
||||
patronymic=user.patronymic,
|
||||
login=user.login,
|
||||
role_id=user.role_id,
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user