| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using Application.Abstractions.Data;
- using Web.Api.Common;
- using Microsoft.EntityFrameworkCore;
- namespace Web.Api.Endpoints.Widget;
- /// <summary>WidgetToken + configID로 GoalConfig 조회 (위젯 스타일 적용용, 인증 불필요).
- /// configID 미지정 시 활성 첫 번째 자동 선택.</summary>
- internal sealed class GoalConfigByToken : IEndpoint
- {
- public void MapEndpoint(IEndpointRouteBuilder app)
- {
- app.MapGet("api/widget/goal/config/{widgetToken}", async (
- string widgetToken,
- int? configID,
- IAppDbContext db,
- CancellationToken ct
- ) => {
- var channelID = await db.Channel.AsNoTracking()
- .Where(c => c.WidgetToken == widgetToken && c.IsActive)
- .Select(c => c.ID)
- .FirstOrDefaultAsync(ct);
- if (channelID == 0)
- {
- return ApiResponse.Ok((object?)null);
- }
- var query = db.DonationGoalConfig.AsNoTracking()
- .Where(g => g.ChannelID == channelID);
- if (configID.HasValue)
- {
- query = query.Where(g => g.ID == configID.Value);
- }
- else
- {
- query = query.Where(g => g.IsActive);
- }
- var config = await query
- .OrderByDescending(g => g.ID)
- .Select(g => new
- {
- id = g.ID,
- title = g.Title,
- style = (int)g.Style,
- startAmount = g.StartAmount,
- targetAmount = g.TargetAmount,
- isShowPercent = g.IsShowPercent,
- barColor = g.BarColor,
- barBackgroundColor = g.BarBackgroundColor,
- barHeightPx = g.BarHeightPx,
- titleFontSizePx = g.TitleFontSizePx,
- titleFontColor = g.TitleFontColor,
- amountFontSizePx = g.AmountFontSizePx,
- amountFontColor = g.AmountFontColor,
- titleFontFamily = g.TitleFontFamily,
- amountFontFamily = g.AmountFontFamily,
- period = (int)g.Period,
- isActive = g.IsActive
- })
- .FirstOrDefaultAsync(ct);
- return ApiResponse.Ok((object?)config);
- })
- .WithTags("Widget")
- .AllowAnonymous();
- }
- }
|