refactor: Замена текста ошибок на русский язык

This commit is contained in:
Андрей Дувакин 2025-06-03 10:51:25 +05:00
parent b581ffd003
commit d0d5bc2798
10 changed files with 69 additions and 62 deletions

View File

@ -10,3 +10,4 @@ class RegisterEntity(BaseModel):
role_id: int role_id: int
login: str login: str
password: str password: str
confirm_password: str

View File

@ -36,7 +36,7 @@ class AppointmentsService:
if not doctor: if not doctor:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) appointments = await self.appointments_repository.get_by_doctor_id(doctor_id)
@ -52,7 +52,7 @@ class AppointmentsService:
if not patient: if not patient:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) appointments = await self.appointments_repository.get_by_patient_id(patient_id)
@ -68,7 +68,7 @@ class AppointmentsService:
if not patient: if not patient:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) doctor = await self.users_repository.get_by_id(doctor_id)
@ -76,7 +76,7 @@ class AppointmentsService:
if not doctor: if not doctor:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,
detail='The doctor/user with this ID was not found', detail='Доктор/пользователь с таким ID не найден',
) )
appointment.doctor_id = doctor_id appointment.doctor_id = doctor_id
@ -86,7 +86,7 @@ class AppointmentsService:
if not appointment_type: if not appointment_type:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) appointment_model = self.entity_to_model(appointment)
@ -101,14 +101,14 @@ class AppointmentsService:
appointment_model = await self.appointments_repository.get_by_id(appointment_id) appointment_model = await self.appointments_repository.get_by_id(appointment_id)
if not appointment_model: 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) patient = await self.patients_repository.get_by_id(appointment.patient_id)
if not patient: if not patient:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) doctor = await self.users_repository.get_by_id(appointment.doctor_id)
@ -116,7 +116,7 @@ class AppointmentsService:
if not doctor: if not doctor:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) appointment_type = await self.appointment_types_repository.get_by_id(appointment.type_id)
@ -124,7 +124,7 @@ class AppointmentsService:
if not appointment_type: if not appointment_type:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,
detail='The appointment type with this ID was not found', detail='Тип приема с таким ID не найден',
) )
appointment_model.results = appointment.results appointment_model.results = appointment.results

View File

@ -23,7 +23,7 @@ class AuthService:
"user_id": user.id "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 @staticmethod
def create_access_token(data: dict) -> str: def create_access_token(data: dict) -> str:

View File

@ -36,7 +36,7 @@ class LensIssuesService:
if not patient: if not patient:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) user = await self.users_repository.get_by_id(user_id)
@ -44,7 +44,7 @@ class LensIssuesService:
if not user: if not user:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,
detail='The user with this ID was not found', detail='Пользователь с таким ID не найден',
) )
lens_issue.doctor_id = user_id lens_issue.doctor_id = user_id
@ -54,13 +54,13 @@ class LensIssuesService:
if not lens: if not lens:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,
detail='The lens with this ID was not found', detail='Линза с таким ID не найдена',
) )
if lens.issued: if lens.issued:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,
detail='The lens is already issued', detail='Линза уже выдана',
) )
lens_issue_model = self.entity_to_model(lens_issue) lens_issue_model = self.entity_to_model(lens_issue)

View File

