Skip to content

Commit

Permalink
Add all category filters in the PLACES section
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrade-dcl committed Nov 21, 2023
1 parent 7b28638 commit 5830037
Show file tree
Hide file tree
Showing 12 changed files with 990 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;

namespace DCLServices.PlacesAPIService
{
[Serializable]
public class PlaceCategoriesAPIResponse
{
public bool ok;
public List<PlaceCategoryInfo> data;
}

[Serializable]
public class PlaceCategoryInfo
{
public string name;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface IPlacesAPIClient
UniTask<List<IHotScenesController.PlaceInfo>> GetAllFavorites(CancellationToken ct);
UniTask<List<IHotScenesController.PlaceInfo>> GetPlacesByCoordsList(List<Vector2Int> coordsList, CancellationToken ct);
UniTask ReportPlace(PlaceContentReportPayload placeContentReportPayload, CancellationToken ct);
UniTask<List<PlaceCategoryInfo>> GetPlaceCategories(CancellationToken ct);


UniTask SetPlaceFavorite(string placeUUID, bool isFavorite, CancellationToken ct);
Expand All @@ -33,6 +34,7 @@ public class PlacesAPIClient: IPlacesAPIClient
private const string BASE_URL_ZONE = "https://places.decentraland.zone/api/places";
private const string POI_URL = "https://dcl-lists.decentraland.org/pois";
private const string CONTENT_MODERATION_REPORT_URL = "https://places.decentraland.org/api/report";
private const string PLACE_CATEGORIES_URL = "https://places.decentraland.org/api/categories";
private readonly IWebRequestController webRequestController;

public PlacesAPIClient(IWebRequestController webRequestController)
Expand Down Expand Up @@ -232,5 +234,19 @@ public async UniTask ReportPlace(PlaceContentReportPayload placeContentReportPay
if (putResult.result != UnityWebRequest.Result.Success)
throw new Exception($"Error reporting place:\n{putResult.error}");
}

public async UniTask<List<PlaceCategoryInfo>> GetPlaceCategories(CancellationToken ct)
{
UnityWebRequest result = await webRequestController.GetAsync(PLACE_CATEGORIES_URL, isSigned: false, cancellationToken: ct);
var response = Utils.SafeFromJson<PlaceCategoriesAPIResponse>(result.downloadHandler.text);

if (response == null)
throw new Exception($"Error parsing get place categories response:\n{result.downloadHandler.text}");

if (response.data == null)
throw new Exception($"No place categories info retrieved:\n{result.downloadHandler.text}");

return response.data;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public interface IPlacesAPIService: IService
UniTask<IReadOnlyList<string>> GetPointsOfInterestCoords(CancellationToken ct, bool renewCache = false);

UniTask ReportPlace(PlaceContentReportPayload placeContentReportPayload, CancellationToken ct);
UniTask<List<PlaceCategoryInfo>> GetPlaceCategories(CancellationToken ct, bool renewCache = false);
}

public class PlacesAPIService : IPlacesAPIService, ILambdaServiceConsumer<IHotScenesController.PlacesAPIResponse>
Expand All @@ -45,6 +46,7 @@ public class PlacesAPIService : IPlacesAPIService, ILambdaServiceConsumer<IHotSc
internal readonly Dictionary<string, IHotScenesController.PlaceInfo> placesById = new ();
internal readonly Dictionary<Vector2Int, IHotScenesController.PlaceInfo> placesByCoords = new ();
private List<string> pointsOfInterestCoords;
private List<PlaceCategoryInfo> placeCategories;

//Favorites
internal bool composedFavoritesDirty = true;
Expand Down Expand Up @@ -298,6 +300,14 @@ public async UniTask<IReadOnlyList<string>> GetPointsOfInterestCoords(Cancellati
public async UniTask ReportPlace(PlaceContentReportPayload placeContentReportPayload, CancellationToken ct) =>
await client.ReportPlace(placeContentReportPayload, ct);

public async UniTask<List<PlaceCategoryInfo>> GetPlaceCategories(CancellationToken ct, bool renewCache = false)
{
if (renewCache || placeCategories == null)
placeCategories = await client.GetPlaceCategories(ct);

return placeCategories;
}

public void Dispose()
{
disposeCts.SafeCancelAndDispose();
Expand Down
Loading

0 comments on commit 5830037

Please sign in to comment.