diff --git a/ProjectLighthouse/Controllers/SlotsController.cs b/ProjectLighthouse/Controllers/SlotsController.cs index 02ecc817..f2915de3 100644 --- a/ProjectLighthouse/Controllers/SlotsController.cs +++ b/ProjectLighthouse/Controllers/SlotsController.cs @@ -1,15 +1,28 @@ +using System; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using ProjectLighthouse.Serialization; +using ProjectLighthouse.Types; namespace ProjectLighthouse.Controllers { [ApiController] - [Route("LITTLEBIGPLANETPS3_XML/slots")] + [Route("LITTLEBIGPLANETPS3_XML/")] [Produces("text/xml")] public class SlotsController : ControllerBase { - [HttpGet("by")] + [HttpGet("slots/by")] public IActionResult SlotsBy() { - return this.Ok(LbpSerializer.BlankElement("slots")); + string response = Enumerable.Aggregate(new Database().Slots, string.Empty, (current, slot) => current + slot.Serialize()); + + return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "total", 1)); + } + + [HttpGet("s/user/{id:int}")] + public async Task SUser(int id) { + Slot slot = await new Database().Slots.FirstOrDefaultAsync(s => s.SlotId == id); + + return this.Ok(slot.Serialize()); } } } \ No newline at end of file diff --git a/ProjectLighthouse/Properties/launchSettings.json b/ProjectLighthouse/Properties/launchSettings.json index d5772d10..ce1164e7 100644 --- a/ProjectLighthouse/Properties/launchSettings.json +++ b/ProjectLighthouse/Properties/launchSettings.json @@ -18,7 +18,7 @@ "ProjectLighthouse": { "commandName": "Project", "dotnetRunMessages": "true", - "applicationUrl": "http://localhost:10060;https://localhost:10061", + "applicationUrl": "http://localhost:10060;https://localhost:10061;http://localhost:1062", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "LIGHTHOUSE_DB_CONNECTION_STRING": "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse" diff --git a/ProjectLighthouse/Types/Slot.cs b/ProjectLighthouse/Types/Slot.cs index f21ed725..f9dc621c 100644 --- a/ProjectLighthouse/Types/Slot.cs +++ b/ProjectLighthouse/Types/Slot.cs @@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Xml.Serialization; +using ProjectLighthouse.Serialization; namespace ProjectLighthouse.Types { /// @@ -79,5 +80,26 @@ namespace ProjectLighthouse.Types { [XmlElement("moveRequired")] public bool MoveRequired { get; set; } + + public string Serialize() { + string slotData = LbpSerializer.StringElement("name", Name) + + LbpSerializer.StringElement("id", SlotId) + + LbpSerializer.StringElement("game", 1) + + LbpSerializer.StringElement("npHandle", "jvyden") + + LbpSerializer.StringElement("description", Description) + + LbpSerializer.StringElement("icon", IconHash) + + LbpSerializer.StringElement("resource", Resource) + + LbpSerializer.StringElement("location", Location.Serialize()) + + LbpSerializer.StringElement("initiallyLocked", InitiallyLocked) + + LbpSerializer.StringElement("isSubLevel", SubLevel) + + LbpSerializer.StringElement("isLBP1Only", Lbp1Only) + + LbpSerializer.StringElement("shareable", Shareable) + + LbpSerializer.StringElement("background", BackgroundHash) + + LbpSerializer.StringElement("minPlayers", MinimumPlayers) + + LbpSerializer.StringElement("maxPlayers", MaximumPlayers) + + LbpSerializer.StringElement("moveRequired", MoveRequired); + + return LbpSerializer.TaggedStringElement("slot", slotData, "type", "user"); + } } } \ No newline at end of file