исправил формат фильтрации

This commit is contained in:
Андрей Дувакин 2025-06-01 10:52:28 +05:00
parent 0a14842120
commit 6c4ecc49ac
11 changed files with 22 additions and 22 deletions

View File

@ -16,6 +16,6 @@ class AppointmentTypesRepository:
return result.scalars().all() return result.scalars().all()
async def get_by_id(self, appointment_type_id: int) -> Optional[AppointmentType]: async def get_by_id(self, appointment_type_id: int) -> Optional[AppointmentType]:
stmt = select(AppointmentType).filter(AppointmentType.id == appointment_type_id) stmt = select(AppointmentType).filter_by(id=appointment_type_id)
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().first() return result.scalars().first()

View File

@ -28,7 +28,7 @@ class AppointmentsRepository:
.options(joinedload(Appointment.type)) .options(joinedload(Appointment.type))
.options(joinedload(Appointment.patient)) .options(joinedload(Appointment.patient))
.options(joinedload(Appointment.doctor)) .options(joinedload(Appointment.doctor))
.filter(Appointment.doctor_id == doctor_id) .filter_by(doctor_id=doctor_id)
.order_by(desc(Appointment.appointment_datetime)) .order_by(desc(Appointment.appointment_datetime))
) )
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
@ -40,7 +40,7 @@ class AppointmentsRepository:
.options(joinedload(Appointment.type)) .options(joinedload(Appointment.type))
.options(joinedload(Appointment.patient)) .options(joinedload(Appointment.patient))
.options(joinedload(Appointment.doctor)) .options(joinedload(Appointment.doctor))
.filter(Appointment.patient_id == patient_id) .filter_by(patient_id=patient_id)
.order_by(desc(Appointment.appointment_datetime)) .order_by(desc(Appointment.appointment_datetime))
) )
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
@ -52,7 +52,7 @@ class AppointmentsRepository:
.options(joinedload(Appointment.type)) .options(joinedload(Appointment.type))
.options(joinedload(Appointment.patient)) .options(joinedload(Appointment.patient))
.options(joinedload(Appointment.doctor)) .options(joinedload(Appointment.doctor))
.filter(Appointment.id == appointment_id) .filter_by(id=appointment_id)
) )
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().first() return result.scalars().first()

View File

@ -23,7 +23,7 @@ class LensIssuesRepository:
return result.scalars().all() return result.scalars().all()
async def get_by_id(self, lens_issue_id: int) -> Optional[LensIssue]: async def get_by_id(self, lens_issue_id: int) -> Optional[LensIssue]:
stmt = select(LensIssue).filter(LensIssue.id == lens_issue_id) stmt = select(LensIssue).filter_by(id=lens_issue_id)
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().first() return result.scalars().first()

View File

@ -16,7 +16,7 @@ class LensTypesRepository:
return result.scalars().all() return result.scalars().all()
async def get_by_id(self, lens_type_id: int) -> Optional[LensType]: async def get_by_id(self, lens_type_id: int) -> Optional[LensType]:
stmt = select(LensType).filter(LensType.id == lens_type_id) stmt = select(LensType).filter_by(id=lens_type_id)
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().first() return result.scalars().first()
@ -32,7 +32,7 @@ class LensTypesRepository:
return lens_type return lens_type
async def delete(self, lens_type_id: int) -> Row[LensType] | RowMapping | None: async def delete(self, lens_type_id: int) -> Row[LensType] | RowMapping | None:
stmt = select(LensType).filter(LensType.id == lens_type_id) stmt = select(LensType).filter_by(id=lens_type_id)
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
lens_type = result.scalars().first() lens_type = result.scalars().first()

View File

@ -1,6 +1,6 @@
from typing import Sequence, Optional from typing import Sequence, Optional
from sqlalchemy import select from sqlalchemy import select, desc
from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.ext.asyncio import AsyncSession
from app.domain.models import Lens from app.domain.models import Lens
@ -11,17 +11,17 @@ class LensesRepository:
self.db = db self.db = db
async def get_all(self) -> Sequence[Lens]: async def get_all(self) -> Sequence[Lens]:
stmt = select(Lens) stmt = select(Lens).order_by(Lens.id)
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]: async def get_all_not_issued(self) -> Sequence[Lens]:
stmt = select(Lens).filter(Lens.issued == False) stmt = select(Lens).filter_by(issued=False).order_by(desc(Lens.id))
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().all() 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_by(id=lens_id)
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().first() return result.scalars().first()

View File

@ -16,7 +16,7 @@ class PatientsRepository:
return result.scalars().all() return result.scalars().all()
async def get_by_id(self, patient_id: int) -> Optional[Patient]: async def get_by_id(self, patient_id: int) -> Optional[Patient]:
stmt = select(Patient).filter(Patient.id == patient_id) stmt = select(Patient).filter_by(id=patient_id)
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().first() return result.scalars().first()

