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

починка 2

This commit is contained in:
MoonTestUse1
2025-01-04 04:57:49 +06:00
parent cbcd2b9695
commit 1586fdfe26
2 changed files with 24 additions and 10 deletions

View File

@@ -5,22 +5,36 @@ from . import models
from .routers import admin, employees, requests, auth, statistics from .routers import admin, employees, requests, auth, statistics
app = FastAPI( app = FastAPI(
# Отключаем автоматическое перенаправление со слэшем # Включаем автоматическое перенаправление со слэшем
redirect_slashes=False redirect_slashes=True,
# Добавляем описание API
title="Support System API",
description="API для системы поддержки",
version="1.0.0"
) )
# CORS configuration # CORS configuration
origins = [
"http://localhost",
"http://localhost:8080",
"http://localhost:5173",
"http://127.0.0.1:5173",
"http://127.0.0.1:8080",
"http://185.139.70.62", # Добавляем ваш production домен
]
app.add_middleware( app.add_middleware(
CORSMiddleware, CORSMiddleware,
allow_origins=["*"], allow_origins=origins,
allow_credentials=True, allow_credentials=True,
allow_methods=["*"], allow_methods=["*"],
allow_headers=["*"], allow_headers=["*"],
expose_headers=["*"]
) )
# Include routers # Include routers
app.include_router(auth.router, prefix="/api/auth", tags=["auth"]) app.include_router(auth.router, prefix="/api/auth", tags=["auth"])
app.include_router(employees.router) app.include_router(employees.router, prefix="/api/employees", tags=["employees"])
app.include_router(requests.router, prefix="/api/requests", tags=["requests"]) app.include_router(requests.router, prefix="/api/requests", tags=["requests"])
app.include_router(admin.router, prefix="/api/admin", tags=["admin"]) app.include_router(admin.router, prefix="/api/admin", tags=["admin"])
app.include_router(statistics.router, prefix="/api/statistics", tags=["statistics"]) app.include_router(statistics.router, prefix="/api/statistics", tags=["statistics"])

View File

@@ -11,9 +11,9 @@ from ..utils.auth import get_current_admin, get_password_hash
# Настройка логирования # Настройка логирования
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
router = APIRouter(prefix="/api/employees", tags=["employees"]) router = APIRouter(tags=["employees"])
@router.post("/", response_model=Employee, status_code=status.HTTP_201_CREATED) @router.post("", response_model=Employee, status_code=status.HTTP_201_CREATED)
async def create_employee( async def create_employee(
employee: EmployeeCreate, employee: EmployeeCreate,
db: Session = Depends(get_db), db: Session = Depends(get_db),
@@ -31,7 +31,7 @@ async def create_employee(
detail="Error creating employee" detail="Error creating employee"
) )
@router.get("/", response_model=List[Employee]) @router.get("", response_model=List[Employee])
async def get_employees( async def get_employees(
skip: int = 0, skip: int = 0,
limit: int = 100, limit: int = 100,
@@ -49,7 +49,7 @@ async def get_employees(
detail="Error getting employees" detail="Error getting employees"
) )
@router.get("/{employee_id}/", response_model=Employee) @router.get("/{employee_id}", response_model=Employee)
async def get_employee( async def get_employee(
employee_id: int, employee_id: int,
db: Session = Depends(get_db), db: Session = Depends(get_db),
@@ -71,7 +71,7 @@ async def get_employee(
detail="Error getting employee" detail="Error getting employee"
) )
@router.put("/{employee_id}/", response_model=Employee) @router.put("/{employee_id}", response_model=Employee)
async def update_employee( async def update_employee(
employee_id: int, employee_id: int,
employee: EmployeeUpdate, employee: EmployeeUpdate,
@@ -94,7 +94,7 @@ async def update_employee(
detail="Error updating employee" detail="Error updating employee"
) )
@router.delete("/{employee_id}/", response_model=Employee) @router.delete("/{employee_id}", response_model=Employee)
async def delete_employee( async def delete_employee(
employee_id: int, employee_id: int,
db: Session = Depends(get_db), db: Session = Depends(get_db),