Files
patch-service/routers/crop.py
2026-09-09 18:42:37 +08:00

30 lines
912 B
Python

from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from config.database import get_db
from schemas.patch import CropCreate, CropUpdate
from service import crop_service
router = APIRouter(prefix="/crops", tags=["crops"])
@router.post("", response_model=bool)
def create(data: CropCreate, db: Session = Depends(get_db)):
return crop_service.create_crop(db, data)
@router.put("/{crop_id}", response_model=bool)
def update(crop_id: int, data: CropUpdate, db: Session = Depends(get_db)):
crop = crop_service.update_crop(db, crop_id, data)
if not crop:
raise HTTPException(404, "Crop not found")
return crop
@router.delete("/{crop_id}", response_model=bool)
def delete(crop_id: int, db: Session = Depends(get_db)):
crop = crop_service.delete_crop(db, crop_id)
if not crop:
raise HTTPException(404, "Crop not found")
return crop