@ -38,7 +38,7 @@ class LensesService:
if not lens_type: if not lens_type:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) lens_model = self.entity_to_model(lens)
@ -51,14 +51,14 @@ class LensesService:
lens_model = await self.lenses_repository.get_by_id(lens_id) lens_model = await self.lenses_repository.get_by_id(lens_id)
if not lens_model: 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: try:
side_enum = SideEnum(lens.side) side_enum = SideEnum(lens.side)
except ValueError: except ValueError:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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 lens_model.tor = lens.tor
@ -80,7 +80,7 @@ class LensesService:
lens = await self.lenses_repository.get_by_id(lens_id) lens = await self.lenses_repository.get_by_id(lens_id)
if not lens: 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) result = await self.lenses_repository.delete(lens)
@ -93,7 +93,7 @@ class LensesService:
except ValueError: except ValueError:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,
detail=f"Invalid side value: {lens.side}. Must be 'левая' or 'правая'." detail=f"Недопустимое значение стороны линзы: {lens.side}. Допустимо 'левая' или 'правая'."
) )
lens_model = Lens( lens_model = Lens(

View File

@ -31,7 +31,7 @@ class PatientsService:
patient_model = await self.patient_repository.get_by_id(patient_id) patient_model = await self.patient_repository.get_by_id(patient_id)
if not patient_model: 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.first_name = patient.first_name
patient_model.last_name = patient.last_name patient_model.last_name = patient.last_name
@ -51,7 +51,7 @@ class PatientsService:
patient = await self.patient_repository.get_by_id(patient_id) patient = await self.patient_repository.get_by_id(patient_id)
if not patient: 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) result = await self.patient_repository.delete(patient)

View File

@ -35,7 +35,7 @@ class ScheduledAppointmentsService:
if not doctor: if not doctor:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) scheduled_appointments = await self.scheduled_appointment_repository.get_by_doctor_id(doctor_id)
@ -53,7 +53,7 @@ class ScheduledAppointmentsService:
if not patient: if not patient:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) scheduled_appointments = await self.scheduled_appointment_repository.get_by_patient_id(patient_id)
@ -72,7 +72,7 @@ class ScheduledAppointmentsService:
if not patient: if not patient:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) doctor = await self.users_repository.get_by_id(doctor_id)
@ -80,7 +80,7 @@ class ScheduledAppointmentsService:
if not doctor: if not doctor:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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 scheduled_appointment.doctor_id = doctor_id
@ -90,7 +90,7 @@ class ScheduledAppointmentsService:
if not appointment_type: if not appointment_type:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) 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) scheduled_appointment_model = await self.scheduled_appointment_repository.get_by_id(scheduled_appointment_id)
if not scheduled_appointment_model: 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: if scheduled_appointment_model.is_canceled:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST,
@ -114,13 +114,13 @@ class ScheduledAppointmentsService:
if not doctor: if not doctor:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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 != 'Администратор': if scheduled_appointment_model.doctor_id != doctor_id and doctor.role.title != 'Администратор':
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail='Permission denied', detail='Доступ запрещен',
) )
scheduled_appointment_model.is_canceled = True 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) scheduled_appointment_model = await self.scheduled_appointment_repository.get_by_id(scheduled_appointment_id)
if not scheduled_appointment_model: 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) patient = await self.patients_repository.get_by_id(scheduled_appointment.patient_id)
if not patient: if not patient:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) doctor = await self.users_repository.get_by_id(scheduled_appointment.doctor_id)
@ -152,7 +152,7 @@ class ScheduledAppointmentsService:
if not doctor: if not doctor:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) appointment_type = await self.appointment_types_repository.get_by_id(scheduled_appointment.type_id)
@ -160,7 +160,7 @@ class ScheduledAppointmentsService:
if not appointment_type: if not appointment_type:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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 scheduled_appointment_model.scheduled_datetime = scheduled_appointment.scheduled_datetime

View File

