сдела энд-поинты для запланированных приемов, а также вынес префиксы роутеров в main файл
This commit is contained in:
parent
51dfe2f508
commit
3fc30f8e59
@ -10,7 +10,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/appointment_types/",
|
||||
"/",
|
||||
response_model=list[AppointmentTypeEntity],
|
||||
summary="Get all appointment types",
|
||||
description="Returns a list of all appointment types",
|
||||
|
||||
@ -10,7 +10,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/appointments/",
|
||||
"/",
|
||||
response_model=list[AppointmentEntity],
|
||||
summary="Get all appointments",
|
||||
description="Returns a list of all appointments",
|
||||
@ -24,7 +24,7 @@ async def get_all_appointments(
|
||||
|
||||
|
||||
@router.get(
|
||||
"/appointments/doctor/{doctor_id}/",
|
||||
"/doctor/{doctor_id}/",
|
||||
response_model=AppointmentEntity,
|
||||
summary="Get all appointments for doctor",
|
||||
description="Returns a list of appointments for doctor",
|
||||
@ -39,7 +39,7 @@ async def get_all_appointments_by_doctor_id(
|
||||
|
||||
|
||||
@router.get(
|
||||
"/appointments/patient/{patient_id}/",
|
||||
"/patient/{patient_id}/",
|
||||
response_model=AppointmentEntity,
|
||||
summary="Get all appointments for patient",
|
||||
description="Returns a list of appointments for patient",
|
||||
@ -54,7 +54,7 @@ async def get_all_appointments_by_patient_id(
|
||||
|
||||
|
||||
@router.post(
|
||||
"/appointments/",
|
||||
"/",
|
||||
response_model=AppointmentEntity,
|
||||
summary="Create appointment",
|
||||
description="Creates a new appointment",
|
||||
@ -69,7 +69,7 @@ async def create_appointment(
|
||||
|
||||
|
||||
@router.put(
|
||||
"/appointments/{appointment_id}/",
|
||||
"/{appointment_id}/",
|
||||
response_model=AppointmentEntity,
|
||||
summary="Update appointment",
|
||||
description="Updates an existing appointment",
|
||||
|
||||
@ -10,7 +10,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/lens_issues/",
|
||||
"/",
|
||||
response_model=list[LensIssueEntity],
|
||||
summary="Get all lens issues",
|
||||
description="Returns a list of all lens issues",
|
||||
@ -24,7 +24,7 @@ async def get_all_lens_issues(
|
||||
|
||||
|
||||
@router.post(
|
||||
"/lens_issues/",
|
||||
"/",
|
||||
response_model=LensIssueEntity,
|
||||
summary="Create lens issue",
|
||||
description="Creates a new lens issue",
|
||||
|
||||
@ -10,7 +10,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/lens_types/",
|
||||
"/",
|
||||
response_model=list[LensTypeEntity],
|
||||
summary="Get all lens types",
|
||||
description="Returns a list of all lens types",
|
||||
|
||||
@ -10,7 +10,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/lenses/",
|
||||
"/",
|
||||
response_model=list[LensEntity],
|
||||
summary="Get all lenses",
|
||||
description="Returns a list of all lenses",
|
||||
@ -24,7 +24,7 @@ async def get_all_lenses(
|
||||
|
||||
|
||||
@router.get(
|
||||
"/lenses/not_issued/",
|
||||
"/not_issued/",
|
||||
response_model=list[LensEntity],
|
||||
summary="Get all not issued lenses",
|
||||
description="Returns a list of all not issued lenses",
|
||||
@ -38,7 +38,7 @@ async def get_all_not_issued_lenses(
|
||||
|
||||
|
||||
@router.post(
|
||||
"/lenses/",
|
||||
"/",
|
||||
response_model=LensEntity,
|
||||
summary="Create lens",
|
||||
description="Creates a new lens",
|
||||
@ -53,7 +53,7 @@ async def create_lens(
|
||||
|
||||
|
||||
@router.put(
|
||||
"/lenses/{lens_id}/",
|
||||
"/{lens_id}/",
|
||||
response_model=LensEntity,
|
||||
summary="Update lens",
|
||||
description="Updates an existing lens",
|
||||
@ -69,7 +69,7 @@ async def update_lens(
|
||||
|
||||
|
||||
@router.delete(
|
||||
"/lenses/{lens_id}/",
|
||||
"/{lens_id}/",
|
||||
response_model=LensEntity,
|
||||
summary="Delete lens",
|
||||
description="Deletes an existing lens",
|
||||
|
||||
@ -10,7 +10,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/patients/",
|
||||
"/",
|
||||
response_model=list[PatientEntity],
|
||||
summary="Get all patients",
|
||||
description="Returns a list of all patients",
|
||||
@ -24,7 +24,7 @@ async def get_all_patients(
|
||||
|
||||
|
||||
@router.post(
|
||||
"/patients/",
|
||||
"/",
|
||||
response_model=PatientEntity,
|
||||
summary="Create a new patient",
|
||||
description="Creates a new patient",
|
||||
@ -39,7 +39,7 @@ async def create_patient(
|
||||
|
||||
|
||||
@router.put(
|
||||
"/patients/{patient_id}/",
|
||||
"/{patient_id}/",
|
||||
response_model=PatientEntity,
|
||||
summary="Update a patient",
|
||||
description="Updates a patient",
|
||||
@ -55,7 +55,7 @@ async def update_patient(
|
||||
|
||||
|
||||
@router.delete(
|
||||
"/patients/{patient_id}/",
|
||||
"/{patient_id}/",
|
||||
response_model=PatientEntity,
|
||||
summary="Delete a patient",
|
||||
description="Deletes a patient",
|
||||
|
||||
@ -9,7 +9,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.post(
|
||||
"/register/",
|
||||
"/",
|
||||
response_model=dict,
|
||||
summary="User Registration",
|
||||
description="Performs user registration in the system",
|
||||
|
||||
84
api/app/controllers/scheduled_appointments_router.py
Normal file
84
api/app/controllers/scheduled_appointments_router.py
Normal file
@ -0,0 +1,84 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.database.session import get_db
|
||||
from app.domain.entities.scheduled_appointment import ScheduledAppointmentEntity
|
||||
from app.infrastructure.dependencies import get_current_user
|
||||
from app.infrastructure.scheduled_appointments_service import ScheduledAppointmentsService
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/",
|
||||
response_model=list[ScheduledAppointmentEntity],
|
||||
summary="Get all scheduled appointments",
|
||||
description="Returns a list of all scheduled appointments",
|
||||
)
|
||||
async def get_all_scheduled_appointments(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user=Depends(get_current_user),
|
||||
):
|
||||
scheduled_appointments_service = ScheduledAppointmentsService(db)
|
||||
return await scheduled_appointments_service.get_all_scheduled_appointments()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/doctor/{doctor_id}/",
|
||||
response_model=ScheduledAppointmentEntity,
|
||||
summary="Get all scheduled appointments for doctor",
|
||||
description="Returns a list of scheduled appointments for doctor",
|
||||
)
|
||||
async def get_all_scheduled_appointments_by_doctor_id(
|
||||
doctor_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user=Depends(get_current_user),
|
||||
):
|
||||
appointments_service = ScheduledAppointmentsService(db)
|
||||
return await appointments_service.get_scheduled_appointments_by_doctor_id(doctor_id)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/patient/{patient_id}/",
|
||||
response_model=ScheduledAppointmentEntity,
|
||||
summary="Get all scheduled appointments for patient",
|
||||
description="Returns a list of scheduled appointments for patient",
|
||||
)
|
||||
async def get_all_appointments_by_patient_id(
|
||||
patient_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user=Depends(get_current_user),
|
||||
):
|
||||
appointments_service = ScheduledAppointmentsService(db)
|
||||
return await appointments_service.get_scheduled_appointments_by_patient_id(patient_id)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/",
|
||||
response_model=ScheduledAppointmentEntity,
|
||||
summary="Create appointment",
|
||||
description="Creates a new appointment",
|
||||
)
|
||||
async def create_appointment(
|
||||
appointment: ScheduledAppointmentEntity,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user=Depends(get_current_user),
|
||||
):
|
||||
appointment_service = ScheduledAppointmentsService(db)
|
||||
return await appointment_service.create_scheduled_appointment(appointment)
|
||||
|
||||
|
||||
@router.put(
|
||||
"/{appointment_id}/",
|
||||
response_model=ScheduledAppointmentEntity,
|
||||
summary="Update appointment",
|
||||
description="Updates an existing appointment",
|
||||
)
|
||||
async def update_appointment(
|
||||
appointment_id: int,
|
||||
appointment: ScheduledAppointmentEntity,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user=Depends(get_current_user),
|
||||
):
|
||||
appointment_service = ScheduledAppointmentsService(db)
|
||||
return await appointment_service.update_scheduled_appointment(appointment_id, appointment)
|
||||
@ -10,7 +10,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
'/set_content/{set_id}/',
|
||||
'/{set_id}/',
|
||||
response_model=list[SetContentEntity],
|
||||
summary='Get all set content by set ID',
|
||||
description='Returns a list of set content by set ID',
|
||||
@ -25,7 +25,7 @@ async def get_set_content_by_set_id(
|
||||
|
||||
|
||||
@router.post(
|
||||
'/set_content/{set_id}/',
|
||||
'/{set_id}/',
|
||||
response_model=list[SetContentEntity],
|
||||
summary='Create a new set content by set_id',
|
||||
description='Create a new set content by set_id',
|
||||
@ -41,7 +41,7 @@ async def create_set_content(
|
||||
|
||||
|
||||
@router.put(
|
||||
'/set_content/{set_id}/',
|
||||
'/{set_id}/',
|
||||
response_model=list[SetContentEntity],
|
||||
summary='Update a set content by set_id',
|
||||
description='Update a set content by set_id',
|
||||
|
||||
@ -11,7 +11,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.get(
|
||||
'/sets/',
|
||||
'/',
|
||||
response_model=list[SetEntity],
|
||||
summary='Get all sets',
|
||||
description='Returns a list of all sets',
|
||||
@ -25,7 +25,7 @@ async def get_all_sets(
|
||||
|
||||
|
||||
@router.post(
|
||||
'/sets/',
|
||||
'/',
|
||||
response_model=SetEntity,
|
||||
summary='Create a new set',
|
||||
description='Create a new set',
|
||||
@ -40,7 +40,7 @@ async def create_set(
|
||||
|
||||
|
||||
@router.put(
|
||||
'/sets/{set_id}/',
|
||||
'/{set_id}/',
|
||||
response_model=SetEntity,
|
||||
summary='Update a set',
|
||||
description='Update a set,'
|
||||
@ -56,7 +56,7 @@ async def update_set(
|
||||
|
||||
|
||||
@router.post(
|
||||
'/sets/append_lenses/{set_id}/',
|
||||
'/append_lenses/{set_id}/',
|
||||
response_model=list[LensEntity],
|
||||
summary='Append content from set to lenses',
|
||||
description='Get all content from set, converting to lens and appending to database',
|
||||
@ -71,7 +71,7 @@ async def append_lenses_set(
|
||||
|
||||
|
||||
@router.delete(
|
||||
'/sets/{set_id}/',
|
||||
'/{set_id}/',
|
||||
response_model=SetEntity,
|
||||
summary='Delete set',
|
||||
description='Delete an existing set',
|
||||
|
||||
@ -63,7 +63,81 @@ class ScheduledAppointmentsService:
|
||||
for scheduled_appointment in scheduled_appointments
|
||||
]
|
||||
|
||||
async def create_scheduled_appointment(self, scheduled_appointment: ScheduledAppointmentEntity) -> Optional[
|
||||
ScheduledAppointmentEntity
|
||||
]:
|
||||
patient = await self.patients_repository.get_by_id(scheduled_appointment.patient_id)
|
||||
|
||||
if not patient:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail='The patient with this ID was not found',
|
||||
)
|
||||
|
||||
doctor = await self.users_repository.get_by_id(scheduled_appointment.doctor_id)
|
||||
|
||||
if not doctor:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail='The doctor/user with this ID was not found',
|
||||
)
|
||||
|
||||
appointment_type = await self.appointment_types_repository.get_by_id(scheduled_appointment.type_id)
|
||||
|
||||
if not appointment_type:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail='The appointment type with this ID was not found',
|
||||
)
|
||||
|
||||
scheduled_appointment_model = self.entity_to_model(scheduled_appointment)
|
||||
|
||||
await self.scheduled_appointment_repository.create(scheduled_appointment_model)
|
||||
|
||||
return self.model_to_entity(scheduled_appointment_model)
|
||||
|
||||
async def update_scheduled_appointment(
|
||||
self,
|
||||
scheduled_appointment_id: int,
|
||||
scheduled_appointment: ScheduledAppointmentEntity
|
||||
) -> Optional[ScheduledAppointmentEntity]:
|
||||
scheduled_appointment_model = await self.scheduled_appointment_repository.get_by_id(scheduled_appointment_id)
|
||||
|
||||
if not scheduled_appointment_model:
|
||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Scheduled appointment not found")
|
||||
|
||||
patient = await self.patients_repository.get_by_id(scheduled_appointment.patient_id)
|
||||
|
||||
if not patient:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail='The patient with this ID was not found',
|
||||
)
|
||||
|
||||
doctor = await self.users_repository.get_by_id(scheduled_appointment.doctor_id)
|
||||
|
||||
if not doctor:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail='The doctor/user with this ID was not found',
|
||||
)
|
||||
|
||||
appointment_type = await self.appointment_types_repository.get_by_id(scheduled_appointment.type_id)
|
||||
|
||||
if not appointment_type:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail='The appointment type with this ID was not found',
|
||||
)
|
||||
|
||||
scheduled_appointment_model.scheduled_datetime = scheduled_appointment.scheduled_datetime
|
||||
scheduled_appointment_model.patient_id = scheduled_appointment.patient_id
|
||||
scheduled_appointment_model.doctor_id = scheduled_appointment.doctor_id
|
||||
scheduled_appointment_model.type_id = scheduled_appointment.type_id
|
||||
|
||||
await self.scheduled_appointment_repository.update(scheduled_appointment_model)
|
||||
|
||||
return self.model_to_entity(scheduled_appointment_model)
|
||||
|
||||
@staticmethod
|
||||
def entity_to_model(scheduled_appointment: ScheduledAppointmentEntity) -> ScheduledAppointment:
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from fastapi import FastAPI
|
||||
from starlette.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.controllers.appointment_types_router import router as appointment_types_router
|
||||
from app.controllers.appointment_types_router import router as appointments_types_router
|
||||
from app.controllers.appointments_router import router as appointment_router
|
||||
from app.controllers.auth_router import router as auth_router
|
||||
from app.controllers.lens_issues_router import router as lens_issues_router
|
||||
@ -9,6 +9,7 @@ from app.controllers.lens_types_router import router as lens_types_router
|
||||
from app.controllers.lenses_router import router as lenses_router
|
||||
from app.controllers.patients_router import router as patients_router
|
||||
from app.controllers.register_routes import router as register_router
|
||||
from app.controllers.scheduled_appointments_router import router as scheduled_appointments_router
|
||||
from app.controllers.set_content_router import router as set_content_router
|
||||
from app.controllers.sets_router import router as sets_router
|
||||
from app.settings import settings
|
||||
@ -25,16 +26,17 @@ def start_app():
|
||||
allow_headers=['*'],
|
||||
)
|
||||
|
||||
api_app.include_router(appointments_types_router, prefix=f'{settings.APP_PREFIX}/appointment_types', tags=['appointment_types'])
|
||||
api_app.include_router(appointment_router, prefix=f'{settings.APP_PREFIX}/appointments', tags=['appointments'])
|
||||
api_app.include_router(auth_router, prefix=settings.APP_PREFIX, tags=['auth'])
|
||||
api_app.include_router(register_router, prefix=settings.APP_PREFIX, tags=['register'])
|
||||
api_app.include_router(patients_router, prefix=settings.APP_PREFIX, tags=['patients'])
|
||||
api_app.include_router(lenses_router, prefix=settings.APP_PREFIX, tags=['lenses'])
|
||||
api_app.include_router(lens_types_router, prefix=settings.APP_PREFIX, tags=['lens_types'])
|
||||
api_app.include_router(sets_router, prefix=settings.APP_PREFIX, tags=['sets'])
|
||||
api_app.include_router(set_content_router, prefix=settings.APP_PREFIX, tags=['set_content'])
|
||||
api_app.include_router(lens_issues_router, prefix=settings.APP_PREFIX, tags=['lens_issue'])
|
||||
api_app.include_router(appointment_types_router, prefix=settings.APP_PREFIX, tags=['appointment_types'])
|
||||
api_app.include_router(appointment_router, prefix=settings.APP_PREFIX, tags=['appointments'])
|
||||
api_app.include_router(lens_issues_router, prefix=f'{settings.APP_PREFIX}/lens_issue', tags=['lens_issue'])
|
||||
api_app.include_router(lens_types_router, prefix=f'{settings.APP_PREFIX}/lens_types', tags=['lens_types'])
|
||||
api_app.include_router(lenses_router, prefix=f'{settings.APP_PREFIX}/lenses', tags=['lenses'])
|
||||
api_app.include_router(patients_router, prefix=f'{settings.APP_PREFIX}/patients', tags=['patients'])
|
||||
api_app.include_router(register_router, prefix=f'{settings.APP_PREFIX}/register', tags=['register'])
|
||||
api_app.include_router(scheduled_appointments_router, prefix=f'{settings.APP_PREFIX}/scheduled_appointments_router', tags=['scheduled_appointments_router'])
|
||||
api_app.include_router(set_content_router, prefix=f'{settings.APP_PREFIX}/set_content', tags=['set_content'])
|
||||
api_app.include_router(sets_router, prefix=f'{settings.APP_PREFIX}/sets', tags=['sets'])
|
||||
|
||||
return api_app
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user