< Summary

Class:MainScripts.DCL.Controllers.HotScenes.IHotScenesController
Assembly:HotScenesController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HotScenes/IHotScenesController.cs
Covered lines:10
Uncovered lines:9
Coverable lines:19
Total lines:177
Line coverage:52.6% (10 of 19)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:3
Method coverage:100% (3 of 3)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OnBeforeSerialize()0%3.793055.56%
OnAfterDeserialize()0%3.793055.56%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HotScenes/IHotScenesController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL;
 3using DCLServices.Lambdas;
 4using Newtonsoft.Json;
 5using System;
 6using System.Collections.Generic;
 7using System.Globalization;
 8using System.Threading;
 9using UnityEngine;
 10
 11namespace MainScripts.DCL.Controllers.HotScenes
 12{
 13    /// <summary>
 14    /// Despite this service is called `HotScenesController` it is responsible to fetch users outside of comms region,
 15    /// so it is essentially `ColdScenesController`
 16    /// </summary>
 17    public interface IHotScenesController : IService
 18    {
 19        UniTask<IReadOnlyList<HotSceneInfo>> GetHotScenesListAsync(CancellationToken cancellationToken);
 20        UniTask<IReadOnlyList<HotWorldInfo.WorldInfo>> GetHotWorldsListAsync(CancellationToken cancellationToken);
 21
 22        [Serializable]
 23        class HotSceneInfo
 24        {
 25            [Serializable]
 26            public class Realm
 27            {
 28                public string serverName;
 29                public string layer;
 30                public int usersCount;
 31                public int maxUsers;
 32                public Vector2Int[] userParcels;
 33            }
 34
 35            public string id;
 36            public string name;
 37            public string creator;
 38            public string description;
 39            public string thumbnail;
 40            public Vector2Int baseCoords;
 41            public Vector2Int[] parcels;
 42            public int usersTotalCount;
 43            public Realm[] realms;
 44        }
 45
 46        [Serializable]
 47        class HotWorldInfo
 48        {
 49            [Serializable]
 50            public class WorldInfo
 51            {
 52                public string worldName;
 53                public int users;
 54            }
 55
 56            [Serializable]
 57            public class WorldData
 58            {
 59                public int totalUsers;
 60                public WorldInfo[] perWorld;
 61            }
 62
 63            public WorldData data;
 64            public string lastUpdated;
 65
 66        }
 67
 68        // TODO: This class should be moved to the PlacesAPIService folder
 69        [Serializable]
 70        public class PlaceInfo : ISerializationCallbackReceiver
 71        {
 72            [Serializable]
 73            public class Realm
 74            {
 75                public string serverName;
 76                public string layer;
 77                public string url;
 78                public int usersCount;
 79                public int maxUsers;
 80                public Vector2Int[] userParcels;
 81            }
 82            public string id;
 83            public string title;
 84            public string description;
 85            public string image;
 86            public string owner;
 87            public string[] tags;
 88            [SerializeField] private string[] positions;
 89            public string world_name;
 90
 91            public Vector2Int[] Positions;
 92
 93            public string base_position;
 94            public string contact_name;
 95            public string contact_email;
 96            public string content_rating;
 97            public bool disabled;
 98            public string disabled_at;
 99            public string created_at;
 100            public string updated_at;
 101            public string deployed_at;
 102            public int favorites;
 103            public int likes;
 104            public int dislikes;
 105            public string[] categories;
 106            public bool highlighted;
 107            public string highlighted_image;
 108            public bool featured;
 109            public string featured_image;
 110            public bool user_favorite;
 111            public bool user_like;
 112            public bool user_dislike;
 113            public int user_count;
 114            public int user_visits;
 115            public Realm[] realms_detail;
 116
 117            public string like_rate;
 118
 119            [JsonIgnore]
 120            public float? like_rate_as_float
 121            {
 122                get
 123                {
 1124                    if (string.IsNullOrEmpty(like_rate))
 1125                        return null;
 126
 0127                    if (float.TryParse(like_rate, NumberStyles.Float, CultureInfo.InvariantCulture, out float result))
 0128                        return result;
 129
 0130                    return null;
 131                }
 132            }
 133
 134            public void OnBeforeSerialize()
 135            {
 2206136                if (Positions == null)
 137                {
 0138                    positions = null;
 0139                    return;
 140                }
 141
 2206142                positions = new string[Positions.Length];
 4412143                for (int i = 0; i < Positions.Length; i++)
 0144                    positions[i] = $"{Positions[i].x},{Positions[i].y}";
 2206145            }
 146
 147            public void OnAfterDeserialize()
 148            {
 2217149                if (positions == null)
 0150                    return;
 2217151                Positions = new Vector2Int[positions.Length];
 4434152                for (int i = 0; i < positions.Length; i++)
 153                {
 0154                    string[] split = positions[i].Split(',');
 0155                    Positions[i] = new Vector2Int(int.Parse(split[0]), int.Parse(split[1]));
 156                }
 2217157            }
 158        }
 159
 160        // TODO: This class should be moved to the PlacesAPIService folder
 161        [Serializable]
 162        public class PlacesAPIResponse : PaginatedResponse
 163        {
 164            public bool ok;
 165            public int total;
 166            public List<PlaceInfo> data;
 167        }
 168
 169        // TODO: This class should be moved to the PlacesAPIService folder
 170        [Serializable]
 171        public class PlacesAPIGetParcelResponse
 172        {
 173            public bool ok;
 174            public PlaceInfo data;
 175        }
 176    }
 177}