Creacion de CRUDs

se crearon los cruds de los catalogos que se encuentran en
public/reference_data
No se agrego autenticacion de los endpoints
This commit is contained in:
2025-10-26 19:13:42 -06:00
parent 1961296593
commit 0aa5fc72fd
36 changed files with 1005 additions and 14 deletions

View File

@@ -0,0 +1,9 @@
from pydantic import BaseModel, Field
class ValuationMethodDTO(BaseModel):
key: str = Field(..., min_length=1, max_length=2)
description: str
class Config:
from_attributes = True

View File

@@ -0,0 +1,46 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from core.database import get_core_db
from .models import ValuationMethod
from .dto import ValuationMethodDTO
router = APIRouter(prefix="/valuation-methods", tags=["Valuation Methods"])
@router.get("/", response_model=list[ValuationMethodDTO])
def list_valuation_methods(db: Session = Depends(get_core_db)):
return db.query(ValuationMethod).all()
@router.get("/{key}", response_model=ValuationMethodDTO)
def get_valuation_method(key: str, db: Session = Depends(get_core_db)):
obj = db.query(ValuationMethod).filter(ValuationMethod.key == key).first()
if not obj:
raise HTTPException(status_code=404, detail="Not found")
return obj
@router.post("/", response_model=ValuationMethodDTO, status_code=201)
def create_valuation_method(data: ValuationMethodDTO, db: Session = Depends(get_core_db)):
obj = ValuationMethod(**data.dict())
db.add(obj)
db.commit()
db.refresh(obj)
return obj
@router.put("/{key}", response_model=ValuationMethodDTO)
def update_valuation_method(key: str, data: ValuationMethodDTO, db: Session = Depends(get_core_db)):
obj = db.query(ValuationMethod).filter(ValuationMethod.key == key).first()
if not obj:
raise HTTPException(status_code=404, detail="Not found")
for field, value in data.dict().items():
setattr(obj, field, value)
db.commit()
db.refresh(obj)
return obj
@router.delete("/{key}", status_code=204)
def delete_valuation_method(key: str, db: Session = Depends(get_core_db)):
obj = db.query(ValuationMethod).filter(ValuationMethod.key == key).first()
if not obj:
raise HTTPException(status_code=404, detail="Not found")
db.delete(obj)
db.commit()
return None