diff --git a/ProjectLighthouse.sln.DotSettings b/ProjectLighthouse.sln.DotSettings index 385c8365..8176a998 100644 --- a/ProjectLighthouse.sln.DotSettings +++ b/ProjectLighthouse.sln.DotSettings @@ -89,6 +89,7 @@ True True True + True True True True @@ -100,6 +101,7 @@ True True True + True True True True diff --git a/ProjectLighthouse/Controllers/CollectionController.cs b/ProjectLighthouse/Controllers/CollectionController.cs new file mode 100644 index 00000000..590ebd8a --- /dev/null +++ b/ProjectLighthouse/Controllers/CollectionController.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using LBPUnion.ProjectLighthouse.Serialization; +using LBPUnion.ProjectLighthouse.Types.Categories; +using Microsoft.AspNetCore.Mvc; + +namespace LBPUnion.ProjectLighthouse.Controllers +{ + [ApiController] + [Route("LITTLEBIGPLANETPS3_XML/")] + [Produces("text/xml")] + public class CollectionController : ControllerBase + { + private readonly Database database; + + public CollectionController(Database database) + { + this.database = database; + } + + [HttpGet("user/{username}/playlists")] + public IActionResult GetUserPlaylists(string username) => this.Ok(); + + [HttpGet("searches")] + [HttpGet("genres")] + public async Task GenresAndSearches() + { + List categories = new() + { + new TeamPicksCategory(), + new TeamPicksCategory(), + new NewestLevelsCategory(), + new NewestLevelsCategory(), + }; + + string categoriesSerialized = categories.Aggregate(string.Empty, (current, category) => current + category.Serialize(this.database)); + + return this.Ok + ( + LbpSerializer.TaggedStringElement + ( + "categories", + categoriesSerialized, + new Dictionary + { + { + "hint", "" + }, + { + "hint_start", 1 + }, + { + "total", categories.Count + }, + } + ) + ); + } + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Controllers/UserController.cs b/ProjectLighthouse/Controllers/UserController.cs index 02bf2355..b87336a6 100644 --- a/ProjectLighthouse/Controllers/UserController.cs +++ b/ProjectLighthouse/Controllers/UserController.cs @@ -58,9 +58,6 @@ namespace LBPUnion.ProjectLighthouse.Controllers return this.Ok(LbpSerializer.StringElement("users", serialized)); } - [HttpGet("user/{username}/playlists")] - public IActionResult GetUserPlaylists(string username) => this.Ok(); - [HttpPost("updateUser")] public async Task UpdateUser() { diff --git a/ProjectLighthouse/Types/Categories/Category.cs b/ProjectLighthouse/Types/Categories/Category.cs new file mode 100644 index 00000000..945aeffe --- /dev/null +++ b/ProjectLighthouse/Types/Categories/Category.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.Linq; +using System.Xml.Serialization; +using LBPUnion.ProjectLighthouse.Serialization; +using LBPUnion.ProjectLighthouse.Types.Levels; + +namespace LBPUnion.ProjectLighthouse.Types.Categories +{ + [XmlType("category")] + [XmlRoot("category")] + public abstract class Category + { + [XmlElement("name")] + public abstract string Name { get; set; } + + [XmlElement("description")] + public abstract string Description { get; set; } + + [XmlElement("icon")] + public abstract string IconHash { get; set; } + + [XmlIgnore] + public abstract string Endpoint { get; set; } + + [XmlElement("url")] + public string IngameEndpoint { + get => $"/searches/{this.Endpoint}"; + set => this.Endpoint = value.Replace("/searches/", ""); + } + + public abstract IEnumerable Slots(Database database); + + public string Serialize(Database database) + { + string slots = this.Slots(database).Aggregate(string.Empty, (current, slot) => current + slot.Serialize()); + + return LbpSerializer.StringElement + ( + "category", + LbpSerializer.StringElement("name", this.Name) + + LbpSerializer.StringElement("description", this.Description) + + LbpSerializer.StringElement("url", this.IngameEndpoint) + + LbpSerializer.StringElement("results", slots) + + LbpSerializer.StringElement("icon", IconHash) + ); + } + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Types/Categories/NewestLevelsCategory.cs b/ProjectLighthouse/Types/Categories/NewestLevelsCategory.cs new file mode 100644 index 00000000..fa01f922 --- /dev/null +++ b/ProjectLighthouse/Types/Categories/NewestLevelsCategory.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Linq; +using LBPUnion.ProjectLighthouse.Types.Levels; + +namespace LBPUnion.ProjectLighthouse.Types.Categories +{ + public class NewestLevelsCategory : Category + { + public override string Name { get; set; } = "Newest Levels"; + public override string Description { get; set; } = "Levels recently published"; + public override string IconHash { get; set; } = "g820623"; + public override string Endpoint { get; set; } = "newest"; + public override IEnumerable Slots(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).Take(1); + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Types/Categories/TeamPicksCategory.cs b/ProjectLighthouse/Types/Categories/TeamPicksCategory.cs new file mode 100644 index 00000000..c33b5afd --- /dev/null +++ b/ProjectLighthouse/Types/Categories/TeamPicksCategory.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Linq; +using LBPUnion.ProjectLighthouse.Types.Levels; + +namespace LBPUnion.ProjectLighthouse.Types.Categories +{ + public class TeamPicksCategory : Category + { + public override string Name { get; set; } = "Team Picks"; + public override string Description { get; set; } = "Levels given awards by your instance admin"; + public override string IconHash { get; set; } = "g820626"; + public override string Endpoint { get; set; } = "team_picks"; + public override IEnumerable Slots(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).Where(s => s.TeamPick).Take(1); + } +} \ No newline at end of file