Index.cshtml.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using SharedKernel.Helpers;
  2. using Domain.Entities.Developers.ValueObject;
  3. using Application.Abstractions.Messaging;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Mvc.RazorPages;
  6. using System.ComponentModel;
  7. using System.ComponentModel.DataAnnotations;
  8. namespace Admin.Pages.Developers.Purchases;
  9. public class IndexModel(IMediator mediator) : PageModel
  10. {
  11. [BindProperty(SupportsGet = true)]
  12. public QueryParams Query { get; set; } = new();
  13. public sealed class QueryParams
  14. {
  15. public ApiPurchaseStatus? Status { get; set; }
  16. public string? Keyword { get; set; }
  17. [DataType(DataType.Date)]
  18. public DateTime? From { get; set; }
  19. [DataType(DataType.Date)]
  20. public DateTime? To { get; set; }
  21. [DisplayName("금액 불일치만")]
  22. public bool OnlyMismatch { get; set; }
  23. [Range(1, int.MaxValue)]
  24. [DisplayName("페이지 번호")]
  25. public int PageNum { get; set; } = 1;
  26. [Range(1, 100)]
  27. [DisplayName("페이지 목록 수")]
  28. public ushort PerPage { get; set; } = 20;
  29. }
  30. public int Total { get; set; }
  31. public Application.Features.Admin.Developers.Purchases.Search.Response.SummaryData? Summary { get; set; }
  32. public List<Application.Features.Admin.Developers.Purchases.Search.Response.Row> List { get; set; } = [];
  33. public Pagination? Pagination { get; set; }
  34. public async Task OnGetAsync(CancellationToken ct)
  35. {
  36. if (!ModelState.IsValid)
  37. {
  38. return;
  39. }
  40. var result = await mediator.Send(new Application.Features.Admin.Developers.Purchases.Search.Query(
  41. Query.Status, Query.Keyword, Query.From, Query.To, Query.OnlyMismatch, Query.PageNum, Query.PerPage
  42. ), ct);
  43. Total = result.Total;
  44. Summary = result.Summary;
  45. List = [..result.List];
  46. Pagination = new Pagination(result.Total, Query.PageNum, Query.PerPage);
  47. }
  48. }