feat: 初始化工程
This commit is contained in:
29
routers/crop.py
Normal file
29
routers/crop.py
Normal 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
|
||||
Reference in New Issue
Block a user