feat: 앱 버전 체크 API 구현 (#86) #87
32
SPMS.API/Controllers/AppVersionController.cs
Normal file
32
SPMS.API/Controllers/AppVersionController.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
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/app")]
|
||||||
|
[ApiExplorerSettings(GroupName = "public")]
|
||||||
|
public class AppVersionController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IAppConfigService _appConfigService;
|
||||||
|
|
||||||
|
public AppVersionController(IAppConfigService appConfigService)
|
||||||
|
{
|
||||||
|
_appConfigService = appConfigService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("version")]
|
||||||
|
[SwaggerOperation(Summary = "앱 버전 체크", Description = "현재 앱 버전 정보를 확인하고 업데이트 필요 여부를 반환합니다.")]
|
||||||
|
public async Task<IActionResult> CheckVersionAsync([FromBody] AppVersionRequestDto request)
|
||||||
|
{
|
||||||
|
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.GetAppVersionAsync(serviceCode, request);
|
||||||
|
return Ok(ApiResponse<AppVersionResponseDto>.Success(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
12
SPMS.Application/DTOs/AppConfig/AppVersionRequestDto.cs
Normal file
12
SPMS.Application/DTOs/AppConfig/AppVersionRequestDto.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace SPMS.Application.DTOs.AppConfig;
|
||||||
|
|
||||||
|
public class AppVersionRequestDto
|
||||||
|
{
|
||||||
|
[JsonPropertyName("platform")]
|
||||||
|
public string Platform { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[JsonPropertyName("app_version")]
|
||||||
|
public string AppVersion { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
18
SPMS.Application/DTOs/AppConfig/AppVersionResponseDto.cs
Normal file
18
SPMS.Application/DTOs/AppConfig/AppVersionResponseDto.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace SPMS.Application.DTOs.AppConfig;
|
||||||
|
|
||||||
|
public class AppVersionResponseDto
|
||||||
|
{
|
||||||
|
[JsonPropertyName("latest_version")]
|
||||||
|
public string? LatestVersion { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("min_version")]
|
||||||
|
public string? MinVersion { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("is_force_update")]
|
||||||
|
public bool IsForceUpdate { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("update_url")]
|
||||||
|
public string? UpdateUrl { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -6,4 +6,5 @@ public interface IAppConfigService
|
||||||
{
|
{
|
||||||
Task<AppConfigResponseDto> GetTermsAsync(string serviceCode);
|
Task<AppConfigResponseDto> GetTermsAsync(string serviceCode);
|
||||||
Task<AppConfigResponseDto> GetPrivacyAsync(string serviceCode);
|
Task<AppConfigResponseDto> GetPrivacyAsync(string serviceCode);
|
||||||
|
Task<AppVersionResponseDto> GetAppVersionAsync(string serviceCode, AppVersionRequestDto request);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,28 @@ public class AppConfigService : IAppConfigService
|
||||||
return await GetConfigUrlAsync(serviceCode, "privacy_url");
|
return await GetConfigUrlAsync(serviceCode, "privacy_url");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<AppVersionResponseDto> GetAppVersionAsync(string serviceCode, AppVersionRequestDto request)
|
||||||
|
{
|
||||||
|
var service = await _serviceRepository.GetByServiceCodeAsync(serviceCode);
|
||||||
|
if (service == null)
|
||||||
|
throw new SpmsException(ErrorCodes.NotFound, "존재하지 않는 서비스입니다.", 404);
|
||||||
|
|
||||||
|
var latestVersion = await _appConfigRepository.GetByKeyAsync(service.Id, "latest_version");
|
||||||
|
var minVersion = await _appConfigRepository.GetByKeyAsync(service.Id, "min_version");
|
||||||
|
var forceUpdate = await _appConfigRepository.GetByKeyAsync(service.Id, "force_update");
|
||||||
|
|
||||||
|
var updateUrlKey = request.Platform?.ToLowerInvariant() == "ios" ? "update_url_ios" : "update_url_android";
|
||||||
|
var updateUrl = await _appConfigRepository.GetByKeyAsync(service.Id, updateUrlKey);
|
||||||
|
|
||||||
|
return new AppVersionResponseDto
|
||||||
|
{
|
||||||
|
LatestVersion = latestVersion?.ConfigValue,
|
||||||
|
MinVersion = minVersion?.ConfigValue,
|
||||||
|
IsForceUpdate = string.Equals(forceUpdate?.ConfigValue, "true", StringComparison.OrdinalIgnoreCase),
|
||||||
|
UpdateUrl = updateUrl?.ConfigValue
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<AppConfigResponseDto> GetConfigUrlAsync(string serviceCode, string configKey)
|
private async Task<AppConfigResponseDto> GetConfigUrlAsync(string serviceCode, string configKey)
|
||||||
{
|
{
|
||||||
var service = await _serviceRepository.GetByServiceCodeAsync(serviceCode);
|
var service = await _serviceRepository.GetByServiceCodeAsync(serviceCode);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user