View File

@ -16,6 +16,6 @@ class RolesRepository:
return result.scalars().all() return result.scalars().all()
async def get_by_id(self, role_id: int) -> Optional[Role]: async def get_by_id(self, role_id: int) -> Optional[Role]:
stmt = select(Role).filter(Role.id == role_id) stmt = select(Role).filter_by(id=role_id)
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().first() return result.scalars().first()

View File

@ -28,7 +28,7 @@ class ScheduledAppointmentsRepository:
.options(joinedload(ScheduledAppointment.type)) .options(joinedload(ScheduledAppointment.type))
.options(joinedload(ScheduledAppointment.patient)) .options(joinedload(ScheduledAppointment.patient))
.options(joinedload(ScheduledAppointment.doctor)) .options(joinedload(ScheduledAppointment.doctor))
.filter(ScheduledAppointment.doctor_id == doctor_id) .filter_by(doctor_id=doctor_id)
.order_by(desc(ScheduledAppointment.scheduled_datetime)) .order_by(desc(ScheduledAppointment.scheduled_datetime))
) )
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
@ -40,7 +40,7 @@ class ScheduledAppointmentsRepository:
.options(joinedload(ScheduledAppointment.type)) .options(joinedload(ScheduledAppointment.type))
.options(joinedload(ScheduledAppointment.patient)) .options(joinedload(ScheduledAppointment.patient))
.options(joinedload(ScheduledAppointment.doctor)) .options(joinedload(ScheduledAppointment.doctor))
.filter(ScheduledAppointment.patient_id == patient_id) .filter_by(patient_id=patient_id)
.order_by(desc(ScheduledAppointment.scheduled_datetime)) .order_by(desc(ScheduledAppointment.scheduled_datetime))
) )
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
@ -52,7 +52,7 @@ class ScheduledAppointmentsRepository:
.options(joinedload(ScheduledAppointment.type)) .options(joinedload(ScheduledAppointment.type))
.options(joinedload(ScheduledAppointment.patient)) .options(joinedload(ScheduledAppointment.patient))
.options(joinedload(ScheduledAppointment.doctor)) .options(joinedload(ScheduledAppointment.doctor))
.filter(ScheduledAppointment.id == scheduled_appointment_id) .filter_by(id=scheduled_appointment_id)
) )
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().first() return result.scalars().first()

View File

@ -16,12 +16,12 @@ class SetContentRepository:
return result.scalars().all() return result.scalars().all()
async def get_by_id(self, set_content_id: int) -> Optional[SetContent]: async def get_by_id(self, set_content_id: int) -> Optional[SetContent]:
stmt = select(SetContent).filter(SetContent.id == set_content_id) stmt = select(SetContent).filter_by(id=set_content_id)
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().first() return result.scalars().first()
async def get_by_set_id(self, set_id: int) -> Sequence[SetContent]: async def get_by_set_id(self, set_id: int) -> Sequence[SetContent]:
stmt = select(SetContent).filter(SetContent.set_id == set_id) stmt = select(SetContent).filter_by(set_id=set_id)
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().all() return result.scalars().all()

View File

@ -16,7 +16,7 @@ class SetsRepository:
return result.scalars().all() return result.scalars().all()
async def get_by_id(self, set_id: int) -> Optional[Set]: async def get_by_id(self, set_id: int) -> Optional[Set]:
stmt = select(Set).filter(Set.id == set_id) stmt = select(Set).filter_by(id=set_id)
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().first() return result.scalars().first()

View File

@ -17,14 +17,14 @@ class UsersRepository:
return result.scalars().all() return result.scalars().all()
async def get_by_id(self, user_id: int) -> Optional[User]: async def get_by_id(self, user_id: int) -> Optional[User]:
stmt = select(User).filter(User.id == user_id) stmt = select(User).filter_by(id=user_id)
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
return result.scalars().first() return result.scalars().first()
async def get_by_login(self, user_login: str) -> Optional[User]: async def get_by_login(self, user_login: str) -> Optional[User]:
stmt = ( stmt = (
select(User) select(User)
.filter(User.login == user_login) .filter_by(login=user_login)
.options(joinedload(User.role)) .options(joinedload(User.role))
) )
result = await self.db.execute(stmt) result = await self.db.execute(stmt)
@ -33,7 +33,7 @@ class UsersRepository:
async def get_by_id_with_role(self, user_id: int) -> Optional[User]: async def get_by_id_with_role(self, user_id: int) -> Optional[User]:
stmt = ( stmt = (
select(User) select(User)
.filter(User.id == user_id) .filter_by(id=user_id)
.options(joinedload(User.role)) .options(joinedload(User.role))
) )
result = await self.db.execute(stmt) result = await self.db.execute(stmt)