forked from AcaMate/AcaMate_Web
[♻️] 세션 스토리지 저장 로직 변경
1. API 호출 후 받아지는 데이터 반환하는 로직 추가 2. 스토리지 저장시 사용하는 변수 이름 변경
This commit is contained in:
parent
d89db8c890
commit
1e563eb576
|
@ -28,9 +28,9 @@ public class APIService(HttpClient http,
|
|||
return response;
|
||||
}
|
||||
|
||||
public async Task<(bool success,T? data)> GetConnectServerAsnyc<T>(string url) {
|
||||
public async Task<(bool success, string? json, T? data)> GetConnectServerAsnyc<T>(string url) {
|
||||
var headerValue = await storageService.GetItemAsync("Web-AM-Connect-Key");
|
||||
if (string.IsNullOrEmpty(headerValue)) return (false, default);
|
||||
if (string.IsNullOrEmpty(headerValue)) return (false, null,default);
|
||||
|
||||
var args = new {
|
||||
url = $"{url}",
|
||||
|
@ -55,14 +55,14 @@ public class APIService(HttpClient http,
|
|||
var dataJson = dataElement.ToString();
|
||||
var serialData = JsonSerializer.Deserialize<T>(dataJson,
|
||||
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
Console.WriteLine("[GetConnectServerAsnyc] 사용자 데이터 Json: " + dataJson);
|
||||
Console.WriteLine("[GetConnectServerAsnyc] 사용자 데이터 Json: " + dataJson + dataJson.GetType());
|
||||
Console.WriteLine("[GetConnectServerAsnyc] 사용자 데이터 변환: " + serialData.ToString());;
|
||||
|
||||
if (serialData != null)
|
||||
{
|
||||
var encryptedData = await secureService.EncryptAsync(dataJson);
|
||||
await storageService.SetItemAsync("USER_DATA", encryptedData);
|
||||
return (true, serialData);
|
||||
// await storageService.SetItemAsync("USER_DATA", encryptedData);
|
||||
return (true, encryptedData, serialData);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -76,7 +76,7 @@ public class APIService(HttpClient http,
|
|||
}
|
||||
|
||||
Console.WriteLine("데이터를 찾을 수 없습니다");
|
||||
return (false, default);
|
||||
return (false, null, default);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ using Microsoft.JSInterop;
|
|||
|
||||
namespace Front.Program.ViewModels;
|
||||
|
||||
public class UserStateService(StorageService _storageService,SecureService _secureService, APIService _APIService,
|
||||
public class UserStateService(StorageService _storageService, SecureService _secureService, APIService _APIService,
|
||||
IJSRuntime _js)
|
||||
{
|
||||
public UserData UserData { get; set; } = new UserData();
|
||||
|
@ -15,11 +15,11 @@ public class UserStateService(StorageService _storageService,SecureService _secu
|
|||
public Models.SimpleAcademy[] academyItems = Array.Empty<Models.SimpleAcademy>();
|
||||
|
||||
|
||||
public async Task<(bool success, UserData? userData)> GetUserDataFromStorageAsync()
|
||||
public async Task<(bool success,UserData? userData)> GetUserDataFromStorageAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var encUserData = await _storageService.GetItemAsync("USER_DATA");
|
||||
var encUserData = await _storageService.GetItemAsync("UsDt");
|
||||
|
||||
if (!string.IsNullOrEmpty(encUserData))
|
||||
{
|
||||
|
@ -46,10 +46,6 @@ public class UserStateService(StorageService _storageService,SecureService _secu
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<(bool success, UserData? userData)> GetUserDataFromServerAsync()
|
||||
{
|
||||
return await _APIService.GetConnectServerAsnyc<UserData>("/api/v1/in/user");
|
||||
}
|
||||
|
||||
public async Task<bool> GetUserDataAsync()
|
||||
{
|
||||
|
@ -101,7 +97,7 @@ public class UserStateService(StorageService _storageService,SecureService _secu
|
|||
{
|
||||
try
|
||||
{
|
||||
await _storageService.RemoveItemAsync("USER_DATA");
|
||||
await _storageService.RemoveItemAsync("UsDt");
|
||||
await _storageService.RemoveItemAsync("IsLogin");
|
||||
Console.WriteLine("사용자 데이터 삭제 성공");
|
||||
isLogin = false;
|
||||
|
@ -114,9 +110,20 @@ public class UserStateService(StorageService _storageService,SecureService _secu
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<(bool success, UserData? userData)> GetUserDataFromServerAsync()
|
||||
{
|
||||
var data = await _APIService.GetConnectServerAsnyc<UserData>("/api/v1/in/user");
|
||||
if (data is { success: true, json: not null })
|
||||
await _storageService.SetItemAsync("UsDt", data.json);
|
||||
return (data.success, data.data);
|
||||
}
|
||||
|
||||
public async Task<(bool success, List<SimpleAcademy>? simpleAcademy)> GetAcademy()
|
||||
{
|
||||
return await _APIService.GetConnectServerAsnyc<List<SimpleAcademy>>("/api/v1/in/user/academy");
|
||||
var data = await _APIService.GetConnectServerAsnyc<List<SimpleAcademy>>("/api/v1/in/user/academy");
|
||||
if (data is { success: true, json: not null })
|
||||
await _storageService.SetItemAsync("UsAcDt", data.json);
|
||||
return (data.success, data.data);
|
||||
}
|
||||
//
|
||||
// var headerValue = await _storageService.GetItemAsync("Web-AM-Connect-Key");
|
||||
|
|
|
@ -1,6 +1,2 @@
|
|||
@page "/am/main"
|
||||
<h3>AcademyMain</h3>
|
||||
|
||||
@code {
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Front.Program.Views.Academy;
|
||||
namespace Front.Program.Views.Academy.Common;
|
||||
|
||||
public partial class LeftSideAcademy : ComponentBase
|
||||
{
|
|
@ -6,7 +6,7 @@ using System.Runtime.InteropServices.JavaScript;
|
|||
using System.Text.Json;
|
||||
using Front.Program.Models;
|
||||
|
||||
namespace Front.Program.Views.Academy;
|
||||
namespace Front.Program.Views.Academy.Common;
|
||||
|
||||
public partial class TopNavAcademy : ComponentBase
|
||||
{
|
Loading…
Reference in New Issue
Block a user