Catalog.cshtml.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using SharedKernel.Extensions;
  2. using Application.Abstractions.Messaging;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.AspNetCore.Mvc.RazorPages;
  5. using System.ComponentModel;
  6. using System.ComponentModel.DataAnnotations;
  7. namespace Admin.Pages.Store.Game;
  8. /// <summary>
  9. /// 게임별 인앱 상품 SKU 정가 카탈로그 관리.
  10. /// 파트너 결제 보고(/v1/purchases) 금액 검증용 — 보고가가 정가와 다르면 불일치 flag.
  11. /// </summary>
  12. public class CatalogModel(IMediator mediator) : PageModel
  13. {
  14. public Application.Features.Admin.Store.GameCatalog.GetByGame.Response? Data { get; private set; }
  15. [BindProperty]
  16. public AddInput Add { get; set; } = new();
  17. public sealed class AddInput
  18. {
  19. public int GameID { get; set; }
  20. [DisplayName("SKU(상품 ID)")]
  21. [Required(ErrorMessage = "{0}은(는) 필수입니다.")]
  22. [StringLength(100, ErrorMessage = "{0}은(는) {1}자 이하로 입력하세요.")]
  23. public string ProductID { get; set; } = null!;
  24. [DisplayName("정가(원)")]
  25. [Range(1, int.MaxValue, ErrorMessage = "{0}은(는) 1 이상이어야 합니다.")]
  26. public int Price { get; set; }
  27. }
  28. public async Task OnGetAsync(int id, CancellationToken ct)
  29. {
  30. var result = await mediator.Send(new Application.Features.Admin.Store.GameCatalog.GetByGame.Query(id), ct);
  31. if (result.IsFailure)
  32. {
  33. TempData["ErrorMessages"] = result.Error.Description;
  34. return;
  35. }
  36. Data = result.Value;
  37. Add.GameID = id;
  38. }
  39. public async Task<IActionResult> OnPostAddAsync(CancellationToken ct)
  40. {
  41. if (!ModelState.IsValid)
  42. {
  43. TempData["ErrorMessages"] = ModelState.GetErrorMessages();
  44. return Redirect($"/Store/Game/Catalog/{Add.GameID}");
  45. }
  46. var result = await mediator.Send(new Application.Features.Admin.Store.GameCatalog.Create.Command(Add.GameID, Add.ProductID, Add.Price), ct);
  47. if (result.IsFailure)
  48. {
  49. TempData["ErrorMessages"] = result.Error.Description;
  50. }
  51. else
  52. {
  53. TempData["SuccessMessage"] = $"SKU {Add.ProductID} 가 등록되었습니다.";
  54. }
  55. return Redirect($"/Store/Game/Catalog/{Add.GameID}");
  56. }
  57. public async Task<IActionResult> OnPostUpdateAsync(int gameID, int id, int price, bool isActive, CancellationToken ct)
  58. {
  59. var result = await mediator.Send(new Application.Features.Admin.Store.GameCatalog.Update.Command(id, price, isActive), ct);
  60. if (result.IsFailure)
  61. {
  62. TempData["ErrorMessages"] = result.Error.Description;
  63. }
  64. else
  65. {
  66. TempData["SuccessMessage"] = "카탈로그 항목이 수정되었습니다.";
  67. }
  68. return Redirect($"/Store/Game/Catalog/{gameID}");
  69. }
  70. public async Task<IActionResult> OnPostDeleteAsync(int gameID, int id, CancellationToken ct)
  71. {
  72. var result = await mediator.Send(new Application.Features.Admin.Store.GameCatalog.Delete.Command(id), ct);
  73. if (result.IsFailure)
  74. {
  75. TempData["ErrorMessages"] = result.Error.Description;
  76. }
  77. else
  78. {
  79. TempData["SuccessMessage"] = "카탈로그 항목이 삭제되었습니다.";
  80. }
  81. return Redirect($"/Store/Game/Catalog/{gameID}");
  82. }
  83. }