Migrate SiteSettings controller to FastEndpoints
Refactored SiteSettingsController to FastEndpoints pattern: - Created GetEndpoint.cs: GET /api/sitesettings (authorized) - Created SaveEndpoint.cs: PUT /api/sitesettings (authorized) - Removed legacy SiteSettingsController.cs Both endpoints use Bearer token authentication and are auto-discovered by FastEndpoints configuration in Program.cs. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using FastEndpoints;
|
||||
using TaxBaik.Application.Services;
|
||||
|
||||
namespace TaxBaik.Web.Endpoints.SiteSettings;
|
||||
|
||||
public class GetEndpoint : Endpoint<EmptyRequest, IReadOnlyDictionary<string, string>>
|
||||
{
|
||||
private readonly SiteSettingService _siteSettingService;
|
||||
|
||||
public GetEndpoint(SiteSettingService siteSettingService)
|
||||
{
|
||||
_siteSettingService = siteSettingService;
|
||||
}
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/sitesettings");
|
||||
Policies("Bearer");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(EmptyRequest _, CancellationToken ct)
|
||||
{
|
||||
var settings = await _siteSettingService.GetAllAsync(ct);
|
||||
await SendAsync(settings, 200, cancellation: ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using FastEndpoints;
|
||||
using TaxBaik.Application.Services;
|
||||
|
||||
namespace TaxBaik.Web.Endpoints.SiteSettings;
|
||||
|
||||
public class SaveSiteSettingsRequest
|
||||
{
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string KakaoUrl { get; set; } = string.Empty;
|
||||
public string InstagramUrl { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class SaveResponse
|
||||
{
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class SaveEndpoint : Endpoint<SaveSiteSettingsRequest, SaveResponse>
|
||||
{
|
||||
private readonly SiteSettingService _siteSettingService;
|
||||
|
||||
public SaveEndpoint(SiteSettingService siteSettingService)
|
||||
{
|
||||
_siteSettingService = siteSettingService;
|
||||
}
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/api/sitesettings");
|
||||
Policies("Bearer");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(SaveSiteSettingsRequest request, CancellationToken ct)
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
ThrowError("요청 본문이 비어 있습니다.");
|
||||
}
|
||||
|
||||
await _siteSettingService.SaveAsync(request.Phone, request.Email, request.KakaoUrl, request.InstagramUrl, ct);
|
||||
|
||||
await SendAsync(new SaveResponse
|
||||
{
|
||||
Message = "사이트 설정이 저장되었습니다."
|
||||
}, 200, cancellation: ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user