profileShare

rasmusjy / splitapp-backend-modular-monolith

Read-only snapshot

No repository description.

main default branch 418 files Expires Sep 13, 2026, 9:06 AM
ISettlementService.cs 1,922 bytes
1 using SplitApp.WebApp.Application.DTO;
2 using SplitApp.Modules.Trips.Domain.Entities;
3 using SplitApp.Modules.Trips.Domain.Enums;
4 using SplitApp.Modules.Expenses.Domain.Entities;
5 using SplitApp.Modules.Expenses.Domain.Enums;
6 using SplitApp.Modules.Users.Domain.Entities;
7
8 namespace SplitApp.WebApp.Application.Services;
9
10 public interface ISettlementService
11 {
12 Task<List<BalanceEntry>> CalculateBalancesAsync(Guid tripId);
13 Task<SettlementPlanBllDto?> CalculateSettlementAsync(Guid tripId, Guid userId);
14 List<PreviewPayment> PreviewSettlement(List<BalanceEntry> balances);
15 Task MarkPaidAsync(Guid paymentId, Guid userId);
16 Task ConfirmPaymentAsync(Guid paymentId, Guid userId);
17
18 // IDOR-protected queries
19 Task<List<BalanceEntry>> GetBalancesAsync(Guid tripId, Guid userId); // participant-only, empty if forbidden
20 Task<SettlementPlanBllDto?> GetLatestPlanAsync(Guid tripId, Guid userId); // participant-only
21 Task<SettlementPlanBllDto?> GetLatestPlanRawAsync(Guid tripId); // no IDOR (used internally after IDOR checked)
22
23 // Payment lookups
24 Task<SettlementPaymentBllDto?> GetPaymentByIdAsync(Guid paymentId);
25 Task<SettlementPlanBllDto?> GetPlanByIdAsync(Guid planId);
26
27 // Guarded mark/confirm that also validate trip participation
28 Task<(bool success, string? errorCode)> MarkPaidGuardedAsync(Guid paymentId, Guid userId);
29 Task<(bool success, string? errorCode)> ConfirmPaymentGuardedAsync(Guid paymentId, Guid userId);
30 }
31
32 public class BalanceEntry
33 {
34 public Guid UserId { get; set; }
35 public string UserName { get; set; } = default!;
36 public decimal TotalPaid { get; set; }
37 public decimal TotalOwed { get; set; }
38 public decimal NetBalance => TotalPaid - TotalOwed;
39 }
40
41 public class PreviewPayment
42 {
43 public string FromUserName { get; set; } = default!;
44 public string ToUserName { get; set; } = default!;
45 public decimal Amount { get; set; }
46 }
47