From e654e1cb66d9a5bce6676f730e7e9707adf7c850 Mon Sep 17 00:00:00 2001 From: Ignacio Gomez Date: Fri, 27 Jun 2025 23:14:49 -0600 Subject: [PATCH] Added final adjusment for demo --- Assets/API/FurnitureFetcher.cs | 114 +++++++++++++++++---- Assets/API/Models/FurnitureItem.cs | 9 ++ Assets/UI Toolkit/FurnitureItem.uxml | 9 +- Assets/UI Toolkit/MainScreen.uxml | 6 +- Assets/UI Toolkit/Styles/FurnitureItem.uss | 14 +++ Packages/manifest.json | 1 + Packages/packages-lock.json | 2 +- ProjectSettings/ProjectSettings.asset | 8 -- 8 files changed, 129 insertions(+), 34 deletions(-) diff --git a/Assets/API/FurnitureFetcher.cs b/Assets/API/FurnitureFetcher.cs index 6aac1a0..6f7bc33 100644 --- a/Assets/API/FurnitureFetcher.cs +++ b/Assets/API/FurnitureFetcher.cs @@ -1,16 +1,34 @@ using System.Collections; -using System.Collections.Generic; -using System.Text; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UIElements; +using Newtonsoft.Json; +using System.Collections.Generic; +using System.Globalization; class FurnitureFetcher : MonoBehaviour { public VisualTreeAsset itemTemplate; public UIDocument uiDocument; - public static string API_URL = "http://100.123.31.103:5102/api/v1/FurnitureVariant/GetByIds"; + public static string API_URL = "https://localhost:7223/api/v1/FurnitureVariant/GetAll"; + + private static readonly Dictionary CurrencySymbols = new() + { + { "USD", "$" }, + { "EUR", "€" }, + { "GBP", "£" }, + { "JPY", "¥" }, + { "MXN", "$" }, + { "CAD", "$" }, + { "BRL", "R$" }, + { "ARS", "$" }, + { "CLP", "$" }, + { "COP", "$" }, + { "CNY", "¥" }, + { "INR", "₹" } + }; + private void Awake() { @@ -19,38 +37,84 @@ class FurnitureFetcher : MonoBehaviour IEnumerator GetFurnitureData() { - Debug.Log($"API URL: {API_URL}"); - List variantIds = new() - { - "ab6fd51f-81f0-490d-b713-8d4f3de61a58", - "1f3b348f-b3ee-4985-b76f-7f6d61f2c835" - }; - - FurnitureIdsRequest data = new() { ids = variantIds }; - string json = JsonUtility.ToJson(data); - - using UnityWebRequest request = new(API_URL, "POST"); - byte[] bodyRaw = Encoding.UTF8.GetBytes(json); - request.uploadHandler = new UploadHandlerRaw(bodyRaw); + using UnityWebRequest request = UnityWebRequest.Get(API_URL); request.downloadHandler = new DownloadHandlerBuffer(); - request.SetRequestHeader("Content-Type", "application/json"); yield return request.SendWebRequest(); + string rawResponse = request.downloadHandler.text; + //Debug.Log("📦 RAW RESPONSE:\n" + rawResponse); + if (request.result == UnityWebRequest.Result.Success) { - string wrappedJson = "{\"items\":" + request.downloadHandler.text + "}"; - FurnitureVariantList list = JsonUtility.FromJson(wrappedJson); + string wrappedJson = "{\"items\":" + rawResponse + "}"; + FurnitureVariantList list; + + try + { + list = JsonConvert.DeserializeObject(wrappedJson); + } + catch (System.Exception ex) + { + Debug.LogError("❌ Error al deserializar JSON: " + ex.Message); + yield break; + } var root = uiDocument.rootVisualElement; var scrollView = root.Q("furniture-list"); + scrollView.Clear(); + foreach (var variant in list.items) { VisualElement item = itemTemplate.CloneTree(); item.Q