forked from AcaMate/AcaMate_API
[✨] 세션 관리 API 추가
1. 웹 - 서버 데이터 관리 위한 세션 관리 API 추가
This commit is contained in:
parent
3ebb7137c0
commit
1738878093
|
@ -13,8 +13,13 @@ namespace Back.Program.Common.Model
|
||||||
public string h_key { get; set; }
|
public string h_key { get; set; }
|
||||||
public string h_value { 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
|
h_key : h_value
|
||||||
iOS_AM_Connect_Key
|
iOS_AM_Connect_Key
|
||||||
|
|
|
@ -73,12 +73,49 @@ namespace Back.Program.Controllers.V1
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("session")]
|
[HttpGet("session/get")]
|
||||||
[CustomOperation("세션 정보 읽어오기", "세션 정보를 읽어오는 동작 수행", "시스템")]
|
[CustomOperation("세션 정보 읽어오기", "세션 정보를 읽어오는 동작 수행", "시스템")]
|
||||||
public async Task<IActionResult> GetSessionData(string key)
|
public async Task<IActionResult> GetSessionData(string key)
|
||||||
{
|
{
|
||||||
var value = _sessionService.GetString(key);
|
if (string.IsNullOrEmpty(key))
|
||||||
return Ok(new {key = value});
|
{
|
||||||
|
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