From da4e29d0afa12abbbb6e3b94f0451009119ddba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EC=98=81=EB=AF=BC?= <117150306+jym04@users.noreply.github.com> Date: Tue, 1 Jul 2025 15:56:24 +0900 Subject: [PATCH] =?UTF-8?q?API=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/Studio/Connect/AuthRepository.cs | 8 +-- Assets/Scripts/Studio/Connect/AuthService.cs | 5 +- .../Studio/Connect/StudioRepository.cs | 2 +- .../Scripts/Studio/Connect/StudioService.cs | 57 +++++++++++++------ .../Studio/UI/Elements/UI_APIConnection.cs | 11 ++-- .../Studio/UI/Panel/Panel_APISetting.cs | 4 +- 6 files changed, 54 insertions(+), 33 deletions(-) diff --git a/Assets/Scripts/Studio/Connect/AuthRepository.cs b/Assets/Scripts/Studio/Connect/AuthRepository.cs index bbdde9a5..49a7af76 100644 --- a/Assets/Scripts/Studio/Connect/AuthRepository.cs +++ b/Assets/Scripts/Studio/Connect/AuthRepository.cs @@ -13,16 +13,16 @@ namespace Studio.Auth public class AuthRepository { - internal async Task Login(string email, string password) + internal async Task Login(string url,string email, string password) { - return await LoginRemote(email, password); + return await LoginRemote(url,email, password); } - private async Task LoginRemote(string email, string password) + private async Task LoginRemote(string url,string email, string password) { try { - var response = await RestAPI.RequestPost>("/api/auth/token", + var response = await RestAPI.RequestPost>(url, new Dictionary { ["email"] = email, diff --git a/Assets/Scripts/Studio/Connect/AuthService.cs b/Assets/Scripts/Studio/Connect/AuthService.cs index 550a19ef..6a4b7e38 100644 --- a/Assets/Scripts/Studio/Connect/AuthService.cs +++ b/Assets/Scripts/Studio/Connect/AuthService.cs @@ -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()); } } diff --git a/Assets/Scripts/Studio/Connect/StudioRepository.cs b/Assets/Scripts/Studio/Connect/StudioRepository.cs index 0f0518cc..ab4ac93c 100644 --- a/Assets/Scripts/Studio/Connect/StudioRepository.cs +++ b/Assets/Scripts/Studio/Connect/StudioRepository.cs @@ -85,7 +85,7 @@ namespace Studio { return await Task.Run>(async () => { - ResponseModel response = await RestAPI.RequestGet>(url); + ResponseModel response = await RestAPI.RequestPost>(url); Debug.Log(response); if (response.code == "SUCCESS") return new StudioEntityWithState(APIState.Loaded, response.data,response.requestsize); diff --git a/Assets/Scripts/Studio/Connect/StudioService.cs b/Assets/Scripts/Studio/Connect/StudioService.cs index b77849f9..0b3874fa 100644 --- a/Assets/Scripts/Studio/Connect/StudioService.cs +++ b/Assets/Scripts/Studio/Connect/StudioService.cs @@ -77,6 +77,14 @@ namespace Studio private Dictionary> topicTable = new(); public Dictionary> TopciTable { get { return topicTable; } } + private void Start() + { + if (repository == null) + { + Init(); + ManagerHub.instance.Get().onStop += DisConnectMQTT; + } + } public void Init() { this.repository = new StudioRepository(); @@ -84,12 +92,6 @@ namespace Studio } public void ConnectMQTT(string domain, string port, List topics) { - if (repository == null) - { - Init(); - ManagerHub.instance.Get().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>(); - JArray jarray = JArray.Parse(datas); - foreach (JObject obj in jarray.Children()) + foreach (JProperty te1 in test.Children()) { - Dictionary 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 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 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; } diff --git a/Assets/Scripts/Studio/UI/Elements/UI_APIConnection.cs b/Assets/Scripts/Studio/UI/Elements/UI_APIConnection.cs index f391521d..e0de936b 100644 --- a/Assets/Scripts/Studio/UI/Elements/UI_APIConnection.cs +++ b/Assets/Scripts/Studio/UI/Elements/UI_APIConnection.cs @@ -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(FindObjectsInactive.Include); //panel_DataRepository.apiConnected = true; } diff --git a/Assets/Scripts/Studio/UI/Panel/Panel_APISetting.cs b/Assets/Scripts/Studio/UI/Panel/Panel_APISetting.cs index 624a7aa6..f5b07b23 100644 --- a/Assets/Scripts/Studio/UI/Panel/Panel_APISetting.cs +++ b/Assets/Scripts/Studio/UI/Panel/Panel_APISetting.cs @@ -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; } -- 2.48.1.windows.1