CrewWidgetConfigEndpoint.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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, 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.Title, body.Theme, body.Period,
  43. body.StartAt, body.EndAt,
  44. body.MaxDisplayCount, body.IsShowAmount, body.IsShowDonationCount,
  45. body.IsShowContributionRate, body.IsShowMemberIcon, body.IsActive,
  46. body.BgColor,
  47. body.TitleFontFamily, body.TitleFontSizePx, body.TitleFontColor,
  48. body.Rank1FontFamily, body.Rank1FontSizePx, body.Rank1FontColor,
  49. body.Rank2FontFamily, body.Rank2FontSizePx, body.Rank2FontColor,
  50. body.Rank3FontFamily, body.Rank3FontSizePx, body.Rank3FontColor,
  51. body.RowFontFamily, body.RowFontSizePx, body.RowFontColor
  52. );
  53. await sender.Send(command, ct);
  54. return ApiResponse.Ok();
  55. })
  56. .WithTags("StudioCrew")
  57. .RequireAuthorization();
  58. app.MapDelete("api/studio/crew/widget/config/{id}/{channelID}", async (
  59. int id,
  60. int channelID,
  61. ISender sender,
  62. CancellationToken ct
  63. ) => {
  64. await sender.Send(new Application.Features.Api.Crew.DeleteWidgetConfig.Command(id, channelID), ct);
  65. return ApiResponse.Ok();
  66. })
  67. .WithTags("StudioCrew")
  68. .RequireAuthorization();
  69. }
  70. }