Spaces:
Runtime error
Runtime error
Download templates/api_templates/api_endpoints.py.j2 from DesarrolloTT/DataSuitePro: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/spaces/DesarrolloTT/DataSuitePro/resolve/main/templates/api_templates/api_endpoints.py.j2
- Command line
-
hf download hf://spaces/DesarrolloTT/DataSuitePro/templates/api_templates/api_endpoints.py.j2
-
curl -L -o api_endpoints.py.j2 https://huggingface.co/spaces/DesarrolloTT/DataSuitePro/resolve/main/templates/api_templates/api_endpoints.py.j2
1.83 kB
| from fastapi import APIRouter, HTTPException | |
| from typing import List, Optional | |
| {% if database != "none" %} | |
| from app import models, schemas | |
| from app.database import SessionLocal | |
| {% endif %} | |
| router = APIRouter() | |
| # Simulamos datos por ahora (en una versión real, usaríamos base de datos) | |
| sample_data = [ | |
| {"id": 1, "name": "Ejemplo 1", "description": "Datos de ejemplo"} | |
| ] | |
| async def list_items(skip: int = 0, limit: int = 100): | |
| """Listar todos los items""" | |
| return sample_data[skip:skip + limit] | |
| async def read_item(item_id: int): | |
| """Obtener un item por ID""" | |
| for item in sample_data: | |
| if item["id"] == item_id: | |
| return item | |
| raise HTTPException(status_code=404, detail="Item no encontrado") | |
| async def create_item(item: dict): | |
| """Crear un nuevo item""" | |
| new_id = max([i["id"] for i in sample_data]) + 1 if sample_data else 1 | |
| new_item = {"id": new_id, **item} | |
| sample_data.append(new_item) | |
| return new_item | |
| async def update_item(item_id: int, item: dict): | |
| """Actualizar un item existente""" | |
| for i, existing_item in enumerate(sample_data): | |
| if existing_item["id"] == item_id: | |
| sample_data[i] = {"id": item_id, **item} | |
| return sample_data[i] | |
| raise HTTPException(status_code=404, detail="Item no encontrado") | |
| async def delete_item(item_id: int): | |
| """Eliminar un item""" | |
| for i, item in enumerate(sample_data): | |
| if item["id"] == item_id: | |
| del sample_data[i] | |
| return {"message": "Item eliminado"} | |
| raise HTTPException(status_code=404, detail="Item no encontrado") |