/
Kostyable
/
callmaster
Обзор
Документация
Войти
/
Kostyable
/
callmaster
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
app/controllers/specialist_controller.py
41 строка
2 KB
Kostyable
feat: implement mvc model
29 окт 2024, 17:52
29 окт 2024, 17:52
0ad77c5
Код
Авторство
О чём код?
from fastapi import HTTPException from app.database.crud import create_specialist, get_specialist_by_id, update_specialist_email, update_specialist_phone, update_specialist_password from app.models.main import SpecializationEnum from app.utils.validators import validate_phone_number, validate_password def register_specialist_controller(specialist_data): validate_phone_number(specialist_data['phone_number']) validate_password(specialist_data['password']) if specialist_data['specialization'] not in SpecializationEnum.__members__.values(): raise HTTPException(status_code=400, detail="Неверная специализация") specialist_id = create_specialist(specialist_data) if specialist_id is None: raise HTTPException(status_code=500, detail="Ошибка при создании специалиста") return specialist_id def get_specialist_controller(specialist_id): specialist = get_specialist_by_id(specialist_id) if specialist is None: raise HTTPException(status_code=404, detail="Специалист не найден") return specialist def update_specialist_email_controller(specialist_id, new_email): success = update_specialist_email(specialist_id, new_email) if not success: raise HTTPException(status_code=500, detail="Ошибка обновления email специалиста") return {"message": "Email специалиста успешно обновлен"} def update_specialist_phone_controller(specialist_id, new_phone_number): validate_phone_number(new_phone_number) success = update_specialist_phone(specialist_id, new_phone_number) if not success: raise HTTPException(status_code=500, detail="Ошибка обновления телефона специалиста") return {"message": "Телефон специалиста успешно обновлен"} def update_specialist_password_controller(specialist_id, new_password): validate_password(new_password) success = update_specialist_password(specialist_id, new_password) if not success: raise HTTPException(status_code=500, detail="Ошибка обновления пароля специалиста") return {"message": "Пароль специалиста успешно обновлен"}