using System.Security.Cryptography; using System.Text; using System.Text.Json; using Back.Program.Common.Auth; using Back.Program.Common.Data; using Back.Program.Common.Model; using Back.Program.Models.Entities; using Back.Program.Repositories.V1.Interfaces; using Back.Program.Services.V1; using Back.Program.Services.V1.Interfaces; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Version = Back.Program.Models.Entities.Version; namespace Back.Program.Controllers.V1 { [ApiController] [Route("/api/v1/in/app")] [ApiExplorerSettings(GroupName = "공통")] public class AppController : ControllerBase { private readonly AppDbContext _dbContext; private readonly ILogger _logger; private readonly IRepositoryService _repositoryService; private readonly JwtTokenService _jwtTokenService; private readonly IAppService _appService; private readonly IAppRepository _appRepository; public AppController(AppDbContext dbContext, ILogger logger, IRepositoryService repositoryService, JwtTokenService jwtTokenService,IAppService appService, IAppRepository appRepository) { _dbContext = dbContext; _logger = logger; _repositoryService = repositoryService; _jwtTokenService = jwtTokenService; _appService = appService; _appRepository = appRepository; } // 이 키값의 제한 시간은 24h이다 [HttpGet] [CustomOperation("헤더 정보 생성", "헤더에 접근하기 위한 키 값 받아오기", "시스템")] public async Task GetHeaderValue(string type, string specific, string project) { if (string.IsNullOrEmpty(specific) || string.IsNullOrEmpty(type) || string.IsNullOrEmpty(project)) return BadRequest(APIResponse.InvalidInputError()); if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError()); string summary = _repositoryService.ReadSummary(typeof(AppController), "GetHeaderValue"); var result = await _appService.GetHeader(summary, type, specific, project); return Ok(result); } [HttpGet("version")] [CustomOperation("앱 버전 확인","앱 버전을 확인해서 업데이트 여부 판단", "시스템")] public async Task GetVersionData(string type) { if (string.IsNullOrEmpty(type)) return BadRequest(APIResponse.InvalidInputError()); string summary = _repositoryService.ReadSummary(typeof(AppController), "GetHeaderValue"); var result = await _appService.GetVersion(summary, type); return Ok(result); } [HttpGet("retryAccess")] [CustomOperation("엑세스 토큰 재발급", "액세스 토큰 재발급 동작 수행", "시스템")] public async Task RetryAccessToken(string refresh) { if (string.IsNullOrEmpty(refresh)) return BadRequest(APIResponse.InvalidInputError()); string summary = _repositoryService.ReadSummary(typeof(AppController), "RetryAccessToken"); var result = await _appService.RetryAccess(summary, refresh); return Ok(result); } } }