Index.cshtml.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using SharedKernel.Helpers;
  2. using SharedKernel.Extensions;
  3. using Domain.Entities.Developers.ValueObject;
  4. using Application.Abstractions.Messaging;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Mvc.RazorPages;
  7. using System.ComponentModel;
  8. using System.ComponentModel.DataAnnotations;
  9. namespace Admin.Pages.Developers.Apps;
  10. public class IndexModel(IMediator mediator) : PageModel
  11. {
  12. [BindProperty(SupportsGet = true)]
  13. public QueryParams Query { get; set; } = new();
  14. public sealed class QueryParams
  15. {
  16. public ApplicationStatus? Status { get; set; }
  17. public string? Keyword { get; set; }
  18. [Range(1, int.MaxValue)]
  19. [DisplayName("페이지 번호")]
  20. public int PageNum { get; set; } = 1;
  21. [Range(1, 100)]
  22. [DisplayName("페이지 목록 수")]
  23. public ushort PerPage { get; set; } = 20;
  24. }
  25. public int Total { get; set; }
  26. public List<Application.Features.Admin.Developers.ListApps.AppRow> List { get; set; } = [];
  27. public Pagination? Pagination { get; set; }
  28. public async Task OnGetAsync(CancellationToken ct)
  29. {
  30. if (!ModelState.IsValid)
  31. {
  32. return;
  33. }
  34. var result = await mediator.Send(new Application.Features.Admin.Developers.ListApps.Query(
  35. Query.Status, Query.Keyword, Query.PageNum, Query.PerPage
  36. ), ct);
  37. Total = result.Total;
  38. List = [..result.List];
  39. Pagination = new Pagination(result.Total, Query.PageNum, Query.PerPage);
  40. }
  41. public async Task<IActionResult> OnPostApproveAsync(int[] ids, CancellationToken ct)
  42. {
  43. try
  44. {
  45. var result = await mediator.Send(new Application.Features.Admin.Developers.ApproveApp.Command(ids), ct);
  46. TempData["SuccessMessage"] = $"{result.AffectedCount}개 앱이 승인되었습니다.";
  47. }
  48. catch (Exception e)
  49. {
  50. TempData["ErrorMessages"] = e.Message;
  51. }
  52. return RedirectToPage("/Developers/Apps/Index", Query);
  53. }
  54. public async Task<IActionResult> OnPostSuspendAsync(int[] ids, CancellationToken ct)
  55. {
  56. try
  57. {
  58. var result = await mediator.Send(new Application.Features.Admin.Developers.SuspendApp.Command(ids), ct);
  59. TempData["SuccessMessage"] = $"{result.AffectedCount}개 앱이 정지되었습니다.";
  60. }
  61. catch (Exception e)
  62. {
  63. TempData["ErrorMessages"] = e.Message;
  64. }
  65. return RedirectToPage("/Developers/Apps/Index", Query);
  66. }
  67. }