Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TickAPI/TickAPI.Tests/Events/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public static GetEventResponseDto CreateSampleEventResponseDto(string name)
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc),
new DateTime(1970, 1, 2, 0, 0, 0, DateTimeKind.Utc),
18,
100,
300,
new GetEventResponsePriceInfoDto(100, "PLN"),
new GetEventResponsePriceInfoDto(300, "PLN"),
[new GetEventResponseCategoryDto("Test")],
EventStatus.TicketsAvailable,
new GetEventResponseAddressDto("United States", "New York", "10001", "Main St", 123, null)
Expand Down
4 changes: 2 additions & 2 deletions TickAPI/TickAPI/Events/DTOs/Response/GetEventResponseDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public record GetEventResponseDto(
DateTime StartDate,
DateTime EndDate,
uint? MinimumAge,
decimal MinimumPrice,
decimal MaximumPrice,
GetEventResponsePriceInfoDto MinimumPrice,
GetEventResponsePriceInfoDto MaximumPrice,
List<GetEventResponseCategoryDto> Categories,
EventStatus Status,
GetEventResponseAddressDto Address
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TickAPI.Events.DTOs.Response;

public record GetEventResponsePriceInfoDto(
decimal Price,
string Currency
);
8 changes: 6 additions & 2 deletions TickAPI/TickAPI/Events/Services/EventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ private static GetEventResponseDto MapEventToGetEventResponseDto(Event ev)
var categories = ev.Categories.Count > 0 ? ev.Categories.Select((c) => new GetEventResponseCategoryDto(c.Name)).ToList() : new List<GetEventResponseCategoryDto>();
var address = new GetEventResponseAddressDto(ev.Address.Country, ev.Address.City, ev.Address.PostalCode, ev.Address.Street, ev.Address.HouseNumber, ev.Address.FlatNumber);

var minimumPrice = ev.TicketTypes.Min(t => t.Price);
var maximumPrice = ev.TicketTypes.Max(t => t.Price);
// Here we assume that there is at least one ticket type in each event
var ttMinimumPrice = ev.TicketTypes.MinBy(t => t.Price)!;
var ttMaximumPrice = ev.TicketTypes.MaxBy(t => t.Price)!;

var minimumPrice = new GetEventResponsePriceInfoDto(ttMinimumPrice.Price, ttMinimumPrice.Currency);
var maximumPrice = new GetEventResponsePriceInfoDto(ttMaximumPrice.Price, ttMaximumPrice.Currency);

return new GetEventResponseDto(ev.Id, ev.Name, ev.Description, ev.StartDate, ev.EndDate, ev.MinimumAge,
minimumPrice, maximumPrice, categories, ev.EventStatus, address);
Expand Down
Loading