From 205e2a592bf781f08fe23f3577cdfe74ff9a076a Mon Sep 17 00:00:00 2001 From: "Somhairle H. Marisol" Date: Mon, 21 Sep 2026 11:44:07 +0800 Subject: Add additional capital deposit flow (3d-4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deposits credit a fund's available cash directly: Domain gains CapitalPolicy (positive, two-decimal, overflow-checked amounts plus a settle function that never touches units, NAV or realized P&L). Persistence records deposits in fund_capital_deposits with a fund_capital_idempotencies table, crediting cash and the deposit row atomically under the same replay/conflict semantics as orders. The API exposes POST /funds/{id}/capital/deposit and GET /funds/{id}/capital/deposits behind the bearer token and idempotency keys. The frontend adds an '追加资金' entry on the fund cash card with in-place balance refresh, and repeats of the same amount reuse the idempotency key so double submits credit cash exactly once. Browser QA extends the J-series (J12-J18): invalid-amount rejection without POST, single credited deposit with a 32-hex key, instant balance refresh, unchanged units/cost proving no realized-income impact, and same-key replay crediting only once. --- src/FundLab.Domain/Capital.fs | 27 +++++++++++++++++++++++++++ src/FundLab.Domain/FundLab.Domain.fsproj | 1 + 2 files changed, 28 insertions(+) create mode 100644 src/FundLab.Domain/Capital.fs (limited to 'src/FundLab.Domain') diff --git a/src/FundLab.Domain/Capital.fs b/src/FundLab.Domain/Capital.fs new file mode 100644 index 0000000..b2ae697 --- /dev/null +++ b/src/FundLab.Domain/Capital.fs @@ -0,0 +1,27 @@ +namespace FundLab.Domain + +open System + +module CapitalPolicy = + let cashMaximum = 999999999999999999.99m + + let validateDeposit (amount: decimal) : Result = + if amount <= 0m then + Error "deposit amount must be positive" + elif Decimal.Round(amount, 2) <> amount then + Error "deposit amount exceeds cash precision" + elif amount > cashMaximum then + Error "deposit amount exceeds database precision" + else + Ok () + + let settle (availableCash: decimal) (amount: decimal) : Result = + match validateDeposit amount with + | Error message -> Error message + | Ok() -> + let updated = availableCash + amount + + if updated > cashMaximum then + Error "available cash exceeds database precision" + else + Ok updated diff --git a/src/FundLab.Domain/FundLab.Domain.fsproj b/src/FundLab.Domain/FundLab.Domain.fsproj index a2c5c24..0daf3ea 100644 --- a/src/FundLab.Domain/FundLab.Domain.fsproj +++ b/src/FundLab.Domain/FundLab.Domain.fsproj @@ -9,6 +9,7 @@ + -- cgit v1.2.3