forked from AcaMate/AcaMate_API
[✨] 세션 관리 API 추가
1. 웹 - 서버 데이터 관리 위한 세션 관리 API 추가
This commit is contained in:
parent
3ebb7137c0
commit
1738878093
|
@ -3,18 +3,23 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||
|
||||
namespace Back.Program.Common.Model
|
||||
{
|
||||
[Table("api_header")]
|
||||
public class APIHeader
|
||||
{
|
||||
[Key]
|
||||
public string specific_id { get; set; }
|
||||
|
||||
public DateTime connect_date { get; set; }
|
||||
public string h_key { get; set; }
|
||||
public string h_value { get; set; }
|
||||
}
|
||||
}
|
||||
[Table("api_header")]
|
||||
public class APIHeader
|
||||
{
|
||||
[Key]
|
||||
public string specific_id { get; set; }
|
||||
|
||||
public DateTime connect_date { get; set; }
|
||||
public string h_key { get; set; }
|
||||
public string h_value { get; set; }
|
||||
}
|
||||
|
||||
public class SessionData
|
||||
{
|
||||
public string key { get; set; }
|
||||
public string value { get; set; }
|
||||
}
|
||||
}
|
||||
/*
|
||||
h_key : h_value
|
||||
iOS_AM_Connect_Key
|
||||
|
|
|
@ -72,13 +72,50 @@ namespace Back.Program.Controllers.V1
|
|||
var result = await _appService.RetryAccess(summary, refresh);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("session")]
|
||||
|
||||
[HttpGet("session/get")]
|
||||
[CustomOperation("세션 정보 읽어오기", "세션 정보를 읽어오는 동작 수행", "시스템")]
|
||||
public async Task<IActionResult> GetSessionData(string key)
|
||||
{
|
||||
var value = _sessionService.GetString(key);
|
||||
return Ok(new {key = value});
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
return BadRequest(APIResponse.InvalidInputError());
|
||||
}
|
||||
|
||||
var (success, value) = await _sessionService.GetString(key);
|
||||
if (!success)
|
||||
{
|
||||
return BadRequest(APIResponse.InvalidInputError());
|
||||
}
|
||||
|
||||
string summary = _repositoryService.ReadSummary(typeof(AppController), "GetSessionData");
|
||||
return Ok(APIResponse.Send("000", $"[{summary}], 정상", new { data = value }));
|
||||
}
|
||||
|
||||
[HttpPost("session/set")]
|
||||
[CustomOperation("세션 정보 저장하기", "세션 정보에 저장하는 동작 수행", "시스템")]
|
||||
public async Task<IActionResult> SetSessionData([FromBody] SessionData[] requests)
|
||||
{
|
||||
if(requests == null || requests.Length == 0)
|
||||
{
|
||||
return BadRequest(APIResponse.InvalidInputError());
|
||||
}
|
||||
|
||||
Console.WriteLine($"받은 세션 데이터: {JsonSerializer.Serialize(requests)}");
|
||||
|
||||
foreach(var request in requests)
|
||||
{
|
||||
Console.WriteLine($"세션 저장 시도 - key: {request.key}, value: {request.value}");
|
||||
var success = await _sessionService.SetString(request.key, request.value);
|
||||
if (!success)
|
||||
{
|
||||
Console.WriteLine($"세션 저장 실패 - key: {request.key}");
|
||||
return BadRequest(APIResponse.InvalidInputError());
|
||||
}
|
||||
Console.WriteLine($"세션 저장 성공 - key: {request.key}");
|
||||
}
|
||||
|
||||
return Ok(APIResponse.Send("000", $"[세션 저장]: 정상", new { }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user