@ -32,7 +32,7 @@ class SetContentService:
if not _set: if not _set:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) set_content = await self.set_content_repository.get_by_set_id(set_id)
@ -49,7 +49,7 @@ class SetContentService:
if not _set: if not _set:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,
detail='The set with this ID was not found', detail='Набор линз с таким ID не найден',
) )
sets_content_models = [] sets_content_models = []
@ -60,7 +60,7 @@ class SetContentService:
if not lens_type: if not lens_type:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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( sets_content_models.append(
@ -80,7 +80,7 @@ class SetContentService:
if not _set: if not _set:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) lens_type = await self.lens_types_repository.get_by_id(set_content.type_id)
@ -88,7 +88,7 @@ class SetContentService:
if not lens_type: if not lens_type:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) _set = await self.set_repository.get_by_id(set_content.set_id)
@ -96,7 +96,7 @@ class SetContentService:
if not _set: if not _set:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) set_content_model = self.entity_to_model(set_content, set_id)
@ -113,7 +113,7 @@ class SetContentService:
if not _set: if not _set:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) 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) set_content_model = await self.set_content_repository.get_by_id(set_content_id)
if not set_content_model: 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) _set = await self.set_repository.get_by_id(set_content.set_id)
if not _set: if not _set:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,
detail='The set with this ID was not found', detail='Набор линз с таким ID не найден',
) )
try: try:
@ -155,7 +155,7 @@ class SetContentService:
except ValueError: except ValueError:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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 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) set_content = await self.set_content_repository.get_by_id(set_content_id)
if not set_content: 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) result = await self.set_content_repository.delete(set_content)
@ -195,7 +195,7 @@ class SetContentService:
except ValueError: except ValueError:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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( set_content_model = SetContent(

View File

@ -38,7 +38,7 @@ class SetsService:
set_model = await self.sets_repository.get_by_id(set_id) set_model = await self.sets_repository.get_by_id(set_id)
if not set_model: 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 set_model.title = _set.title
@ -50,7 +50,7 @@ class SetsService:
_set = await self.sets_repository.get_by_id(set_id) _set = await self.sets_repository.get_by_id(set_id)
if not _set: 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) set_content = await self.set_content_repository.get_by_set_id(set_id)
await self.set_content_repository.delete_list_sets( await self.set_content_repository.delete_list_sets(
@ -65,7 +65,7 @@ class SetsService:
_set = await self.sets_repository.get_by_id(set_id) _set = await self.sets_repository.get_by_id(set_id)
if not _set: 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) set_content = await self.set_content_repository.get_by_set_id(set_id)

View File

@ -23,7 +23,7 @@ class UsersService:
if not user: if not user:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,
detail='User was not found', detail='Пользователь не найден',
) )
user_entity = self.model_to_entity(user) user_entity = self.model_to_entity(user)
@ -47,32 +47,32 @@ class UsersService:
if not user: if not user:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) current_user = await self.users_repository.get_by_id(current_user_id)
if not current_user: if not current_user:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,
detail='User was not found', detail='Пользователь не найден',
) )
if user.id != current_user.id and current_user.role.title != 'Администратор': if user.id != current_user.id and current_user.role.title != 'Администратор':
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail='Permission denied', detail='Доступ запрещен',
) )
if not user.check_password(data.current_password): if not user.check_password(data.current_password):
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail='Permission denied', detail='Доступ запрещен',
) )
if data.new_password != data.confirm_password: if data.new_password != data.confirm_password:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,
detail='Password not matched', detail='Пароли не совпали',
) )
user.set_password(data.confirm_password) user.set_password(data.confirm_password)
@ -86,20 +86,26 @@ class UsersService:
if not role: if not role:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) user = await self.users_repository.get_by_login(register_entity.login)
if user: if user:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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( user_model = User(
@ -109,7 +115,7 @@ class UsersService:
login=register_entity.login, login=register_entity.login,
role_id=register_entity.role_id, 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) created_user = await self.users_repository.create(user_model)
@ -127,20 +133,20 @@ class UsersService:
if not user_model: if not user_model:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, 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) current_user = await self.users_repository.get_by_id(current_user_id)
if not current_user: if not current_user:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, status_code=status.HTTP_400_BAD_REQUEST,
detail='User was not found', detail='Пользователь не найден',
) )
if user.id != current_user.id and current_user.role.title != 'Администратор': if user.id != current_user.id and current_user.role.title != 'Администратор':
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail='Permission denied', detail='Доступ запрещен',
) )
user_model.first_name = user.first_name user_model.first_name = user.first_name