endpoint_biblioteca_funcionando
This commit is contained in:
@@ -4,6 +4,6 @@ from fastapi import APIRouter
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/ping")
|
||||
@router.get("/")
|
||||
async def ping():
|
||||
return {"message": "pong"}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
from backend.db.conexion import get_conexion
|
||||
from src.TextManager.biblioteca import Biblioteca
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class BibliotecaIn(BaseModel):
|
||||
nombre: str
|
||||
descripcion: Optional[str] = ""
|
||||
vector_dim: Optional[int] = None
|
||||
|
||||
@router.post("/")
|
||||
def crear_biblioteca(biblio: BibliotecaIn):
|
||||
try:
|
||||
biblioteca = Biblioteca(
|
||||
nombre=biblio.nombre,
|
||||
descripcion=biblio.descripcion,
|
||||
vector_dim=biblio.vector_dim
|
||||
)
|
||||
conexion = get_conexion()
|
||||
modelo = biblioteca.generar_modelo_notas(conexion)
|
||||
return {"id": biblioteca.id, "modelo": str(modelo.__name__)}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
@@ -0,0 +1,21 @@
|
||||
# backend/api/v1/biblioteca.py
|
||||
from fastapi import APIRouter, Depends
|
||||
from pydantic import BaseModel
|
||||
from backend.db.conexion import get_conexion
|
||||
from backend.services.text_manager import crear_biblioteca
|
||||
from src.ConexionSql.Postgres_conexion import PostgresConexion
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class BibliotecaInput(BaseModel):
|
||||
nombre_biblioteca: str
|
||||
descripcion: str
|
||||
|
||||
@router.post("/")
|
||||
def crear_biblioteca_endpoint(
|
||||
data: BibliotecaInput,
|
||||
conexion: PostgresConexion = Depends(get_conexion)
|
||||
):
|
||||
return crear_biblioteca(nombre_biblioteca=data.nombre_biblioteca,
|
||||
descripcion=data.descripcion,
|
||||
conexion=conexion)
|
||||
@@ -1,8 +1,8 @@
|
||||
# backend/api/router.py
|
||||
|
||||
from fastapi import APIRouter
|
||||
from backend.api.v1.endpoints import ping, nota, text_manager
|
||||
from backend.api.v1.endpoints import ping, text_manager_endpoint
|
||||
|
||||
router = APIRouter()
|
||||
router.include_router(ping.router, prefix="/api/v1/ping")
|
||||
router.include_router(text_manager.router, prefix="/api/v1/bibliotecas")
|
||||
router.include_router(text_manager_endpoint.router, prefix="/api/v1/text_manager")
|
||||
|
||||
Reference in New Issue
Block a user