DonationGoalConfig.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System.Security.Claims;
  2. using MediatR;
  3. using Web.Api.Common;
  4. using Web.Api.Extensions;
  5. namespace Web.Api.Endpoints.Studio.Donation;
  6. /// <summary>후원 목표 위젯 설정 (스튜디오 전용)</summary>
  7. internal sealed class DonationGoalConfig : IEndpoint
  8. {
  9. internal sealed record SaveRequest(
  10. int? ID,
  11. int ChannelID,
  12. string Title,
  13. int Style,
  14. int StartAmount,
  15. int TargetAmount,
  16. DateTime? StartAt,
  17. DateTime? EndAt,
  18. bool IsShowPercent,
  19. string BarColor,
  20. string BarBackgroundColor,
  21. int BarHeightPx,
  22. int TitleFontSizePx,
  23. string TitleFontColor,
  24. int AmountFontSizePx,
  25. string AmountFontColor,
  26. string? TitleFontFamily,
  27. string? AmountFontFamily,
  28. int Period,
  29. bool IsActive
  30. );
  31. public void MapEndpoint(IEndpointRouteBuilder app)
  32. {
  33. /// 목표 설정 목록 조회
  34. app.MapGet("api/studio/donation/goal/config/{channelID}", async (
  35. int channelID,
  36. ISender sender,
  37. CancellationToken ct
  38. ) => {
  39. var data = await sender.Send(new Application.Features.Api.DonationGoal.GetConfig.Query(channelID), ct);
  40. return ApiResponse.Ok(data);
  41. })
  42. .WithTags("StudioDonationGoal")
  43. .RequireAuthorization();
  44. /// 목표 설정 저장/수정
  45. app.MapPost("api/studio/donation/goal/config", async (
  46. SaveRequest body,
  47. ClaimsPrincipal user,
  48. ISender sender,
  49. CancellationToken ct
  50. ) => {
  51. var memberID = user.GetRequiredMemberID();
  52. var command = new Application.Features.Api.DonationGoal.SaveConfig.Command(
  53. body.ChannelID,
  54. memberID,
  55. body.ID,
  56. body.Title,
  57. body.Style,
  58. body.StartAmount,
  59. body.TargetAmount,
  60. body.StartAt,
  61. body.EndAt,
  62. body.IsShowPercent,
  63. body.BarColor,
  64. body.BarBackgroundColor,
  65. body.BarHeightPx,
  66. body.TitleFontSizePx,
  67. body.TitleFontColor,
  68. body.AmountFontSizePx,
  69. body.AmountFontColor,
  70. body.TitleFontFamily,
  71. body.AmountFontFamily,
  72. body.Period,
  73. body.IsActive
  74. );
  75. await sender.Send(command, ct);
  76. return ApiResponse.Ok();
  77. })
  78. .WithTags("StudioDonationGoal")
  79. .RequireAuthorization();
  80. /// 목표 설정 삭제
  81. app.MapDelete("api/studio/donation/goal/config/{id}/{channelID}", async (
  82. int id,
  83. int channelID,
  84. ISender sender,
  85. CancellationToken ct
  86. ) => {
  87. await sender.Send(new Application.Features.Api.DonationGoal.DeleteConfig.Command(id, channelID), ct);
  88. return ApiResponse.Ok();
  89. })
  90. .WithTags("StudioDonationGoal")
  91. .RequireAuthorization();
  92. /// 목표 활성/비활성 토글
  93. app.MapPatch("api/studio/donation/goal/config/{id}/active", async (
  94. int id,
  95. ToggleActiveRequest body,
  96. ISender sender,
  97. CancellationToken ct
  98. ) => {
  99. var result = await sender.Send(new Application.Features.Api.DonationGoal.ToggleActive.Command(id, body.ChannelID, body.IsActive), ct);
  100. return result.Match(
  101. data => ApiResponse.Ok(data),
  102. CustomResults.Problem
  103. );
  104. })
  105. .WithTags("StudioDonationGoal")
  106. .RequireAuthorization();
  107. }
  108. internal sealed record ToggleActiveRequest(int ChannelID, bool IsActive);
  109. }