mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Починка adm8
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
"""Employee management routes"""
|
"""Employee management routes"""
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
@@ -9,6 +10,26 @@ from ..utils.loggers import auth_logger
|
|||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.get("/")
|
||||||
|
async def get_employees(db: Session = Depends(get_db)):
|
||||||
|
"""Get all employees"""
|
||||||
|
try:
|
||||||
|
employees_list = db.query(employees_crud.Employee).all()
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"id": emp.id,
|
||||||
|
"firstName": emp.first_name,
|
||||||
|
"lastName": emp.last_name,
|
||||||
|
"department": emp.department,
|
||||||
|
"office": emp.office,
|
||||||
|
"createdAt": emp.created_at
|
||||||
|
}
|
||||||
|
for emp in employees_list
|
||||||
|
]
|
||||||
|
except Exception as e:
|
||||||
|
auth_logger.error(f"Error fetching employees: {e}", exc_info=True)
|
||||||
|
raise HTTPException(status_code=500, detail="Ошибка при получении списка сотрудников")
|
||||||
|
|
||||||
@router.post("/")
|
@router.post("/")
|
||||||
async def create_employee(employee: EmployeeCreate, db: Session = Depends(get_db)):
|
async def create_employee(employee: EmployeeCreate, db: Session = Depends(get_db)):
|
||||||
"""Create new employee"""
|
"""Create new employee"""
|
||||||
@@ -45,4 +66,4 @@ async def create_employee(employee: EmployeeCreate, db: Session = Depends(get_db
|
|||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
auth_logger.error(f"Error creating employee: {e}", exc_info=True)
|
auth_logger.error(f"Error creating employee: {e}", exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail="Ошибка при создании сотрудника")
|
raise HTTPException(status_code=500, detail="Ошибка при создании сотрудника")
|
||||||
|
Reference in New Issue
Block a user