feat: 이용약관/개인정보처리방침 API 구현 (#84)
This commit is contained in:
parent
0ead7a4bcb
commit
6475c0c753
44
SPMS.API/Controllers/TermsController.cs
Normal file
44
SPMS.API/Controllers/TermsController.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Swashbuckle.AspNetCore.Annotations;
|
||||||
|
using SPMS.Application.DTOs.AppConfig;
|
||||||
|
using SPMS.Application.Interfaces;
|
||||||
|
using SPMS.Domain.Common;
|
||||||
|
|
||||||
|
namespace SPMS.API.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("v1/in/public")]
|
||||||
|
[ApiExplorerSettings(GroupName = "public")]
|
||||||
|
public class TermsController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IAppConfigService _appConfigService;
|
||||||
|
|
||||||
|
public TermsController(IAppConfigService appConfigService)
|
||||||
|
{
|
||||||
|
_appConfigService = appConfigService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("terms")]
|
||||||
|
[SwaggerOperation(Summary = "이용약관", Description = "이용약관 URL을 조회합니다.")]
|
||||||
|
public async Task<IActionResult> GetTermsAsync()
|
||||||
|
{
|
||||||
|
var serviceCode = Request.Headers["X-Service-Code"].FirstOrDefault();
|
||||||
|
if (string.IsNullOrWhiteSpace(serviceCode))
|
||||||
|
return BadRequest(ApiResponse.Fail(ErrorCodes.BadRequest, "X-Service-Code 헤더가 필요합니다."));
|
||||||
|
|
||||||
|
var result = await _appConfigService.GetTermsAsync(serviceCode);
|
||||||
|
return Ok(ApiResponse<AppConfigResponseDto>.Success(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("privacy")]
|
||||||
|
[SwaggerOperation(Summary = "개인정보처리방침", Description = "개인정보처리방침 URL을 조회합니다.")]
|
||||||
|
public async Task<IActionResult> GetPrivacyAsync()
|
||||||
|
{
|
||||||
|
var serviceCode = Request.Headers["X-Service-Code"].FirstOrDefault();
|
||||||
|
if (string.IsNullOrWhiteSpace(serviceCode))
|
||||||
|
return BadRequest(ApiResponse.Fail(ErrorCodes.BadRequest, "X-Service-Code 헤더가 필요합니다."));
|
||||||
|
|
||||||
|
var result = await _appConfigService.GetPrivacyAsync(serviceCode);
|
||||||
|
return Ok(ApiResponse<AppConfigResponseDto>.Success(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
9
SPMS.Application/DTOs/AppConfig/AppConfigResponseDto.cs
Normal file
9
SPMS.Application/DTOs/AppConfig/AppConfigResponseDto.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace SPMS.Application.DTOs.AppConfig;
|
||||||
|
|
||||||
|
public class AppConfigResponseDto
|
||||||
|
{
|
||||||
|
[JsonPropertyName("url")]
|
||||||
|
public string? Url { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -15,6 +15,7 @@ public static class DependencyInjection
|
||||||
services.AddScoped<INoticeService, NoticeService>();
|
services.AddScoped<INoticeService, NoticeService>();
|
||||||
services.AddScoped<IBannerService, BannerService>();
|
services.AddScoped<IBannerService, BannerService>();
|
||||||
services.AddScoped<IFaqService, FaqService>();
|
services.AddScoped<IFaqService, FaqService>();
|
||||||
|
services.AddScoped<IAppConfigService, AppConfigService>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
SPMS.Application/Interfaces/IAppConfigService.cs
Normal file
9
SPMS.Application/Interfaces/IAppConfigService.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
using SPMS.Application.DTOs.AppConfig;
|
||||||
|
|
||||||
|
namespace SPMS.Application.Interfaces;
|
||||||
|
|
||||||
|
public interface IAppConfigService
|
||||||
|
{
|
||||||
|
Task<AppConfigResponseDto> GetTermsAsync(string serviceCode);
|
||||||
|
Task<AppConfigResponseDto> GetPrivacyAsync(string serviceCode);
|
||||||
|
}
|
||||||
43
SPMS.Application/Services/AppConfigService.cs
Normal file
43
SPMS.Application/Services/AppConfigService.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
using SPMS.Application.DTOs.AppConfig;
|
||||||
|
using SPMS.Application.Interfaces;
|
||||||
|
using SPMS.Domain.Common;
|
||||||
|
using SPMS.Domain.Exceptions;
|
||||||
|
using SPMS.Domain.Interfaces;
|
||||||
|
|
||||||
|
namespace SPMS.Application.Services;
|
||||||
|
|
||||||
|
public class AppConfigService : IAppConfigService
|
||||||
|
{
|
||||||
|
private readonly IAppConfigRepository _appConfigRepository;
|
||||||
|
private readonly IServiceRepository _serviceRepository;
|
||||||
|
|
||||||
|
public AppConfigService(IAppConfigRepository appConfigRepository, IServiceRepository serviceRepository)
|
||||||
|
{
|
||||||
|
_appConfigRepository = appConfigRepository;
|
||||||
|
_serviceRepository = serviceRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<AppConfigResponseDto> GetTermsAsync(string serviceCode)
|
||||||
|
{
|
||||||
|
return await GetConfigUrlAsync(serviceCode, "terms_url");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<AppConfigResponseDto> GetPrivacyAsync(string serviceCode)
|
||||||
|
{
|
||||||
|
return await GetConfigUrlAsync(serviceCode, "privacy_url");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<AppConfigResponseDto> GetConfigUrlAsync(string serviceCode, string configKey)
|
||||||
|
{
|
||||||
|
var service = await _serviceRepository.GetByServiceCodeAsync(serviceCode);
|
||||||
|
if (service == null)
|
||||||
|
throw new SpmsException(ErrorCodes.NotFound, "존재하지 않는 서비스입니다.", 404);
|
||||||
|
|
||||||
|
var config = await _appConfigRepository.GetByKeyAsync(service.Id, configKey);
|
||||||
|
|
||||||
|
return new AppConfigResponseDto
|
||||||
|
{
|
||||||
|
Url = config?.ConfigValue
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
8
SPMS.Domain/Interfaces/IAppConfigRepository.cs
Normal file
8
SPMS.Domain/Interfaces/IAppConfigRepository.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
using SPMS.Domain.Entities;
|
||||||
|
|
||||||
|
namespace SPMS.Domain.Interfaces;
|
||||||
|
|
||||||
|
public interface IAppConfigRepository : IRepository<AppConfig>
|
||||||
|
{
|
||||||
|
Task<AppConfig?> GetByKeyAsync(long serviceId, string configKey);
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,7 @@ public static class DependencyInjection
|
||||||
services.AddScoped<INoticeRepository, NoticeRepository>();
|
services.AddScoped<INoticeRepository, NoticeRepository>();
|
||||||
services.AddScoped<IBannerRepository, BannerRepository>();
|
services.AddScoped<IBannerRepository, BannerRepository>();
|
||||||
services.AddScoped<IFaqRepository, FaqRepository>();
|
services.AddScoped<IFaqRepository, FaqRepository>();
|
||||||
|
services.AddScoped<IAppConfigRepository, AppConfigRepository>();
|
||||||
|
|
||||||
// External Services
|
// External Services
|
||||||
services.AddScoped<IJwtService, JwtService>();
|
services.AddScoped<IJwtService, JwtService>();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using SPMS.Domain.Entities;
|
||||||
|
using SPMS.Domain.Interfaces;
|
||||||
|
|
||||||
|
namespace SPMS.Infrastructure.Persistence.Repositories;
|
||||||
|
|
||||||
|
public class AppConfigRepository : Repository<AppConfig>, IAppConfigRepository
|
||||||
|
{
|
||||||
|
public AppConfigRepository(AppDbContext context) : base(context) { }
|
||||||
|
|
||||||
|
public async Task<AppConfig?> GetByKeyAsync(long serviceId, string configKey)
|
||||||
|
{
|
||||||
|
return await _dbSet.FirstOrDefaultAsync(c => c.ServiceId == serviceId && c.ConfigKey == configKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user