Skip to content

Commit

Permalink
Inlcude Initiator Reply In Event Response (#54)
Browse files Browse the repository at this point in the history
* include initiator event reply in event response
  • Loading branch information
skrasekmichael authored May 14, 2024
1 parent 16ee0da commit 62a653a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
46 changes: 43 additions & 3 deletions src/TeamUp.Application/Events/GetEvents/GetEvetnsQueryHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,24 @@ public async Task<Result<List<EventSlimResponse>>> 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)
Expand All @@ -38,6 +53,17 @@ public async Task<Result<List<EventSlimResponse>>> 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
Expand All @@ -50,12 +76,26 @@ public async Task<Result<List<EventSlimResponse>>> 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)
Expand Down
1 change: 1 addition & 0 deletions src/TeamUp.Contracts/Events/EventSlimResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReplyCountResponse> ReplyCount { get; init; }
}

0 comments on commit 62a653a

Please sign in to comment.