From d0d5bc279898b3a91bcea05a9207b628f105eb7e Mon Sep 17 00:00:00 2001 From: andrei Date: Tue, 3 Jun 2025 10:51:25 +0500 Subject: [PATCH] =?UTF-8?q?refactor:=20=D0=97=D0=B0=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BE=D0=BA=20=D0=BD=D0=B0=20=D1=80=D1=83=D1=81?= =?UTF-8?q?=D1=81=D0=BA=D0=B8=D0=B9=20=D1=8F=D0=B7=D1=8B=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/domain/entities/register.py | 1 + .../infrastructure/appointments_service.py | 18 +++++----- api/app/infrastructure/auth_service.py | 2 +- api/app/infrastructure/lens_issues_service.py | 8 ++--- api/app/infrastructure/lenses_service.py | 10 +++--- api/app/infrastructure/patients_service.py | 4 +-- .../scheduled_appointments_service.py | 24 ++++++------- api/app/infrastructure/set_content_service.py | 24 ++++++------- api/app/infrastructure/sets_service.py | 6 ++-- api/app/infrastructure/users_service.py | 34 +++++++++++-------- 10 files changed, 69 insertions(+), 62 deletions(-) diff --git a/api/app/domain/entities/register.py b/api/app/domain/entities/register.py index d982841..71aad61 100644 --- a/api/app/domain/entities/register.py +++ b/api/app/domain/entities/register.py @@ -10,3 +10,4 @@ class RegisterEntity(BaseModel): role_id: int login: str password: str + confirm_password: str diff --git a/api/app/infrastructure/appointments_service.py b/api/app/infrastructure/appointments_service.py index 8761014..8006af6 100644 --- a/api/app/infrastructure/appointments_service.py +++ b/api/app/infrastructure/appointments_service.py @@ -36,7 +36,7 @@ class AppointmentsService: if not doctor: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The doctor with this ID was not found', + detail='Доктор с таким ID не найден', ) appointments = await self.appointments_repository.get_by_doctor_id(doctor_id) @@ -52,7 +52,7 @@ class AppointmentsService: if not patient: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The patient with this ID was not found', + detail='Пациент с таким ID не найден', ) appointments = await self.appointments_repository.get_by_patient_id(patient_id) @@ -68,7 +68,7 @@ class AppointmentsService: if not patient: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The patient with this ID was not found', + detail='Пациент с таким ID не найден', ) doctor = await self.users_repository.get_by_id(doctor_id) @@ -76,7 +76,7 @@ class AppointmentsService: if not doctor: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The doctor/user with this ID was not found', + detail='Доктор/пользователь с таким ID не найден', ) appointment.doctor_id = doctor_id @@ -86,7 +86,7 @@ class AppointmentsService: if not appointment_type: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The appointment type with this ID was not found', + detail='Тип приема с таким ID не найден', ) appointment_model = self.entity_to_model(appointment) @@ -101,14 +101,14 @@ class AppointmentsService: appointment_model = await self.appointments_repository.get_by_id(appointment_id) if not appointment_model: - raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Appointment not found") + raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Прием не найден") patient = await self.patients_repository.get_by_id(appointment.patient_id) if not patient: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The patient with this ID was not found', + detail='Пациент с таким ID не найден', ) doctor = await self.users_repository.get_by_id(appointment.doctor_id) @@ -116,7 +116,7 @@ class AppointmentsService: if not doctor: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The doctor/user with this ID was not found', + detail='Доктор/пользователь с таким ID не найден', ) appointment_type = await self.appointment_types_repository.get_by_id(appointment.type_id) @@ -124,7 +124,7 @@ class AppointmentsService: if not appointment_type: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The appointment type with this ID was not found', + detail='Тип приема с таким ID не найден', ) appointment_model.results = appointment.results diff --git a/api/app/infrastructure/auth_service.py b/api/app/infrastructure/auth_service.py index d43afac..dff7dd8 100644 --- a/api/app/infrastructure/auth_service.py +++ b/api/app/infrastructure/auth_service.py @@ -23,7 +23,7 @@ class AuthService: "user_id": user.id } - raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Invalid login or password") + raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Неправильный логин или пароль") @staticmethod def create_access_token(data: dict) -> str: diff --git a/api/app/infrastructure/lens_issues_service.py b/api/app/infrastructure/lens_issues_service.py index f690298..9a84a55 100644 --- a/api/app/infrastructure/lens_issues_service.py +++ b/api/app/infrastructure/lens_issues_service.py @@ -36,7 +36,7 @@ class LensIssuesService: if not patient: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The patient with this ID was not found', + detail='Пациент с таким ID не найден', ) user = await self.users_repository.get_by_id(user_id) @@ -44,7 +44,7 @@ class LensIssuesService: if not user: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The user with this ID was not found', + detail='Пользователь с таким ID не найден', ) lens_issue.doctor_id = user_id @@ -54,13 +54,13 @@ class LensIssuesService: if not lens: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The lens with this ID was not found', + detail='Линза с таким ID не найдена', ) if lens.issued: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The lens is already issued', + detail='Линза уже выдана', ) lens_issue_model = self.entity_to_model(lens_issue) diff --git a/api/app/infrastructure/lenses_service.py b/api/app/infrastructure/lenses_service.py index 9a16369..af55642 100644 --- a/api/app/infrastructure/lenses_service.py +++ b/api/app/infrastructure/lenses_service.py @@ -38,7 +38,7 @@ class LensesService: if not lens_type: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The lens type with this ID was not found', + detail='Тип линзы с таким ID не найден', ) lens_model = self.entity_to_model(lens) @@ -51,14 +51,14 @@ class LensesService: lens_model = await self.lenses_repository.get_by_id(lens_id) if not lens_model: - raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Lens not found") + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Линза не найдена") try: side_enum = SideEnum(lens.side) except ValueError: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail=f"Invalid side value: {lens.side}. Must be 'левая' or 'правая'." + detail=f"Недопустимое значение стороны линзы: {lens.side}. Допустимо 'левая' или 'правая'." ) lens_model.tor = lens.tor @@ -80,7 +80,7 @@ class LensesService: lens = await self.lenses_repository.get_by_id(lens_id) if not lens: - raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Lens not found") + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Линза не найдена") result = await self.lenses_repository.delete(lens) @@ -93,7 +93,7 @@ class LensesService: except ValueError: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail=f"Invalid side value: {lens.side}. Must be 'левая' or 'правая'." + detail=f"Недопустимое значение стороны линзы: {lens.side}. Допустимо 'левая' или 'правая'." ) lens_model = Lens( diff --git a/api/app/infrastructure/patients_service.py b/api/app/infrastructure/patients_service.py index aca50bd..bb56f29 100644 --- a/api/app/infrastructure/patients_service.py +++ b/api/app/infrastructure/patients_service.py @@ -31,7 +31,7 @@ class PatientsService: patient_model = await self.patient_repository.get_by_id(patient_id) if not patient_model: - raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Patient not found") + raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Пациент не найден") patient_model.first_name = patient.first_name patient_model.last_name = patient.last_name @@ -51,7 +51,7 @@ class PatientsService: patient = await self.patient_repository.get_by_id(patient_id) if not patient: - raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Patient not found") + raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Пациент не найден") result = await self.patient_repository.delete(patient) diff --git a/api/app/infrastructure/scheduled_appointments_service.py b/api/app/infrastructure/scheduled_appointments_service.py index cd9966e..a100d2e 100644 --- a/api/app/infrastructure/scheduled_appointments_service.py +++ b/api/app/infrastructure/scheduled_appointments_service.py @@ -35,7 +35,7 @@ class ScheduledAppointmentsService: if not doctor: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The doctor with this ID was not found', + detail='Доктор с таким ID не найден', ) scheduled_appointments = await self.scheduled_appointment_repository.get_by_doctor_id(doctor_id) @@ -53,7 +53,7 @@ class ScheduledAppointmentsService: if not patient: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The patient with this ID was not found', + detail='Пациент с таким ID не найден', ) scheduled_appointments = await self.scheduled_appointment_repository.get_by_patient_id(patient_id) @@ -72,7 +72,7 @@ class ScheduledAppointmentsService: if not patient: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The patient with this ID was not found', + detail='Пациент с таким ID не найден', ) doctor = await self.users_repository.get_by_id(doctor_id) @@ -80,7 +80,7 @@ class ScheduledAppointmentsService: if not doctor: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The doctor/user with this ID was not found', + detail='Доктор/пользователь с таким ID не найден', ) scheduled_appointment.doctor_id = doctor_id @@ -90,7 +90,7 @@ class ScheduledAppointmentsService: if not appointment_type: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The appointment type with this ID was not found', + detail='Тип приема с таким ID не найден', ) scheduled_appointment_model = self.entity_to_model(scheduled_appointment) @@ -103,7 +103,7 @@ class ScheduledAppointmentsService: 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") + raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Запланированный прием не найден") if scheduled_appointment_model.is_canceled: raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, @@ -114,13 +114,13 @@ class ScheduledAppointmentsService: if not doctor: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The doctor/user with this ID was not found', + detail='Доктор/пользователь с таким ID не найден', ) if scheduled_appointment_model.doctor_id != doctor_id and doctor.role.title != 'Администратор': raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, - detail='Permission denied', + detail='Доступ запрещен', ) scheduled_appointment_model.is_canceled = True @@ -137,14 +137,14 @@ class ScheduledAppointmentsService: 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") + raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Запланированный прием не найден") 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', + detail='Пациент с таким ID не найден', ) doctor = await self.users_repository.get_by_id(scheduled_appointment.doctor_id) @@ -152,7 +152,7 @@ class ScheduledAppointmentsService: if not doctor: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The doctor/user with this ID was not found', + detail='Доктор/пользователь с таким ID не найден', ) appointment_type = await self.appointment_types_repository.get_by_id(scheduled_appointment.type_id) @@ -160,7 +160,7 @@ class ScheduledAppointmentsService: if not appointment_type: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The appointment type with this ID was not found', + detail='Тип приема с таким ID не найден', ) scheduled_appointment_model.scheduled_datetime = scheduled_appointment.scheduled_datetime diff --git a/api/app/infrastructure/set_content_service.py b/api/app/infrastructure/set_content_service.py index c2d6053..f86a4b3 100644 --- a/api/app/infrastructure/set_content_service.py +++ b/api/app/infrastructure/set_content_service.py @@ -32,7 +32,7 @@ class SetContentService: if not _set: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The set with this ID was not found', + detail='Набор линз с таким ID не найден', ) set_content = await self.set_content_repository.get_by_set_id(set_id) @@ -49,7 +49,7 @@ class SetContentService: if not _set: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The set with this ID was not found', + detail='Набор линз с таким ID не найден', ) sets_content_models = [] @@ -60,7 +60,7 @@ class SetContentService: if not lens_type: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The lens type with this ID was not found', + detail='Nbg kbyps с таким ID не найден', ) sets_content_models.append( @@ -80,7 +80,7 @@ class SetContentService: if not _set: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The set with this ID was not found', + detail='Набор линз с таким ID не найден', ) lens_type = await self.lens_types_repository.get_by_id(set_content.type_id) @@ -88,7 +88,7 @@ class SetContentService: if not lens_type: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The lens type with this ID was not found', + detail='Nbg kbyps с таким ID не найден', ) _set = await self.set_repository.get_by_id(set_content.set_id) @@ -96,7 +96,7 @@ class SetContentService: if not _set: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The set with this ID was not found', + detail='Набор линз с таким ID не найден', ) set_content_model = self.entity_to_model(set_content, set_id) @@ -113,7 +113,7 @@ class SetContentService: if not _set: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The set with this ID was not found', + detail='Набор линз с таким ID не найден', ) old_set_content = await self.set_content_repository.get_by_set_id(set_id) @@ -140,14 +140,14 @@ class SetContentService: set_content_model = await self.set_content_repository.get_by_id(set_content_id) if not set_content_model: - raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Set content not found") + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Содержимое набора не найдено") _set = await self.set_repository.get_by_id(set_content.set_id) if not _set: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The set with this ID was not found', + detail='Набор линз с таким ID не найден', ) try: @@ -155,7 +155,7 @@ class SetContentService: except ValueError: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail=f"Invalid side value: {set_content_model.side}. Must be 'левая' or 'правая'." + detail=f"Недопустимое значение стороны линзы: {set_content_model.side}. Допустимо 'левая' или 'правая'." ) set_content_model.tor = set_content.tor @@ -178,7 +178,7 @@ class SetContentService: set_content = await self.set_content_repository.get_by_id(set_content_id) if not set_content: - raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Set content not found") + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Содержимое набора не найдено") result = await self.set_content_repository.delete(set_content) @@ -195,7 +195,7 @@ class SetContentService: except ValueError: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail=f"Invalid side value: {set_content.side}. Must be 'левая' or 'правая'." + detail=f"Недопустимое значение стороны линзы: {set_content.side}. Допустимо 'левая' или 'правая'." ) set_content_model = SetContent( diff --git a/api/app/infrastructure/sets_service.py b/api/app/infrastructure/sets_service.py index a09373c..3a71bad 100644 --- a/api/app/infrastructure/sets_service.py +++ b/api/app/infrastructure/sets_service.py @@ -38,7 +38,7 @@ class SetsService: set_model = await self.sets_repository.get_by_id(set_id) if not set_model: - raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Set not found") + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Набор линз не найден") set_model.title = _set.title @@ -50,7 +50,7 @@ class SetsService: _set = await self.sets_repository.get_by_id(set_id) if not _set: - raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Set not found") + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Набор линз не найден") set_content = await self.set_content_repository.get_by_set_id(set_id) await self.set_content_repository.delete_list_sets( @@ -65,7 +65,7 @@ class SetsService: _set = await self.sets_repository.get_by_id(set_id) if not _set: - raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Set not found") + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Набор линз не найден") set_content = await self.set_content_repository.get_by_set_id(set_id) diff --git a/api/app/infrastructure/users_service.py b/api/app/infrastructure/users_service.py index 69fb9dd..6e293c2 100644 --- a/api/app/infrastructure/users_service.py +++ b/api/app/infrastructure/users_service.py @@ -23,7 +23,7 @@ class UsersService: if not user: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='User was not found', + detail='Пользователь не найден', ) user_entity = self.model_to_entity(user) @@ -47,32 +47,32 @@ class UsersService: if not user: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='User was not found', + detail='Пользователь не найден', ) current_user = await self.users_repository.get_by_id(current_user_id) if not current_user: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='User was not found', + detail='Пользователь не найден', ) if user.id != current_user.id and current_user.role.title != 'Администратор': raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, - detail='Permission denied', + detail='Доступ запрещен', ) if not user.check_password(data.current_password): raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, - detail='Permission denied', + detail='Доступ запрещен', ) if data.new_password != data.confirm_password: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='Password not matched', + detail='Пароли не совпали', ) user.set_password(data.confirm_password) @@ -86,20 +86,26 @@ class UsersService: if not role: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='The role with this ID was not found' + detail='Роль с таким ID не найдена' ) user = await self.users_repository.get_by_login(register_entity.login) if user: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='Such a login already exists' + detail='Пользователь с таким логином уже существует' ) - if not self.is_strong_password(register_entity.password): + if register_entity.password != register_entity.confirm_password: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail="Password is too weak. It must contain at least 8 characters, including an uppercase letter, a lowercase letter, a digit, and a special character." + detail='Пароли не совпали', + ) + + if not self.is_strong_password(register_entity.confirm_password): + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="Пароль слишком слабый. Пароль должен содержать не менее 8 символов, включая хотя бы одну букву и одну цифру и один специальный символ." ) user_model = User( @@ -109,7 +115,7 @@ class UsersService: login=register_entity.login, role_id=register_entity.role_id, ) - user_model.set_password(register_entity.password) + user_model.set_password(register_entity.confirm_password) created_user = await self.users_repository.create(user_model) @@ -127,20 +133,20 @@ class UsersService: if not user_model: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='User was not found', + detail='Пользователь не найден', ) current_user = await self.users_repository.get_by_id(current_user_id) if not current_user: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, - detail='User was not found', + detail='Пользователь не найден', ) if user.id != current_user.id and current_user.role.title != 'Администратор': raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, - detail='Permission denied', + detail='Доступ запрещен', ) user_model.first_name = user.first_name