Refactor Dewar service methods and improve field handling

Updated Dewar API methods to use protected endpoints for enhanced security and consistency. Added `pgroups` handling in various frontend components and modified the LogisticsView contact field for clarity. Simplified backend router imports for better readability.
This commit is contained in:
GotthardG
2025-01-30 13:39:49 +01:00
parent 44582cf38e
commit c2215860bf
20 changed files with 304 additions and 262 deletions

View File

@ -3,6 +3,8 @@ from sqlalchemy.orm import Session
from typing import List
from datetime import date
import json
import logging
from sqlalchemy.exc import SQLAlchemyError
from app.models import (
Shipment as ShipmentModel,
@ -20,11 +22,11 @@ from app.schemas import (
Shipment as ShipmentSchema,
Contact as ContactSchema,
Sample as SampleSchema,
DewarSchema,
loginData,
Dewar,
)
from app.database import get_db
from app.crud import get_shipment_by_id
from app.crud import get_shipment_by_id, get_shipments
from app.routers.auth import get_current_user
shipment_router = APIRouter()
@ -59,7 +61,17 @@ async def fetch_shipments(
return shipments
@shipment_router.get("/{shipment_id}/dewars", response_model=List[DewarSchema])
@shipment_router.get("/shipments", response_model=List[ShipmentSchema])
async def get_all_shipments(db: Session = Depends(get_db)):
try:
shipments = get_shipments(db)
return shipments
except SQLAlchemyError as e:
logging.error(f"Database error occurred: {e}")
raise HTTPException(status_code=500, detail="Internal server error")
@shipment_router.get("/{shipment_id}/dewars", response_model=List[Dewar])
async def get_dewars_by_shipment_id(shipment_id: int, db: Session = Depends(get_db)):
shipment = db.query(ShipmentModel).filter(ShipmentModel.id == shipment_id).first()
if not shipment: