profileShare

rasmusjy / splitapp-backend-microservices

Read-only snapshot

No repository description.

main default branch 501 files Expires Sep 13, 2026, 9:06 AM
PollBllDtoFactory.cs 2,220 bytes
1 using SplitApp.Modules.Trips.Domain.Entities;
2 using SplitApp.WebApp.Application.DTO;
3
4 namespace SplitApp.WebApp.Application.Mappers;
5
6 public static class PollBllDtoFactory
7 {
8 public static TripPollBllDto Create(TripPoll entity, bool includeOptions = false) => new()
9 {
10 Id = entity.Id,
11 CreatedAt = entity.CreatedAt,
12 UpdatedAt = entity.UpdatedAt,
13 TripId = entity.TripId,
14 Trip = entity.Trip != null ? TripBllDtoFactory.Create(entity.Trip) : null,
15 CreatedByUserId = entity.CreatedByUserId,
16 CreatedByUser = AppUserBllDtoFactory.Create(entity.CreatedByUser),
17 Question = entity.Question,
18 AllowMultipleVotes = entity.AllowMultipleVotes,
19 IsAnonymous = entity.IsAnonymous,
20 ClosedAt = entity.ClosedAt,
21 Options = includeOptions && entity.Options != null
22 ? entity.Options.OrderBy(o => o.DisplayOrder).Select(PollOptionBllDtoFactory.Create).ToList()
23 : null
24 };
25
26 public static List<TripPollBllDto> CreateList(IEnumerable<TripPoll> entities, bool includeOptions = false)
27 => entities.Select(p => Create(p, includeOptions)).ToList();
28
29 public static TripPoll ToEntity(TripPollBllDto dto) => new()
30 {
31 Id = dto.Id,
32 TripId = dto.TripId,
33 CreatedByUserId = dto.CreatedByUserId,
34 Question = dto.Question,
35 AllowMultipleVotes = dto.AllowMultipleVotes,
36 IsAnonymous = dto.IsAnonymous,
37 ClosedAt = dto.ClosedAt
38 };
39 }
40
41 public static class PollOptionBllDtoFactory
42 {
43 public static TripPollOptionBllDto Create(TripPollOption entity) => new()
44 {
45 Id = entity.Id,
46 CreatedAt = entity.CreatedAt,
47 UpdatedAt = entity.UpdatedAt,
48 PollId = entity.PollId,
49 Text = entity.Text,
50 DisplayOrder = entity.DisplayOrder,
51 VoteCount = entity.Votes?.Count ?? 0,
52 VoterUserIds = entity.Votes?.Select(v => v.UserId).ToList() ?? new List<Guid>(),
53 Voters = new List<AppUserBllDto>()
54 };
55
56 public static TripPollOption ToEntity(TripPollOptionBllDto dto) => new()
57 {
58 Id = dto.Id,
59 PollId = dto.PollId,
60 Text = dto.Text,
61 DisplayOrder = dto.DisplayOrder
62 };
63 }
64