feat: add deposit edit and delete for pending deposits
Add PUT /api/v1/dca/deposits/{id} endpoint to update amount, currency,
and notes on pending deposits. Add DELETE endpoint to remove deposits
not yet inserted into the machine. Both endpoints reject confirmed
deposits. Frontend now shows edit/delete buttons only for pending rows.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6eb076d5f6
commit
28241e70c3
5 changed files with 121 additions and 3 deletions
53
views_api.py
53
views_api.py
|
|
@ -19,7 +19,9 @@ from .crud import (
|
|||
create_deposit,
|
||||
get_all_deposits,
|
||||
get_deposit,
|
||||
update_deposit,
|
||||
update_deposit_status,
|
||||
delete_deposit,
|
||||
get_client_balance_summary,
|
||||
# Lamassu config CRUD operations
|
||||
create_lamassu_config,
|
||||
|
|
@ -39,6 +41,7 @@ from .models import (
|
|||
UpdateDcaClientData,
|
||||
CreateDepositData,
|
||||
DcaDeposit,
|
||||
UpdateDepositData,
|
||||
UpdateDepositStatusData,
|
||||
ClientBalanceSummary,
|
||||
CreateLamassuConfigData,
|
||||
|
|
@ -161,6 +164,56 @@ async def api_update_deposit_status(
|
|||
return updated_deposit
|
||||
|
||||
|
||||
@satmachineadmin_api_router.put("/api/v1/dca/deposits/{deposit_id}")
|
||||
async def api_update_deposit(
|
||||
deposit_id: str,
|
||||
data: UpdateDepositData,
|
||||
user: User = Depends(check_super_user),
|
||||
) -> DcaDeposit:
|
||||
"""Update deposit fields (amount, currency, notes). Only pending deposits can be edited."""
|
||||
deposit = await get_deposit(deposit_id)
|
||||
if not deposit:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Deposit not found."
|
||||
)
|
||||
|
||||
if deposit.status != "pending":
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST,
|
||||
detail="Only pending deposits can be edited.",
|
||||
)
|
||||
|
||||
updated_deposit = await update_deposit(deposit_id, data)
|
||||
if not updated_deposit:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to update deposit.",
|
||||
)
|
||||
return updated_deposit
|
||||
|
||||
|
||||
@satmachineadmin_api_router.delete("/api/v1/dca/deposits/{deposit_id}")
|
||||
async def api_delete_deposit(
|
||||
deposit_id: str,
|
||||
user: User = Depends(check_super_user),
|
||||
):
|
||||
"""Delete a deposit. Only pending deposits (not yet inserted into the machine) can be deleted."""
|
||||
deposit = await get_deposit(deposit_id)
|
||||
if not deposit:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Deposit not found."
|
||||
)
|
||||
|
||||
if deposit.status != "pending":
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST,
|
||||
detail="Only pending deposits can be deleted. Confirmed deposits have already been inserted into the machine.",
|
||||
)
|
||||
|
||||
await delete_deposit(deposit_id)
|
||||
return {"message": "Deposit deleted successfully"}
|
||||
|
||||
|
||||
# Transaction Polling Endpoints
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue