WishlistBllDtoFactory.cs
2,034 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.Mappers; |
| 9 | |
| 10 | public static class WishlistBllDtoFactory |
| 11 | { |
| 12 | public static TripWishlistItemBllDto Create(TripWishlistItem entity) => new() |
| 13 | { |
| 14 | Id = entity.Id, |
| 15 | CreatedAt = entity.CreatedAt, |
| 16 | UpdatedAt = entity.UpdatedAt, |
| 17 | TripId = entity.TripId, |
| 18 | Trip = entity.Trip != null ? TripBllDtoFactory.Create(entity.Trip) : null, |
| 19 | AddedByUserId = entity.AddedByUserId, |
| 20 | AddedByUser = AppUserBllDtoFactory.Create(entity.AddedByUser), |
| 21 | Title = entity.Title, |
| 22 | Description = entity.Description, |
| 23 | Category = entity.Category, |
| 24 | Priority = entity.Priority, |
| 25 | EstimatedCost = entity.EstimatedCost, |
| 26 | Url = entity.Url, |
| 27 | Location = entity.Location, |
| 28 | IsCompleted = entity.IsCompleted, |
| 29 | CompletedAt = entity.CompletedAt, |
| 30 | DisplayOrder = entity.DisplayOrder, |
| 31 | VoteCount = entity.Votes?.Count(v => v.IsInterested) ?? 0, |
| 32 | VoterUserIds = entity.Votes?.Where(v => v.IsInterested).Select(v => v.UserId).ToList() ?? new List<Guid>() |
| 33 | }; |
| 34 | |
| 35 | public static List<TripWishlistItemBllDto> CreateList(IEnumerable<TripWishlistItem> entities) |
| 36 | => entities.Select(Create).ToList(); |
| 37 | |
| 38 | public static TripWishlistItem ToEntity(TripWishlistItemBllDto dto) => new() |
| 39 | { |
| 40 | Id = dto.Id, |
| 41 | TripId = dto.TripId, |
| 42 | AddedByUserId = dto.AddedByUserId, |
| 43 | Title = dto.Title, |
| 44 | Description = dto.Description, |
| 45 | Category = dto.Category, |
| 46 | Priority = dto.Priority, |
| 47 | EstimatedCost = dto.EstimatedCost, |
| 48 | Url = dto.Url, |
| 49 | Location = dto.Location, |
| 50 | IsCompleted = dto.IsCompleted, |
| 51 | CompletedAt = dto.CompletedAt, |
| 52 | DisplayOrder = dto.DisplayOrder |
| 53 | }; |
| 54 | } |
| 55 | |