Skip to content

Commit

Permalink
fixes #588
Browse files Browse the repository at this point in the history
  • Loading branch information
dlidstrom committed May 8, 2022
1 parent a1d8d3f commit 10dbff1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
18 changes: 11 additions & 7 deletions Snittlistan.Web/Commands/GetRostersFromBitsCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,21 @@ public override async Task Handle(HandlerContext<Command> context)
Roster[] toRemove = rosters.Where(x => foundMatchIds.Contains(x.BitsMatchId) == false).ToArray();
if (toRemove.Any())
{
string joined = string.Join(
",",
toRemove.Select(x => $"Id={x.Id} BitsMatchId={x.BitsMatchId}"));
Logger.InfoFormat("Rosters to remove: {joined}", joined);
List<Roster> actualRemoved = new();
foreach (Roster roster in toRemove)
{
CompositionRoot.DocumentSession.Delete(roster);
if (roster.MatchResultId is null && roster.Turn > 20)
{
CompositionRoot.DocumentSession.Delete(roster);
actualRemoved.Add(roster);
}
}

string body =
$"Rosters to remove: {joined}";
string joined = string.Join(
",",
actualRemoved.Select(x => $"Id={x.Id} BitsMatchId={x.BitsMatchId}"));
Logger.InfoFormat("Rosters to remove: {joined}", joined);
string body = $"Rosters to remove: {joined}";
SendEmail email = SendEmail.ToAdmin(
$"Removed rosters for {CompositionRoot.CurrentTenant.TeamFullName}",
body);
Expand Down
5 changes: 3 additions & 2 deletions Snittlistan.Web/Commands/VerifyMatchCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public override async Task Handle(HandlerContext<Command> context)
}
else
{
MatchResult? matchResult = CompositionRoot.EventStoreSession.Load<MatchResult>(roster.MatchResultId);
MatchResult? matchResult =
CompositionRoot.EventStoreSession.Load<MatchResult>(roster.MatchResultId);
ParseResult? parseResult = parser.Parse(bitsMatchResult, websiteConfig.ClubId);
update.Players = parseResult!.GetPlayerIds();
Dictionary<string, ResultForPlayerIndex.Result> resultsForPlayer =
Expand All @@ -82,7 +83,7 @@ public override async Task Handle(HandlerContext<Command> context)
}
}

roster.UpdateWith(context.CorrelationId, update);
_ = roster.UpdateWith(context.CorrelationId, update);
}

public record Command(
Expand Down
22 changes: 11 additions & 11 deletions Snittlistan.Web/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ public static SelectListItem[] CreatePlayerSelectList(
return playerList.ToArray();
}

public static TResult LoadEx<TResult>(this Raven.Client.IDocumentSession session, string key)
{
return session.Load<TResult>(key) ?? throw new Exception($"No entity with key '{key}' found");
}

public static User FindUserByEmail(this Raven.Client.IDocumentSession sess, string email)
{
return sess.Query<User, User_ByEmail>()
.FirstOrDefault(u => u.Email == email);
}

private static SelectListItem[] GetRosterSelectList(
Raven.Client.IDocumentSession session,
int season,
Expand Down Expand Up @@ -113,15 +124,4 @@ private static SelectListItem[] GetRosterSelectList(
.ToArray();
return rosterSelectList;
}

public static TResult LoadEx<TResult>(this Raven.Client.IDocumentSession session, string key)
{
return session.Load<TResult>(key) ?? throw new Exception($"No entity with key '{key}' found");
}

public static User FindUserByEmail(this Raven.Client.IDocumentSession sess, string email)
{
return sess.Query<User, User_ByEmail>()
.FirstOrDefault(u => u.Email == email);
}
}

0 comments on commit 10dbff1

Please sign in to comment.