You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.4 KiB
Python
119 lines
3.4 KiB
Python
from typing import List, Optional
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter, HTTPException, Query, status
|
|
|
|
from src.database.service import (CommonParameters, DbSession,
|
|
search_filter_sort_paginate)
|
|
from src.models import StandardResponse
|
|
|
|
from .schema import (OverhaulActivityCreate, OverhaulActivityPagination,
|
|
OverhaulActivityRead, OverhaulActivityUpdate)
|
|
from .service import create, delete, get, get_all, update
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get(
|
|
"/{overhaul_session}", response_model=StandardResponse[OverhaulActivityPagination]
|
|
)
|
|
async def get_scope_equipments(
|
|
common: CommonParameters,
|
|
overhaul_session: str,
|
|
assetnum: Optional[str] = Query(None),
|
|
scope_name: Optional[str] = Query(None),
|
|
):
|
|
"""Get all scope activity pagination."""
|
|
# return
|
|
data = await get_all(
|
|
common=common,
|
|
assetnum=assetnum,
|
|
scope_name=scope_name,
|
|
overhaul_session_id=overhaul_session,
|
|
)
|
|
|
|
return StandardResponse(
|
|
data=data,
|
|
message="Data retrieved successfully",
|
|
)
|
|
|
|
|
|
@router.post("/{overhaul_session}", response_model=StandardResponse[List[str]])
|
|
async def create_overhaul_equipment(
|
|
db_session: DbSession,
|
|
overhaul_activty_in: OverhaulActivityCreate,
|
|
overhaul_session: str,
|
|
):
|
|
|
|
activity = await create(
|
|
db_session=db_session,
|
|
overhaul_activty_in=overhaul_activty_in,
|
|
overhaul_session_id=overhaul_session,
|
|
)
|
|
|
|
return StandardResponse(data=activity, message="Data created successfully")
|
|
|
|
|
|
@router.get(
|
|
"/{overhaul_session}/{assetnum}",
|
|
response_model=StandardResponse[OverhaulActivityRead],
|
|
)
|
|
async def get_overhaul_equipment(
|
|
db_session: DbSession, assetnum: str, overhaul_session
|
|
):
|
|
equipment = await get(
|
|
db_session=db_session, assetnum=assetnum, overhaul_session_id=overhaul_session
|
|
)
|
|
if not equipment:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="A data with this id does not exist.",
|
|
)
|
|
|
|
return StandardResponse(data=equipment, message="Data retrieved successfully")
|
|
|
|
|
|
@router.put(
|
|
"/{overhaul_session}/{assetnum}",
|
|
response_model=StandardResponse[OverhaulActivityRead],
|
|
)
|
|
async def update_scope(
|
|
db_session: DbSession,
|
|
scope_equipment_activity_in: OverhaulActivityUpdate,
|
|
assetnum: str,
|
|
):
|
|
activity = await get(db_session=db_session, assetnum=assetnum)
|
|
|
|
if not activity:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="A data with this id does not exist.",
|
|
)
|
|
|
|
return StandardResponse(
|
|
data=await update(
|
|
db_session=db_session,
|
|
activity=activity,
|
|
scope_equipment_activity_in=scope_equipment_activity_in,
|
|
),
|
|
message="Data updated successfully",
|
|
)
|
|
|
|
|
|
@router.delete(
|
|
"/{overhaul_session}/{assetnum}",
|
|
response_model=StandardResponse[OverhaulActivityRead],
|
|
)
|
|
async def delete_scope(db_session: DbSession, assetnum: str):
|
|
activity = await get(db_session=db_session, assetnum=assetnum)
|
|
|
|
if not activity:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail=[{"msg": "A data with this id does not exist."}],
|
|
)
|
|
|
|
await delete(db_session=db_session, assetnum=assetnum)
|
|
|
|
return StandardResponse(message="Data deleted successfully", data=activity)
|