|
|
|
@ -3,19 +3,36 @@
|
|
|
|
from typing import Annotated, List, Optional
|
|
|
|
from typing import Annotated, List, Optional
|
|
|
|
|
|
|
|
|
|
|
|
from src.models import StandardResponse
|
|
|
|
from src.models import StandardResponse
|
|
|
|
from .service import get_all_master
|
|
|
|
from .service import get_all_master, get_master
|
|
|
|
from fastapi import APIRouter, Query
|
|
|
|
from fastapi import APIRouter, HTTPException, Query, status
|
|
|
|
from .schema import EquipmentMasterTree
|
|
|
|
from .schema import EquipmentMasterPaginated, EquipmentMasterRead
|
|
|
|
|
|
|
|
from src.database.service import search_filter_sort_paginate, CommonParameters
|
|
|
|
from src.database.core import DbSession
|
|
|
|
from src.database.core import DbSession
|
|
|
|
router = APIRouter()
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("", response_model=StandardResponse[List[EquipmentMasterTree]])
|
|
|
|
@router.get("", response_model=StandardResponse[EquipmentMasterPaginated])
|
|
|
|
async def get_all_equipment_master_tree(
|
|
|
|
async def get_all_equipment_master_tree(
|
|
|
|
db_session: DbSession,
|
|
|
|
db_session: DbSession,
|
|
|
|
|
|
|
|
common: CommonParameters,
|
|
|
|
parent_id: Annotated[Optional[str], Query(description="Parent ID")] = None,
|
|
|
|
parent_id: Annotated[Optional[str], Query(description="Parent ID")] = None,
|
|
|
|
):
|
|
|
|
|
|
|
|
equipment_masters = await get_all_master(parent_id=parent_id, db_session=db_session)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
equipment_masters = await get_all_master(parent_id=parent_id, db_session=db_session, common=common)
|
|
|
|
|
|
|
|
|
|
|
|
return StandardResponse(data=equipment_masters, message="Data retrieved successfully")
|
|
|
|
return StandardResponse(data=equipment_masters, message="Data retrieved successfully")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/{equipment_master_id}", response_model=StandardResponse[EquipmentMasterRead])
|
|
|
|
|
|
|
|
async def get_equipment_master_tree(
|
|
|
|
|
|
|
|
db_session: DbSession, equipment_master_id: str
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
equipment_master = await get_master(db_session=db_session, equipment_master_id=equipment_master_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not equipment_master:
|
|
|
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
|
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
|
|
|
|
|
|
detail="A data with this id does not exist.",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return StandardResponse(data=equipment_master, message="Data retrieved successfully")
|
|
|
|
|