|
|
|
@ -1,4 +1,5 @@
|
|
|
|
from typing import Optional
|
|
|
|
from typing import List, Optional
|
|
|
|
|
|
|
|
from uuid import UUID
|
|
|
|
|
|
|
|
|
|
|
|
from fastapi import APIRouter, HTTPException, Query, status
|
|
|
|
from fastapi import APIRouter, HTTPException, Query, status
|
|
|
|
|
|
|
|
|
|
|
|
@ -11,10 +12,12 @@ from .schema import (
|
|
|
|
PlantFSTransactionDataCreate,
|
|
|
|
PlantFSTransactionDataCreate,
|
|
|
|
PlantFSTransactionDataImport,
|
|
|
|
PlantFSTransactionDataImport,
|
|
|
|
PlantFSTransactionDataPagination,
|
|
|
|
PlantFSTransactionDataPagination,
|
|
|
|
|
|
|
|
|
|
|
|
PlantFSTransactionDataRead,
|
|
|
|
PlantFSTransactionDataRead,
|
|
|
|
PlantFSTransactionDataUpdate,
|
|
|
|
PlantFSTransactionDataUpdate,
|
|
|
|
|
|
|
|
PlantFSChartData,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
from .service import create, delete, get, get_all, update, update_fs_charts_from_matrix
|
|
|
|
from .service import create, delete, get, get_all, update, update_fs_charts_from_matrix, get_charts
|
|
|
|
|
|
|
|
|
|
|
|
from typing import List
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
|
|
|
|
@ -43,15 +46,57 @@ async def list_fs_transactions(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post(
|
|
|
|
|
|
|
|
"/import/charts",
|
|
|
|
|
|
|
|
response_model=StandardResponse[List[PlantFSTransactionDataRead]],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
async def import_fs_charts(
|
|
|
|
|
|
|
|
db_session: DbSession,
|
|
|
|
|
|
|
|
payload: PlantFSTransactionDataImport,
|
|
|
|
|
|
|
|
current_user: CurrentUser,
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
updated, missing = await update_fs_charts_from_matrix(
|
|
|
|
|
|
|
|
db_session=db_session,
|
|
|
|
|
|
|
|
payload=payload,
|
|
|
|
|
|
|
|
updated_by=getattr(current_user, "user_id", None) if current_user else None,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
msg = "Data imported successfully."
|
|
|
|
|
|
|
|
if missing:
|
|
|
|
|
|
|
|
msg += f" Note: Years {missing} were not found."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return StandardResponse(data=updated, message=msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/charts", response_model=StandardResponse[PlantFSChartData])
|
|
|
|
|
|
|
|
async def get_chart_data(db_session: DbSession, common: CommonParameters):
|
|
|
|
|
|
|
|
chart_data, bep_year, bep_total_lcc = await get_charts(
|
|
|
|
|
|
|
|
db_session=db_session, common=common
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if not chart_data:
|
|
|
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
|
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
|
|
|
|
|
|
detail="No chart data found.",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return StandardResponse(
|
|
|
|
|
|
|
|
data={
|
|
|
|
|
|
|
|
"items": chart_data,
|
|
|
|
|
|
|
|
"bep_year": bep_year,
|
|
|
|
|
|
|
|
"bep_total_lcc": bep_total_lcc,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
message="Data retrieved successfully",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get(
|
|
|
|
@router.get(
|
|
|
|
"/{fs_transaction_id}",
|
|
|
|
"/{fs_transaction_id}",
|
|
|
|
response_model=StandardResponse[PlantFSTransactionDataRead],
|
|
|
|
response_model=StandardResponse[PlantFSTransactionDataRead],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
async def retrieve_fs_transaction(
|
|
|
|
async def retrieve_fs_transaction(
|
|
|
|
db_session: DbSession,
|
|
|
|
db_session: DbSession,
|
|
|
|
fs_transaction_id: str,
|
|
|
|
fs_transaction_id: UUID,
|
|
|
|
):
|
|
|
|
):
|
|
|
|
record = await get(db_session=db_session, fs_transaction_id=fs_transaction_id)
|
|
|
|
record = await get(db_session=db_session, fs_transaction_id=str(fs_transaction_id))
|
|
|
|
if not record:
|
|
|
|
if not record:
|
|
|
|
raise HTTPException(
|
|
|
|
raise HTTPException(
|
|
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
|
|
@ -82,11 +127,11 @@ async def create_fs_transaction(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
async def update_fs_transaction(
|
|
|
|
async def update_fs_transaction(
|
|
|
|
db_session: DbSession,
|
|
|
|
db_session: DbSession,
|
|
|
|
fs_transaction_id: str,
|
|
|
|
fs_transaction_id: UUID,
|
|
|
|
payload: PlantFSTransactionDataUpdate,
|
|
|
|
payload: PlantFSTransactionDataUpdate,
|
|
|
|
current_user: CurrentUser,
|
|
|
|
current_user: CurrentUser,
|
|
|
|
):
|
|
|
|
):
|
|
|
|
record = await get(db_session=db_session, fs_transaction_id=fs_transaction_id)
|
|
|
|
record = await get(db_session=db_session, fs_transaction_id=str(fs_transaction_id))
|
|
|
|
if not record:
|
|
|
|
if not record:
|
|
|
|
raise HTTPException(
|
|
|
|
raise HTTPException(
|
|
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
|
|
@ -109,39 +154,20 @@ async def update_fs_transaction(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
async def delete_fs_transaction(
|
|
|
|
async def delete_fs_transaction(
|
|
|
|
db_session: DbSession,
|
|
|
|
db_session: DbSession,
|
|
|
|
fs_transaction_id: str,
|
|
|
|
fs_transaction_id: UUID,
|
|
|
|
):
|
|
|
|
):
|
|
|
|
record = await get(db_session=db_session, fs_transaction_id=fs_transaction_id)
|
|
|
|
record = await get(db_session=db_session, fs_transaction_id=str(fs_transaction_id))
|
|
|
|
if not record:
|
|
|
|
if not record:
|
|
|
|
raise HTTPException(
|
|
|
|
raise HTTPException(
|
|
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
|
|
detail=[{"msg": "A data with this id does not exist."}],
|
|
|
|
detail=[{"msg": "A data with this id does not exist."}],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
await delete(db_session=db_session, fs_transaction_id=fs_transaction_id)
|
|
|
|
await delete(db_session=db_session, fs_transaction_id=str(fs_transaction_id))
|
|
|
|
|
|
|
|
|
|
|
|
return StandardResponse(data=record, message="Data deleted successfully")
|
|
|
|
return StandardResponse(data=record, message="Data deleted successfully")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post(
|
|
|
|
|
|
|
|
"/import/charts",
|
|
|
|
|
|
|
|
response_model=StandardResponse[List[PlantFSTransactionDataRead]],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
async def import_fs_charts(
|
|
|
|
|
|
|
|
db_session: DbSession,
|
|
|
|
|
|
|
|
payload: PlantFSTransactionDataImport,
|
|
|
|
|
|
|
|
current_user: CurrentUser,
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
updated, missing = await update_fs_charts_from_matrix(
|
|
|
|
|
|
|
|
db_session=db_session,
|
|
|
|
|
|
|
|
payload=payload,
|
|
|
|
|
|
|
|
updated_by=getattr(current_user, "user_id", None) if current_user else None,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
msg = "Data imported successfully."
|
|
|
|
|
|
|
|
if missing:
|
|
|
|
|
|
|
|
msg += f" Note: Years {missing} were not found."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return StandardResponse(data=updated, message=msg)
|
|
|
|
|
|
|
|
|