From 111a65da858079e8a14676b0fdf7a0f354c68538 Mon Sep 17 00:00:00 2001 From: Brian Wiborg Date: Sun, 28 Sep 2025 17:33:21 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20CRUD=20endpoints=20boilerplate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ohmyapi/core/templates/app/routes.py.j2 | 38 +++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/ohmyapi/core/templates/app/routes.py.j2 b/src/ohmyapi/core/templates/app/routes.py.j2 index a5a4d4f..dd1579a 100644 --- a/src/ohmyapi/core/templates/app/routes.py.j2 +++ b/src/ohmyapi/core/templates/app/routes.py.j2 @@ -1,17 +1,41 @@ -from ohmyapi.router import APIRouter +from ohmyapi.router import APIRouter, HTTPException, HTTPStatus from . import models +from typing import List + # Expose your app's routes via `router = fastapi.APIRouter`. # Use prefixes wisely to avoid cross-app namespace-collisions. # Tags improve the UX of the OpenAPI docs at /docs. router = APIRouter(prefix="/{{ app_name }}", tags=['{{ app_name }}']) -@router.get("/") -def hello_world(): - return { - "project": "{{ project_name }}", - "app": "{{ app_name }}", - } + +@router.get("/") +async def list(): + """List all ...""" + return [] + + +@router.post("/") +async def post(): + """Create ...""" + return HTTPException(status_code=HTTPStatus.CREATED) + + +@router.get("/{id}") +async def get(id: str): + """Get single ...""" + return {} + + +@router.put("/{id}") +async def put(id: str): + """Update ...""" + return HTTPException(status_code=HTTPStatus.ACCEPTED) + + +@router.delete("/{id}") +async def delete(id: str): + return HTTPException(status_code=HTTPStatus.ACCEPTED)