CrewWidgetConfigEndpoint.cs 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.Security.Claims;
  2. using MediatR;
  3. using Web.Api.Common;
  4. using Web.Api.Extensions;
  5. namespace Web.Api.Endpoints.Studio.Crew;
  6. /// <summary>크루 위젯 설정 CRUD</summary>
  7. internal sealed class CrewWidgetConfigEndpoint : IEndpoint
  8. {
  9. internal sealed record SaveRequest(
  10. int? ID, int ChannelID, int CrewID, string Title, int Theme, int Period,
  11. DateTime? StartAt, DateTime? EndAt,
  12. int MaxDisplayCount, bool IsShowAmount, bool IsShowDonationCount,
  13. bool IsShowContributionRate, bool IsShowMemberIcon, bool IsActive,
  14. string BgColor,
  15. string? TitleFontFamily, int TitleFontSizePx, string TitleFontColor,
  16. string? Rank1FontFamily, int Rank1FontSizePx, string Rank1FontColor,
  17. string? Rank2FontFamily, int Rank2FontSizePx, string Rank2FontColor,
  18. string? Rank3FontFamily, int Rank3FontSizePx, string Rank3FontColor,
  19. string? RowFontFamily, int RowFontSizePx, string RowFontColor
  20. );
  21. public void MapEndpoint(IEndpointRouteBuilder app)
  22. {
  23. app.MapGet("api/studio/crew/widget/config/{channelID}", async (
  24. int channelID,
  25. ISender sender,
  26. CancellationToken ct
  27. ) => {
  28. var data = await sender.Send(new Application.Features.Api.Crew.GetWidgetConfig.Query(channelID), ct);
  29. return ApiResponse.Ok(data);
  30. })
  31. .WithTags("StudioCrew")
  32. .RequireAuthorization();
  33. app.MapPost("api/studio/crew/widget/config", async (
  34. SaveRequest body,
  35. ClaimsPrincipal user,
  36. ISender sender,
  37. CancellationToken ct
  38. ) => {
  39. var memberID = user.GetRequiredMemberID();
  40. var command = new Application.Features.Api.Crew.SaveWidgetConfig.Command(
  41. body.ChannelID, memberID, body.ID,
  42. body.CrewID,
  43. body.Title, body.Theme, body.Period,
  44. body.StartAt, body.EndAt,
  45. body.MaxDisplayCount, body.IsShowAmount, body.IsShowDonationCount,
  46. body.IsShowContributionRate, body.IsShowMemberIcon, body.IsActive,
  47. body.BgColor,
  48. body.TitleFontFamily, body.TitleFontSizePx, body.TitleFontColor,
  49. body.Rank1FontFamily, body.Rank1FontSizePx, body.Rank1FontColor,
  50. body.Rank2FontFamily, body.Rank2FontSizePx, body.Rank2FontColor,
  51. body.Rank3FontFamily, body.Rank3FontSizePx, body.Rank3FontColor,
  52. body.RowFontFamily, body.RowFontSizePx, body.RowFontColor
  53. );
  54. await sender.Send(command, ct);
  55. return ApiResponse.Ok();
  56. })
  57. .WithTags("StudioCrew")
  58. .RequireAuthorization();
  59. app.MapDelete("api/studio/crew/widget/config/{id}/{channelID}", async (
  60. int id,
  61. int channelID,
  62. ISender sender,
  63. CancellationToken ct
  64. ) => {
  65. await sender.Send(new Application.Features.Api.Crew.DeleteWidgetConfig.Command(id, channelID), ct);
  66. return ApiResponse.Ok();
  67. })
  68. .WithTags("StudioCrew")
  69. .RequireAuthorization();
  70. /// 위젯 활성/비활성 토글
  71. app.MapPatch("api/studio/crew/widget/config/{id}/active", async (
  72. int id,
  73. ToggleActiveRequest body,
  74. ISender sender,
  75. CancellationToken ct
  76. ) => {
  77. var result = await sender.Send(new Application.Features.Api.Crew.ToggleWidgetActive.Command(id, body.ChannelID, body.IsActive), ct);
  78. return result.Match(
  79. data => ApiResponse.Ok(data),
  80. CustomResults.Problem
  81. );
  82. })
  83. .WithTags("StudioCrew")
  84. .RequireAuthorization();
  85. }
  86. internal sealed record ToggleActiveRequest(int ChannelID, bool IsActive);
  87. }