DonationAlertConfig.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Web.Api.Common;
  2. using Web.Api.Extensions;
  3. using MediatR;
  4. namespace Web.Api.Endpoints.Studio.Donation;
  5. /// <summary>후원 알림 위젯 설정 (스튜디오 전용)</summary>
  6. internal sealed class DonationAlertConfig : IEndpoint
  7. {
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. /// 금액별 효과음, 이미지, 노출 시간 등 조회
  11. app.MapGet("api/studio/donation/alert/config/{channelID}", async (
  12. int channelID,
  13. ISender sender,
  14. CancellationToken ct
  15. ) => {
  16. var data = await sender.Send(new Application.Features.Api.DonationAlert.GetConfig.Query(channelID), ct);
  17. return ApiResponse.Ok(data);
  18. })
  19. .WithTags("StudioDonationAlert")
  20. .RequireAuthorization();
  21. /// 알림 설정 저장/수정
  22. app.MapPost("api/studio/donation/alert/config", async (
  23. Application.Features.Api.DonationAlert.SaveConfig.Command body,
  24. ISender sender,
  25. CancellationToken ct
  26. ) => {
  27. await sender.Send(body, ct);
  28. return ApiResponse.Ok();
  29. })
  30. .WithTags("StudioDonationAlert")
  31. .RequireAuthorization();
  32. /// 알림 설정 일괄 저장/삭제
  33. app.MapPost("api/studio/donation/alert/config/batch", async (
  34. Application.Features.Api.DonationAlert.BatchSaveConfig.Command body,
  35. ISender sender,
  36. CancellationToken ct
  37. ) => {
  38. await sender.Send(body, ct);
  39. return ApiResponse.Ok();
  40. })
  41. .WithTags("StudioDonationAlert")
  42. .RequireAuthorization();
  43. /// 알림 설정 삭제
  44. app.MapDelete("api/studio/donation/alert/config/{id}/{channelID}", async (
  45. int id,
  46. int channelID,
  47. ISender sender,
  48. CancellationToken ct
  49. ) => {
  50. await sender.Send(new Application.Features.Api.DonationAlert.DeleteConfig.Command(id, channelID), ct);
  51. return ApiResponse.Ok();
  52. })
  53. .WithTags("StudioDonationAlert")
  54. .RequireAuthorization();
  55. /// 알림 활성/비활성 토글
  56. app.MapPatch("api/studio/donation/alert/config/{id}/active", async (
  57. int id,
  58. ToggleActiveRequest body,
  59. ISender sender,
  60. CancellationToken ct
  61. ) => {
  62. var result = await sender.Send(new Application.Features.Api.DonationAlert.ToggleActive.Command(id, body.ChannelID, body.IsActive), ct);
  63. return result.Match(
  64. data => ApiResponse.Ok(data),
  65. CustomResults.Problem
  66. );
  67. })
  68. .WithTags("StudioDonationAlert")
  69. .RequireAuthorization();
  70. }
  71. public sealed record ToggleActiveRequest(int ChannelID, bool IsActive);
  72. }