| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System.Security.Claims;
- using MediatR;
- using Web.Api.Common;
- using Web.Api.Extensions;
- namespace Web.Api.Endpoints.Studio.Crew;
- /// <summary>크루 위젯 설정 CRUD</summary>
- internal sealed class CrewWidgetConfigEndpoint : IEndpoint
- {
- internal sealed record SaveRequest(
- int? ID, int ChannelID, int CrewID, string Title, int Theme, int Period,
- DateTime? StartAt, DateTime? EndAt,
- int MaxDisplayCount, bool IsShowAmount, bool IsShowDonationCount,
- bool IsShowContributionRate, bool IsShowMemberIcon, bool IsActive,
- string BgColor,
- string? TitleFontFamily, int TitleFontSizePx, string TitleFontColor,
- string? Rank1FontFamily, int Rank1FontSizePx, string Rank1FontColor,
- string? Rank2FontFamily, int Rank2FontSizePx, string Rank2FontColor,
- string? Rank3FontFamily, int Rank3FontSizePx, string Rank3FontColor,
- string? RowFontFamily, int RowFontSizePx, string RowFontColor
- );
- public void MapEndpoint(IEndpointRouteBuilder app)
- {
- app.MapGet("api/studio/crew/widget/config/{channelID}", async (
- int channelID,
- ISender sender,
- CancellationToken ct
- ) => {
- var data = await sender.Send(new Application.Features.Api.Crew.GetWidgetConfig.Query(channelID), ct);
- return ApiResponse.Ok(data);
- })
- .WithTags("StudioCrew")
- .RequireAuthorization();
- app.MapPost("api/studio/crew/widget/config", async (
- SaveRequest body,
- ClaimsPrincipal user,
- ISender sender,
- CancellationToken ct
- ) => {
- var memberID = user.GetRequiredMemberID();
- var command = new Application.Features.Api.Crew.SaveWidgetConfig.Command(
- body.ChannelID, memberID, body.ID,
- body.CrewID,
- body.Title, body.Theme, body.Period,
- body.StartAt, body.EndAt,
- body.MaxDisplayCount, body.IsShowAmount, body.IsShowDonationCount,
- body.IsShowContributionRate, body.IsShowMemberIcon, body.IsActive,
- body.BgColor,
- body.TitleFontFamily, body.TitleFontSizePx, body.TitleFontColor,
- body.Rank1FontFamily, body.Rank1FontSizePx, body.Rank1FontColor,
- body.Rank2FontFamily, body.Rank2FontSizePx, body.Rank2FontColor,
- body.Rank3FontFamily, body.Rank3FontSizePx, body.Rank3FontColor,
- body.RowFontFamily, body.RowFontSizePx, body.RowFontColor
- );
- await sender.Send(command, ct);
- return ApiResponse.Ok();
- })
- .WithTags("StudioCrew")
- .RequireAuthorization();
- app.MapDelete("api/studio/crew/widget/config/{id}/{channelID}", async (
- int id,
- int channelID,
- ISender sender,
- CancellationToken ct
- ) => {
- await sender.Send(new Application.Features.Api.Crew.DeleteWidgetConfig.Command(id, channelID), ct);
- return ApiResponse.Ok();
- })
- .WithTags("StudioCrew")
- .RequireAuthorization();
- /// 위젯 활성/비활성 토글
- app.MapPatch("api/studio/crew/widget/config/{id}/active", async (
- int id,
- ToggleActiveRequest body,
- ISender sender,
- CancellationToken ct
- ) => {
- var result = await sender.Send(new Application.Features.Api.Crew.ToggleWidgetActive.Command(id, body.ChannelID, body.IsActive), ct);
- return result.Match(
- data => ApiResponse.Ok(data),
- CustomResults.Problem
- );
- })
- .WithTags("StudioCrew")
- .RequireAuthorization();
- }
- internal sealed record ToggleActiveRequest(int ChannelID, bool IsActive);
- }
|