From d06b1be8c19f3150782147d1ea3f1ee18109a48e Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Mon, 14 Apr 2025 03:08:20 +0000 Subject: [PATCH] feat: Generated endpoint endpoints/get-fruits.get.py via AI for Fruit --- endpoints/get-fruits.get.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/endpoints/get-fruits.get.py b/endpoints/get-fruits.get.py index e69de29..3b5212d 100644 --- a/endpoints/get-fruits.get.py +++ b/endpoints/get-fruits.get.py @@ -0,0 +1,16 @@ +from fastapi import APIRouter, Depends, HTTPException +from sqlalchemy.orm import Session +from typing import List +from core.database import get_db +from models.fruit import Fruit +from schemas.fruit import FruitSchema + +router = APIRouter() + +@router.get("/get-fruits", response_model=List[FruitSchema], status_code=200) +async def get_fruits(db: Session = Depends(get_db)): + """Get all fruits from the database""" + fruits = db.query(Fruit).all() + if not fruits: + raise HTTPException(status_code=404, detail="No fruits found") + return fruits \ No newline at end of file