Implement LBP3 community tab

This commit is contained in:
jvyden 2021-12-27 20:37:39 -05:00
commit d6a0b7fd9c
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
6 changed files with 141 additions and 3 deletions

View file

@ -89,6 +89,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Affero/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=airfryer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=BCAS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=BCES/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=BCET/@EntryIndexedValue">True</s:Boolean>
@ -100,6 +101,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=ezoiar/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=farc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=friendscores/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ingame/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Kettu/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=lbpme/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=LBPU/@EntryIndexedValue">True</s:Boolean>

View file

@ -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<IActionResult> GenresAndSearches()
{
List<Category> 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<string, object>
{
{
"hint", ""
},
{
"hint_start", 1
},
{
"total", categories.Count
},
}
)
);
}
}
}

View file

@ -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<IActionResult> UpdateUser()
{

View file

@ -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<Slot> 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)
);
}
}
}

View file

@ -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<Slot> Slots(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).Take(1);
}
}

View file

@ -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<Slot> Slots(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).Where(s => s.TeamPick).Take(1);
}
}