feat: 初始化工程

This commit is contained in:
2026-09-09 18:42:37 +08:00
commit 31af6e07e2
29 changed files with 1208 additions and 0 deletions

29
routers/crop.py Normal file
View File

@@ -0,0 +1,29 @@
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