628cddc3ae
- Updated LoggerDB to remove all active sinks on initialization. - Added a new PostgresCredencial setup in notas_mmr.py for database connection. - Replaced print statements with logger calls for better logging in notas_mmr.py. - Introduced new FastAPI endpoints for various chart types (bar, line, pie, scatter). - Created Editor_biblioteca.css for styling the rich text editor. - Implemented Editor_Test.tsx to test the rich text editor functionality.
113 lines
4.0 KiB
Python
113 lines
4.0 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from fastapi import Path
|
|
|
|
from backend.schemas.text_manager_schema import BibliotecaInput, NotaInput
|
|
|
|
from fastapi.concurrency import run_in_threadpool
|
|
from backend.db.conexion import get_conexion
|
|
from backend.services.text_manager_srvc import *
|
|
from src.ConexionSql.Postgres_conexion import PostgresConexion
|
|
|
|
from entrypoint.init_db import db_credencial
|
|
from src.Logger.logger_db import LoggerDB, logger
|
|
LoggerDB(db_credencial, "logger_textos", created_by="sistema")
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/biblioteca", summary="Crear una nueva biblioteca")
|
|
async def crear_biblioteca_endpoint(
|
|
data: BibliotecaInput,
|
|
conexion: PostgresConexion = Depends(get_conexion)
|
|
):
|
|
try:
|
|
return await run_in_threadpool(
|
|
crear_biblioteca,
|
|
data.nombre_biblioteca,
|
|
conexion,
|
|
data.descripcion,
|
|
)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=404, detail=str(e))
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"Error interno al crear la biblioteca: {str(e)}")
|
|
|
|
|
|
|
|
@router.get("/list", summary="Listar todas las bibliotecas")
|
|
def listar_todas_bibliotecas(
|
|
conexion: PostgresConexion = Depends(get_conexion)
|
|
):
|
|
try:
|
|
return listar_bibliotecas(conexion=conexion)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=404, detail=str(e))
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail="Error interno al listar las bibliotecas")
|
|
|
|
|
|
|
|
@router.post("/nota/{biblioteca_id}", summary="Agregar una nota a una biblioteca")
|
|
def agregar_nota(
|
|
biblioteca_id: str = Path(..., description="ID de la biblioteca a la que se agregará la nota"),
|
|
nota: NotaInput = ..., # viene del body
|
|
conexion: PostgresConexion = Depends(get_conexion)
|
|
):
|
|
try:
|
|
return agregar_nota_a_biblioteca(
|
|
conexion=conexion,
|
|
biblioteca_id=biblioteca_id,
|
|
titulo=nota.titulo,
|
|
texto=nota.texto,
|
|
tags=nota.tags,
|
|
conexiones=nota.conexiones,
|
|
resumen=nota.resumen
|
|
)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=404, detail=str(e))
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail="Error interno al agregar la nota")
|
|
|
|
|
|
|
|
@router.get("/nota/list/{biblioteca_id}", summary="Listar todas las notas de una biblioteca")
|
|
def listar_notas(
|
|
biblioteca_id: str,
|
|
conexion: PostgresConexion = Depends(get_conexion)
|
|
):
|
|
try:
|
|
return listar_notas_de_biblioteca(conexion, biblioteca_id)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=404, detail=str(e))
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail="Error interno al listar las notas")
|
|
|
|
|
|
|
|
@router.delete("/nota/{biblioteca_id}/{nota_id}", summary="Eliminar una nota por ID")
|
|
def eliminar_nota_endpoint(
|
|
biblioteca_id: str = Path(..., description="ID de la biblioteca"),
|
|
nota_id: str = Path(..., description="ID de la nota a eliminar"),
|
|
conexion: PostgresConexion = Depends(get_conexion)
|
|
):
|
|
try:
|
|
return eliminar_nota(conexion=conexion, biblioteca_id=biblioteca_id, nota_id=nota_id)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=404, detail=str(e))
|
|
except Exception:
|
|
raise HTTPException(status_code=500, detail="Error interno al eliminar la nota")
|
|
|
|
|
|
@router.put("/nota/{biblioteca_id}/{nota_id}", summary="Actualizar una nota por ID")
|
|
def actualizar_nota_endpoint(
|
|
biblioteca_id: str = Path(..., description="ID de la biblioteca"),
|
|
nota_id: str = Path(..., description="ID de la nota a actualizar"),
|
|
nota: NotaInput = ..., # body
|
|
conexion: PostgresConexion = Depends(get_conexion)
|
|
):
|
|
try:
|
|
return actualizar_nota(conexion=conexion, biblioteca_id=biblioteca_id, nota_id=nota_id, nota_input=nota)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=404, detail=str(e))
|
|
except Exception:
|
|
raise HTTPException(status_code=500, detail="Error interno al actualizar la nota") |