Files
jungwoo choi e60e531cdc feat: Phase 2 - Service Management CRUD API (Backend)
Backend Implementation:
- Service model with comprehensive fields (name, url, type, status, health_endpoint)
- Complete CRUD API endpoints for service management
- Health check mechanism with httpx and response time tracking
- Service status tracking (healthy/unhealthy/unknown)
- Service type categorization (backend, frontend, database, cache, etc.)

API Endpoints:
- GET /api/services - Get all services
- POST /api/services - Create new service
- GET /api/services/{id} - Get service by ID
- PUT /api/services/{id} - Update service
- DELETE /api/services/{id} - Delete service
- POST /api/services/{id}/health-check - Check specific service health
- POST /api/services/health-check/all - Check all services health

Frontend Preparation:
- TypeScript type definitions for Service
- Service API client with full CRUD methods
- Health check client methods

Files Added:
- backend/app/models/service.py - Service data model
- backend/app/schemas/service.py - Request/response schemas
- backend/app/services/service_service.py - Business logic
- backend/app/routes/services.py - API route handlers
- frontend/src/types/service.ts - TypeScript types
- frontend/src/api/service.ts - API client

Updated:
- backend/app/main.py - Added services router
- docs/PROGRESS.md - Added Phase 2 status

Next: Frontend UI implementation (Services list page, Add/Edit modal, Health monitoring)

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-28 16:44:33 +09:00

114 lines
2.8 KiB
Python

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