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.
85 lines
2.7 KiB
Python
85 lines
2.7 KiB
Python
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 (ActivityMaster, ActivityMasterCreate,
|
|
ActivityMasterPagination)
|
|
from .service import create, delete, get, get_all, update
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("", response_model=StandardResponse[ActivityMasterPagination])
|
|
async def get_activities(common: CommonParameters):
|
|
"""Get all scope activity pagination."""
|
|
# return
|
|
data = await get_all(common=common)
|
|
|
|
return StandardResponse(
|
|
data=data,
|
|
message="Data retrieved successfully",
|
|
)
|
|
|
|
|
|
@router.post("", response_model=StandardResponse[ActivityMasterCreate])
|
|
async def create_activity(db_session: DbSession, activity_in: ActivityMasterCreate):
|
|
|
|
activity = await create(db_session=db_session, activty_in=activity_in)
|
|
|
|
return StandardResponse(data=activity, message="Data created successfully")
|
|
|
|
|
|
@router.get(
|
|
"/{scope_equipment_activity_id}", response_model=StandardResponse[ActivityMaster]
|
|
)
|
|
async def get_activity(db_session: DbSession, activity_id: str):
|
|
activity = await get(db_session=db_session, activity_id=activity_id)
|
|
if not activity:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="A data with this id does not exist.",
|
|
)
|
|
|
|
return StandardResponse(data=activity, message="Data retrieved successfully")
|
|
|
|
|
|
@router.put(
|
|
"/{scope_equipment_activity_id}", response_model=StandardResponse[ActivityMaster]
|
|
)
|
|
async def update_scope(
|
|
db_session: DbSession, activity_in: ActivityMasterCreate, activity_id
|
|
):
|
|
activity = await get(db_session=db_session, activity_id=activity_id)
|
|
|
|
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, activity_in=activity_in
|
|
),
|
|
message="Data updated successfully",
|
|
)
|
|
|
|
|
|
@router.delete(
|
|
"/{scope_equipment_activity_id}", response_model=StandardResponse[ActivityMaster]
|
|
)
|
|
async def delete_scope(db_session: DbSession, activity_id: str):
|
|
activity = await get(db_session=db_session, activity_id=activity_id)
|
|
|
|
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, activity_id=activity_id)
|
|
|
|
return StandardResponse(message="Data deleted successfully", data=activity)
|