from typing import List from fastapi import APIRouter, Depends, HTTPException, status from app.models.service import Service from app.models.user import User from app.schemas.service import ( ServiceCreate, ServiceUpdate, ServiceResponse, ServiceHealthCheck ) from app.services.service_service import ServiceService from app.core.security import get_current_user router = APIRouter(prefix="/api/services", tags=["services"]) @router.post("", response_model=ServiceResponse, status_code=status.HTTP_201_CREATED) async def create_service( service_data: ServiceCreate, current_user: User = Depends(get_current_user) ): """ Create a new service Requires authentication. """ service = await ServiceService.create_service(service_data) return service.model_dump(by_alias=True) @router.get("", response_model=List[ServiceResponse]) async def get_all_services( current_user: User = Depends(get_current_user) ): """ Get all services Requires authentication. """ services = await ServiceService.get_all_services() return [service.model_dump(by_alias=True) for service in services] @router.get("/{service_id}", response_model=ServiceResponse) async def get_service( service_id: str, current_user: User = Depends(get_current_user) ): """ Get a service by ID Requires authentication. """ service = await ServiceService.get_service(service_id) return service.model_dump(by_alias=True) @router.put("/{service_id}", response_model=ServiceResponse) async def update_service( service_id: str, service_data: ServiceUpdate, current_user: User = Depends(get_current_user) ): """ Update a service Requires authentication. """ service = await ServiceService.update_service(service_id, service_data) return service.model_dump(by_alias=True) @router.delete("/{service_id}", status_code=status.HTTP_204_NO_CONTENT) async def delete_service( service_id: str, current_user: User = Depends(get_current_user) ): """ Delete a service Requires authentication. """ await ServiceService.delete_service(service_id) return None @router.post("/{service_id}/health-check", response_model=ServiceHealthCheck) async def check_service_health( service_id: str, current_user: User = Depends(get_current_user) ): """ Check health of a specific service Requires authentication. """ result = await ServiceService.check_service_health(service_id) return result @router.post("/health-check/all", response_model=List[ServiceHealthCheck]) async def check_all_services_health( current_user: User = Depends(get_current_user) ): """ Check health of all services Requires authentication. """ results = await ServiceService.check_all_services_health() return results