Handler.cs 776 B

12345678910111213141516171819202122232425
  1. using Application.Abstractions.Messaging;
  2. using Application.Abstractions.Data;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Application.Features.Admin.Crypto.TickerConfig.Get;
  5. public sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response>
  6. {
  7. public async Task<Response> Handle(Query request, CancellationToken ct)
  8. {
  9. var config = await db.Config.AsNoTracking().OrderByDescending(x => x.ID).FirstOrDefaultAsync(ct);
  10. if (config is null)
  11. {
  12. return new Response(5, 5.0m, -5.0m, 10);
  13. }
  14. return new Response(
  15. config.Crypto.TickerRefreshSeconds,
  16. config.Crypto.SurgeThreshold,
  17. config.Crypto.PlungeThreshold,
  18. config.Crypto.MainPageCoinCount
  19. );
  20. }
  21. }