1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

Все подряд

This commit is contained in:
MoonTestUse1
2024-12-31 02:37:57 +06:00
parent 8e53bb6cb2
commit d5780b2eab
3258 changed files with 1087440 additions and 268 deletions

View File

@@ -3,6 +3,7 @@ from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from ..database import get_db
from ..crud import requests as requests_crud
from ..crud import employees as employees_crud
from ..models.request import RequestCreate
from ..bot.notifications import send_notification
from ..utils.loggers import request_logger
@@ -13,13 +14,27 @@ router = APIRouter()
async def create_request(request: RequestCreate, db: Session = Depends(get_db)):
"""Create new request"""
try:
# Verify employee exists
employee = employees_crud.get_employee(db, request.employee_id)
if not employee:
raise HTTPException(
status_code=404,
detail="Сотрудник не найден"
)
db_request = requests_crud.create_request(db, request)
request_logger.info(
"Request created",
extra={"request_id": db_request.id, "employee_id": request.employee_id}
)
await send_notification(requests_crud.get_request_details(db, db_request.id))
request_details = requests_crud.get_request_details(db, db_request.id)
await send_notification(request_details)
return db_request
except HTTPException:
raise
except Exception as e:
request_logger.error(
f"Error creating request: {e}",