profileShare

rasmusjy / splitapp-backend-microservices

Read-only snapshot

No repository description.

main default branch 501 files Expires Sep 13, 2026, 9:06 AM
SettlementPaymentAdminService.cs 2,948 bytes
1 using SplitApp.WebApp.Application.Contracts;
2 using SplitApp.WebApp.Application.DTO;
3 using SplitApp.WebApp.Application.Mappers;
4 using SplitApp.WebApp.Application.UsersService;
5
6 namespace SplitApp.WebApp.Application.Services.Admin;
7
8 public class SettlementPaymentAdminService : ISettlementPaymentAdminService
9 {
10 private readonly IAppUnitOfWork _uow;
11 private readonly IUsersServiceClient _usersService;
12
13 public SettlementPaymentAdminService(IAppUnitOfWork uow, IUsersServiceClient usersService)
14 {
15 _uow = uow;
16 _usersService = usersService;
17 }
18
19 public async Task<List<SettlementPaymentBllDto>> GetAllAsync(string? search)
20 {
21 var payments = (await _uow.SettlementPayments.GetAllAsync()).ToList();
22 if (!string.IsNullOrEmpty(search))
23 payments = payments.Where(s =>
24 (s.FromUser?.Email != null && s.FromUser.Email.Contains(search)) ||
25 (s.ToUser?.Email != null && s.ToUser.Email.Contains(search))).ToList();
26 return SettlementPaymentBllDtoFactory.CreateList(payments.OrderByDescending(s => s.Id));
27 }
28
29 public async Task<SettlementPaymentBllDto?> GetByIdAsync(Guid id)
30 {
31 var entity = await _uow.SettlementPayments.GetByIdAsync(id);
32 return entity == null ? null : SettlementPaymentBllDtoFactory.Create(entity);
33 }
34
35 public async Task CreateAsync(SettlementPaymentBllDto entity)
36 {
37 var domainEntity = SettlementPaymentBllDtoFactory.ToEntity(entity);
38 domainEntity.Id = Guid.NewGuid();
39 _uow.SettlementPayments.Add(domainEntity);
40 await _uow.SaveChangesAsync();
41 }
42
43 public async Task UpdateAsync(SettlementPaymentBllDto entity)
44 {
45 var existing = await _uow.SettlementPayments.GetByIdAsync(entity.Id);
46 if (existing == null) return;
47 existing.SettlementPlanId = entity.SettlementPlanId;
48 existing.FromUserId = entity.FromUserId;
49 existing.ToUserId = entity.ToUserId;
50 existing.Amount = entity.Amount;
51 existing.Status = entity.Status;
52 existing.MarkedPaidAt = entity.MarkedPaidAt;
53 existing.ConfirmedAt = entity.ConfirmedAt;
54 _uow.SettlementPayments.Update(existing);
55 await _uow.SaveChangesAsync();
56 }
57
58 public async Task DeleteAsync(Guid id)
59 {
60 await _uow.SettlementPayments.RemoveAsync(id);
61 await _uow.SaveChangesAsync();
62 }
63
64 public async Task<List<SettlementPlanBllDto>> GetSettlementPlansAsync()
65 {
66 var plans = await _uow.SettlementPlans.GetAllAsync();
67 return SettlementBllDtoFactory.CreateList(plans);
68 }
69
70 public async Task<List<AppUserBllDto>> GetUsersAsync()
71 {
72 var users = await _usersService.ListUsersAsync();
73 return users.Select(u => new AppUserBllDto
74 {
75 Id = u.Id,
76 FirstName = u.FirstName,
77 LastName = u.LastName,
78 Email = u.Email,
79 }).ToList();
80 }
81 }
82