from fastapi import APIRouter, Depends, HTTPException from sqlalchemy.orm import Session from config.database import get_db from schemas.patch import PatchResponse, PatchCreate, PatchUpdate from service import patch_service from service.patch_service import get_patch router = APIRouter(prefix="/patches", tags=["patches"]) @router.post("", response_model=bool) def create(data: PatchCreate, db: Session = Depends(get_db)): return patch_service.create_patch(db, data) @router.get("", response_model=list[PatchResponse]) def list_all(db: Session = Depends(get_db)): return patch_service.get_patches(db) @router.get("/{patch_id}", response_model=PatchResponse) def get_one(patch_id: int, db: Session = Depends(get_db)): patch = get_patch(db, patch_id) if not patch: raise HTTPException(404, "Patch not found") return patch @router.put("/{patch_id}", response_model=bool) def update(patch_id: int, data: PatchUpdate, db: Session = Depends(get_db)): patch = patch_service.update_patch(db, patch_id, data) if not patch: raise HTTPException(404, "Patch not found") return patch @router.delete("/{patch_id}", response_model=bool) def delete(patch_id: int, db: Session = Depends(get_db)): patch = patch_service.delete_patch(db, patch_id) if not patch: raise HTTPException(404, "Patch not found") return patch