DonationGoalConfig.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. bool IsActive
  29. );
  30. public void MapEndpoint(IEndpointRouteBuilder app)
  31. {
  32. /// 목표 설정 목록 조회
  33. app.MapGet("api/studio/donation/goal/config/{channelID}", async (
  34. int channelID,
  35. ISender sender,
  36. CancellationToken ct
  37. ) => {
  38. var data = await sender.Send(new Application.Features.Api.DonationGoal.GetConfig.Query(channelID), ct);
  39. return ApiResponse.Ok(data);
  40. })
  41. .WithTags("StudioDonationGoal")
  42. .RequireAuthorization();
  43. /// 목표 설정 저장/수정
  44. app.MapPost("api/studio/donation/goal/config", async (
  45. SaveRequest body,
  46. ClaimsPrincipal user,
  47. ISender sender,
  48. CancellationToken ct
  49. ) => {
  50. var memberID = user.GetRequiredMemberID();
  51. var command = new Application.Features.Api.DonationGoal.SaveConfig.Command(
  52. body.ChannelID,
  53. memberID,
  54. body.ID,
  55. body.Title,
  56. body.Style,
  57. body.StartAmount,
  58. body.TargetAmount,
  59. body.StartAt,
  60. body.EndAt,
  61. body.IsShowPercent,
  62. body.BarColor,
  63. body.BarBackgroundColor,
  64. body.BarHeightPx,
  65. body.TitleFontSizePx,
  66. body.TitleFontColor,
  67. body.AmountFontSizePx,
  68. body.AmountFontColor,
  69. body.TitleFontFamily,
  70. body.AmountFontFamily,
  71. body.IsActive
  72. );
  73. await sender.Send(command, ct);
  74. return ApiResponse.Ok();
  75. })
  76. .WithTags("StudioDonationGoal")
  77. .RequireAuthorization();
  78. /// 목표 설정 삭제
  79. app.MapDelete("api/studio/donation/goal/config/{id}/{channelID}", async (
  80. int id,
  81. int channelID,
  82. ISender sender,
  83. CancellationToken ct
  84. ) => {
  85. await sender.Send(new Application.Features.Api.DonationGoal.DeleteConfig.Command(id, channelID), ct);
  86. return ApiResponse.Ok();
  87. })
  88. .WithTags("StudioDonationGoal")
  89. .RequireAuthorization();
  90. }
  91. }