API 테스트 #195
@@ -13,16 +13,16 @@ namespace Studio.Auth
|
||||
|
||||
public class AuthRepository
|
||||
{
|
||||
internal async Task<AuthEntity> Login(string email, string password)
|
||||
internal async Task<AuthEntity> Login(string url,string email, string password)
|
||||
{
|
||||
return await LoginRemote(email, password);
|
||||
return await LoginRemote(url,email, password);
|
||||
}
|
||||
|
||||
private async Task<AuthEntity> LoginRemote(string email, string password)
|
||||
private async Task<AuthEntity> LoginRemote(string url,string email, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await RestAPI.RequestPost<ResponseModel<AuthEntity>>("/api/auth/token",
|
||||
var response = await RestAPI.RequestPost<ResponseModel<AuthEntity>>(url,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
["email"] = email,
|
||||
|
||||
@@ -29,8 +29,7 @@ namespace Studio.Auth
|
||||
};
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public async Task Login(string email, string password)
|
||||
public async Task Login(string url,string email, string password)
|
||||
{
|
||||
// Simulate login
|
||||
if (email.Length > 0 && password.Length > 0)
|
||||
@@ -40,7 +39,7 @@ namespace Studio.Auth
|
||||
State = AuthEntitiState.Loading,
|
||||
};
|
||||
//OnChanged?.Invoke(this, entiti.Copy());
|
||||
entiti = await _repository.Login(email, password);
|
||||
entiti = await _repository.Login(url,email, password);
|
||||
//OnChanged?.Invoke(this, entiti.Copy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace Studio
|
||||
{
|
||||
return await Task.Run<StudioEntityWithState<object>>(async () =>
|
||||
{
|
||||
ResponseModel<object> response = await RestAPI.RequestGet<ResponseModel<object>>(url);
|
||||
ResponseModel<object> response = await RestAPI.RequestPost<ResponseModel<object>>(url);
|
||||
Debug.Log(response);
|
||||
if (response.code == "SUCCESS")
|
||||
return new StudioEntityWithState<object>(APIState.Loaded, response.data,response.requestsize);
|
||||
|
||||
@@ -77,6 +77,14 @@ namespace Studio
|
||||
private Dictionary<string, List<Topic>> topicTable = new();
|
||||
public Dictionary<string, List<Topic>> TopciTable { get { return topicTable; } }
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (repository == null)
|
||||
{
|
||||
Init();
|
||||
ManagerHub.instance.Get<RunManager>().onStop += DisConnectMQTT;
|
||||
}
|
||||
}
|
||||
public void Init()
|
||||
{
|
||||
this.repository = new StudioRepository();
|
||||
@@ -84,12 +92,6 @@ namespace Studio
|
||||
}
|
||||
public void ConnectMQTT(string domain, string port, List<Util.Topic> topics)
|
||||
{
|
||||
if (repository == null)
|
||||
{
|
||||
Init();
|
||||
ManagerHub.instance.Get<RunManager>().onStop += DisConnectMQTT;
|
||||
}
|
||||
|
||||
var conntedInfo = $"MQTT Domain : {domain} , MQTTPORT :{port}";
|
||||
if (!topicTable.ContainsKey(conntedInfo))
|
||||
topicTable.Add(conntedInfo, new());
|
||||
@@ -300,22 +302,43 @@ namespace Studio
|
||||
Debug.Log($"kEY : {key}, Value:{value}");
|
||||
}
|
||||
|
||||
var datas = json["rows"].ToString();
|
||||
//TODO :리팩토링 필요함.
|
||||
var datas = json["data"].ToString();
|
||||
JObject test = JObject.Parse(datas);
|
||||
var list = new List<Dictionary<string, string>>();
|
||||
JArray jarray = JArray.Parse(datas);
|
||||
foreach (JObject obj in jarray.Children())
|
||||
foreach (JProperty te1 in test.Children())
|
||||
{
|
||||
Dictionary<string, string> keyvalue = new();
|
||||
string id = string.Empty;
|
||||
foreach (JProperty prop in obj.Children())
|
||||
string key1 = te1.Name.ToString();
|
||||
string value = te1.Value.ToString();
|
||||
var split = value.ToString().Split('[');
|
||||
var t = string.Empty;
|
||||
|
||||
if(split.Length >1)
|
||||
t = $"[{split[split.Length - 1]}";
|
||||
else if(!split[split.Length - 1].Contains("{"))
|
||||
{
|
||||
string key = prop.Name.ToString();
|
||||
string value = prop.Value.ToString();
|
||||
keyvalue.Add(key, value);
|
||||
Dictionary<string, string> item = new();
|
||||
item.Add(key1, value);
|
||||
list.Add(item);
|
||||
continue;
|
||||
}
|
||||
list.Add(keyvalue);
|
||||
}
|
||||
else
|
||||
t= $"[{split[split.Length - 1]}]";
|
||||
|
||||
JArray jarray = JArray.Parse(t);
|
||||
foreach (JObject obj in jarray.Children())
|
||||
{
|
||||
Dictionary<string, string> keyvalue = new();
|
||||
string id = string.Empty;
|
||||
foreach (JProperty prop in obj.Children())
|
||||
{
|
||||
string key = prop.Name.ToString();
|
||||
string value2 = prop.Value.ToString();
|
||||
keyvalue.Add(key, value2);
|
||||
}
|
||||
list.Add(keyvalue);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,17 +51,16 @@ namespace Studio.UI
|
||||
onTestAPI?.Invoke();
|
||||
|
||||
// API 연결
|
||||
//ConfigConnected.APIDomain = InputField_Domain.text;
|
||||
// ConfigConnected.APIPort = int.Parse(InputField_Port.text);
|
||||
// ConfigConnected.APIDomain = InputField_Domain.text;
|
||||
// ConfigConnected.APIPort = int.Parse(InputField_Port.text);
|
||||
//StudioService.instance.ConnectMQTT();
|
||||
|
||||
await AuthService.Instance.Login("xr", "@dbqlTl1");
|
||||
string loginURL = $"http://{InputField_Domain.text}:{InputField_Port.text}/api/auth/token";
|
||||
await AuthService.Instance.Login(loginURL, "sdi", "@SdiDT1!");
|
||||
|
||||
foreach (UI_InputURLItem item in inputURLItems)
|
||||
{
|
||||
string url = "/api/" + item.InputField_URL.text;
|
||||
string url = $"http://{InputField_Domain.text}:{InputField_Port.text}/api/{item.InputField_URL.text}";
|
||||
await StudioService.instance.LoadBaseData(url);
|
||||
|
||||
//panel_DataRepository = FindAnyObjectByType<Panel_DataRepository>(FindObjectsInactive.Include);
|
||||
//panel_DataRepository.apiConnected = true;
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ namespace Studio.UI
|
||||
var apiSetting = new APISetting();
|
||||
foreach (var item in apiConnectionItems)
|
||||
{
|
||||
var mqttConnection = item.GetAPIConnection();
|
||||
apiSetting.apiConnections.Add(mqttConnection);
|
||||
var apiConnection = item.GetAPIConnection();
|
||||
apiSetting.apiConnections.Add(apiConnection);
|
||||
}
|
||||
return apiSetting;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user