- Updated GBultoService to use models.Package instead of models.GBulto. - Refactored Part model to use SQLAlchemy 2.0 style with Mapped and mapped_column. - Added timestamps (created_at, updated_at, deleted_at) to various pedimento models. - Improved relationships and foreign key constraints in pedimento models. - Updated PermissionRuleOct and Seal models to use Mapped and mapped_column. - Changed DTO configuration from orm_mode to from_attributes for better compatibility. - Removed obsolete models (models.py and models_ped.py) from the repository.
66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from typing import List
|
|
|
|
from core.database import get_core_db
|
|
from core.security import get_current_user
|
|
from .dto import FractionRuleOctaveCreateDTO, FractionRuleOctaveResponseDTO
|
|
from .services import FractionRuleOctaveService
|
|
|
|
router = APIRouter(prefix="/fraction_rule_octave", tags=["FractionRuleOctave"])
|
|
|
|
|
|
@router.get("/", response_model=List[FractionRuleOctaveResponseDTO])
|
|
async def list_fractions(
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""
|
|
List all FractionRuleOctave entries.
|
|
"""
|
|
return db.query(FractionRuleOctaveService).all()
|
|
|
|
|
|
@router.get("/{permission}/{line}/{fraction}", response_model=FractionRuleOctaveResponseDTO)
|
|
async def read_fraction(
|
|
permission: str,
|
|
line: int,
|
|
fraction: str,
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""
|
|
Get a specific FractionRuleOctave by its composite key.
|
|
"""
|
|
frac = FractionRuleOctaveService.get_fraction_by_permission_line(db, permission, line, fraction)
|
|
if not frac:
|
|
raise HTTPException(status_code=404, detail="FractionRuleOctave not found")
|
|
return frac
|
|
|
|
|
|
@router.post("/", response_model=FractionRuleOctaveResponseDTO, status_code=status.HTTP_201_CREATED)
|
|
async def create_frac(
|
|
frac_data: FractionRuleOctaveCreateDTO,
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""
|
|
Create a new FractionRuleOctave entry.
|
|
"""
|
|
return FractionRuleOctaveService.create_frac(db, frac_data)
|
|
|
|
|
|
@router.delete("/{permission}/{line}/{fraction}", status_code=status.HTTP_204_NO_CONTENT)
|
|
async def delete_fraction(
|
|
permission: str,
|
|
line: int,
|
|
fraction: str,
|
|
db: Session = Depends(get_core_db),
|
|
current_user: dict = Depends(get_current_user)
|
|
):
|
|
"""
|
|
Delete a FractionRuleOctave by its composite key.
|
|
"""
|
|
frac = FractionRuleOctaveService.delete_fraction(db, permission, line, fraction)
|
|
if not frac:
|
|
raise HTTPException(status_code=404, detail="FractionRuleOctave not found") |