profileShare

rasmusjy / splitapp-backend-modular-monolith

Read-only snapshot

No repository description.

main default branch 418 files Expires Sep 13, 2026, 9:06 AM
SettlementBllDtoFactory.cs 2,742 bytes
1 using SplitApp.Modules.Expenses.Domain.Entities;
2 using SplitApp.Modules.Trips.Domain.Entities;
3 using SplitApp.WebApp.Application.DTO;
4
5 namespace SplitApp.WebApp.Application.Mappers;
6
7 public static class SettlementBllDtoFactory
8 {
9 public static SettlementPlanBllDto Create(SettlementPlan entity, bool includePayments = false) => new()
10 {
11 Id = entity.Id,
12 CreatedAt = entity.CreatedAt,
13 UpdatedAt = entity.UpdatedAt,
14 TripId = entity.TripId,
15 // entity.Trip is `object?` (Expenses module avoids direct ref to Trip type) — cast back here.
16 Trip = entity.Trip is Trip trip ? TripBllDtoFactory.Create(trip) : null,
17 CreatedByUserId = entity.CreatedByUserId,
18 CreatedByUser = AppUserBllDtoFactory.Create(entity.CreatedByUser),
19 TotalAmount = entity.TotalAmount,
20 Status = entity.Status,
21 CompletedAt = entity.CompletedAt,
22 Payments = includePayments && entity.Payments != null
23 ? entity.Payments.Select(SettlementPaymentBllDtoFactory.Create).ToList()
24 : null
25 };
26
27 public static List<SettlementPlanBllDto> CreateList(IEnumerable<SettlementPlan> entities, bool includePayments = false)
28 => entities.Select(p => Create(p, includePayments)).ToList();
29
30 public static SettlementPlan ToEntity(SettlementPlanBllDto dto) => new()
31 {
32 Id = dto.Id,
33 TripId = dto.TripId,
34 CreatedByUserId = dto.CreatedByUserId,
35 TotalAmount = dto.TotalAmount,
36 Status = dto.Status,
37 CompletedAt = dto.CompletedAt
38 };
39 }
40
41 public static class SettlementPaymentBllDtoFactory
42 {
43 public static SettlementPaymentBllDto Create(SettlementPayment entity) => new()
44 {
45 Id = entity.Id,
46 CreatedAt = entity.CreatedAt,
47 UpdatedAt = entity.UpdatedAt,
48 SettlementPlanId = entity.SettlementPlanId,
49 FromUserId = entity.FromUserId,
50 FromUser = AppUserBllDtoFactory.Create(entity.FromUser),
51 ToUserId = entity.ToUserId,
52 ToUser = AppUserBllDtoFactory.Create(entity.ToUser),
53 Amount = entity.Amount,
54 Status = entity.Status,
55 MarkedPaidAt = entity.MarkedPaidAt,
56 ConfirmedAt = entity.ConfirmedAt
57 };
58
59 public static List<SettlementPaymentBllDto> CreateList(IEnumerable<SettlementPayment> entities)
60 => entities.Select(Create).ToList();
61
62 public static SettlementPayment ToEntity(SettlementPaymentBllDto dto) => new()
63 {
64 Id = dto.Id,
65 SettlementPlanId = dto.SettlementPlanId,
66 FromUserId = dto.FromUserId,
67 ToUserId = dto.ToUserId,
68 Amount = dto.Amount,
69 Status = dto.Status,
70 MarkedPaidAt = dto.MarkedPaidAt,
71 ConfirmedAt = dto.ConfirmedAt
72 };
73 }
74