From 62a653accbd1e6902d56e111b0fab6fdafef2f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20=C5=A0kr=C3=A1=C5=A1ek?= Date: Tue, 14 May 2024 15:47:12 +0200 Subject: [PATCH] Inlcude Initiator Reply In Event Response (#54) * include initiator event reply in event response --- .../GetEvents/GetEvetnsQueryHandlers.cs | 46 +++++++++++++++++-- .../Events/EventSlimResponse.cs | 1 + 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/TeamUp.Application/Events/GetEvents/GetEvetnsQueryHandlers.cs b/src/TeamUp.Application/Events/GetEvents/GetEvetnsQueryHandlers.cs index 22247eb..450485f 100644 --- a/src/TeamUp.Application/Events/GetEvents/GetEvetnsQueryHandlers.cs +++ b/src/TeamUp.Application/Events/GetEvents/GetEvetnsQueryHandlers.cs @@ -22,9 +22,24 @@ public async Task>> Handle(GetEventsQuery query, { var from = query.FromUtc ?? _dateTimeProvider.UtcNow; var team = await _appQueryContext.Teams + .Where(team => team.Id == query.TeamId) .Select(team => new { team.Id, + team.EventTypes, + Initiator = team.Members + .Where(member => member.UserId == query.InitiatorId) + .Select(member => new + { + member.Id, + member.Nickname, + }) + .FirstOrDefault() + }) + .Select(team => new + { + team.Id, + team.Initiator, Events = _appQueryContext.Events .AsSplitQuery() .Where(e => e.TeamId == team.Id && e.ToUtc > from) @@ -38,6 +53,17 @@ public async Task>> Handle(GetEventsQuery query, Status = e.Status, MeetTime = e.MeetTime, ReplyClosingTimeBeforeMeetTime = e.ReplyClosingTimeBeforeMeetTime, + InitiatorResponse = e.EventResponses + .Where(er => er.TeamMemberId == team.Initiator!.Id) + .Select(er => new EventResponseResponse + { + TeamMemberId = team.Initiator!.Id, + Message = er.Message, + TeamMemberNickname = team.Initiator.Nickname, + TimeStampUtc = er.TimeStampUtc, + Type = er.ReplyType, + }) + .FirstOrDefault(), ReplyCount = e.EventResponses .GroupBy(er => er.ReplyType) .Select(x => new ReplyCountResponse @@ -50,12 +76,26 @@ public async Task>> Handle(GetEventsQuery query, }) .OrderBy(e => e.FromUtc) .ToList(), - Initiator = team.Members - .Select(member => member.UserId) - .FirstOrDefault(id => id == query.InitiatorId) }) .FirstOrDefaultAsync(team => team.Id == query.TeamId, ct); + /* + var team2 = await _appQueryContext.Teams + .Where(team => team.Id == query.TeamId) + .Select(team => new + { + Initiator = team.Members + .Where(member => member.UserId == query.InitiatorId) + .Select(member => new + { + member.Id, + member.Nickname, + }) + .FirstOrDefault() + }) + .FirstOrDefaultAsync(ct); + */ + return team .EnsureNotNull(TeamErrors.TeamNotFound) .EnsureNotNull(team => team.Initiator, TeamErrors.NotMemberOfTeam) diff --git a/src/TeamUp.Contracts/Events/EventSlimResponse.cs b/src/TeamUp.Contracts/Events/EventSlimResponse.cs index 5053b00..00e39e8 100644 --- a/src/TeamUp.Contracts/Events/EventSlimResponse.cs +++ b/src/TeamUp.Contracts/Events/EventSlimResponse.cs @@ -10,5 +10,6 @@ public sealed class EventSlimResponse public required EventStatus Status { get; init; } public required TimeSpan MeetTime { get; init; } public required TimeSpan ReplyClosingTimeBeforeMeetTime { get; init; } + public required EventResponseResponse? InitiatorResponse { get; init; } public required List ReplyCount { get; init; } }