Handler.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Application.Abstractions.Data;
  2. using Application.Abstractions.Messaging;
  3. using Domain.Entities.Members;
  4. using Microsoft.EntityFrameworkCore;
  5. namespace Application.Features.Api.TrackRecord.GetTrackRecord;
  6. internal sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response>
  7. {
  8. public async Task<Response> Handle(Query request, CancellationToken ct)
  9. {
  10. var sid = request.SID?.Trim() ?? string.Empty;
  11. var row = await db.MemberTrackRecord.AsNoTracking()
  12. .Where(c => c.Member.SID == sid)
  13. .Select(c => new
  14. {
  15. c.Tier,
  16. c.HitRate,
  17. c.Predictions,
  18. c.Hits,
  19. c.Misses,
  20. c.Voids,
  21. c.CurrentStreak,
  22. c.BestStreak
  23. })
  24. .FirstOrDefaultAsync(ct);
  25. if (row is null)
  26. {
  27. return new Response { SID = sid, HasRecord = false };
  28. }
  29. return new Response
  30. {
  31. SID = sid,
  32. HasRecord = true,
  33. Tier = row.Tier.ToString(),
  34. TierCode = (byte)row.Tier,
  35. HitRate = row.HitRate,
  36. Predictions = row.Predictions,
  37. Hits = row.Hits,
  38. Misses = row.Misses,
  39. Voids = row.Voids,
  40. CurrentStreak = row.CurrentStreak,
  41. BestStreak = row.BestStreak
  42. };
  43. }
  44. }