summaryrefslogtreecommitdiff
path: root/src/FundLab.Domain
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-21 11:44:07 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-21 11:44:07 +0800
commit205e2a592bf781f08fe23f3577cdfe74ff9a076a (patch)
tree05aad6f87ca8f6c78fbc2d4c4d0d89356439936a /src/FundLab.Domain
parentb8811922f4e167d50efb8817da35a12d8a9d653b (diff)
downloadfund-lab-205e2a592bf781f08fe23f3577cdfe74ff9a076a.tar.gz
Add additional capital deposit flow (3d-4)
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.
Diffstat (limited to 'src/FundLab.Domain')
-rw-r--r--src/FundLab.Domain/Capital.fs27
-rw-r--r--src/FundLab.Domain/FundLab.Domain.fsproj1
2 files changed, 28 insertions, 0 deletions
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<unit, string> =
+ 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<decimal, string> =
+ 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 @@
<Compile Include="Domain.fs" />
<Compile Include="Ledger.fs" />
<Compile Include="Redemption.fs" />
+ <Compile Include="Capital.fs" />
<Compile Include="Performance.fs" />
</ItemGroup>
</Project>