profileShare

rasmusjy / splitapp-backend-microservices

Read-only snapshot

No repository description.

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