diff --git a/ProjectLighthouse.sln.DotSettings b/ProjectLighthouse.sln.DotSettings index 619794f7..3c18bfb3 100644 --- a/ProjectLighthouse.sln.DotSettings +++ b/ProjectLighthouse.sln.DotSettings @@ -1,4 +1,6 @@  True True - True \ No newline at end of file + True + True + True \ No newline at end of file diff --git a/ProjectLighthouse/Controllers/LoginController.cs b/ProjectLighthouse/Controllers/LoginController.cs index cb99b68f..49d5ddde 100644 --- a/ProjectLighthouse/Controllers/LoginController.cs +++ b/ProjectLighthouse/Controllers/LoginController.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Primitives; using ProjectLighthouse.Types; @@ -12,9 +11,15 @@ namespace ProjectLighthouse.Controllers { [HttpGet] [HttpPost] public IActionResult Post() { + if(!this.Request.Query.TryGetValue("titleID", out StringValues titleValues)) { + this.BadRequest(); + }; + + string titleId = titleValues[0]; + return this.Ok(new LoginResult { AuthTicket = "d2c6bbec59162a1e786ed24ad95f2b73", - LbpEnvVer = "rLBP_Cepheus" + LbpEnvVer = "ProjectLighthouse" }.Serialize()); } } diff --git a/ProjectLighthouse/Controllers/UserController.cs b/ProjectLighthouse/Controllers/UserController.cs new file mode 100644 index 00000000..00d10f36 --- /dev/null +++ b/ProjectLighthouse/Controllers/UserController.cs @@ -0,0 +1,59 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Xml; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using ProjectLighthouse.Types; + +namespace ProjectLighthouse.Controllers { + [ApiController] + [Route("LITTLEBIGPLANETPS3_XML/")] + [Produces("text/xml")] + public class UserController : ControllerBase { + [HttpGet("user/{username}")] + public async Task GetUser(string username) { + User user = await new Database().Users.FirstOrDefaultAsync(u => u.Username == username); + + if(user == null) return this.NotFound(); + return this.Ok(user.Serialize()); + } + + [HttpPost("updateUser")] + public async Task UpdateUser() { + await using Database database = new(); + User user = await database.Users.Where(u => u.Username == "jvyden").FirstOrDefaultAsync(); + + if(user == null) return this.BadRequest(); + + XmlReaderSettings settings = new() { + Async = true + }; + + using(XmlReader reader = XmlReader.Create(Request.Body, settings)) { + string currentElement = ""; + while(await reader.ReadAsync()) { + switch(reader.NodeType) { + case XmlNodeType.Element: + currentElement = reader.Name; + break; + case XmlNodeType.Text: + switch(currentElement) { + case "biography": { + user.Biography = await reader.GetValueAsync(); + break; + } + } + break; + case XmlNodeType.EndElement: + currentElement = ""; + break; + } + } + } + + await database.SaveChangesAsync(); + return this.Ok(); + } + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Startup.cs b/ProjectLighthouse/Startup.cs index f8ecda62..aadc22ee 100644 --- a/ProjectLighthouse/Startup.cs +++ b/ProjectLighthouse/Startup.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; @@ -39,8 +41,13 @@ namespace ProjectLighthouse { // Example: "200: GET /LITTLEBIGPLANETPS3_XML/news" // Example: "404: GET /asdasd?query=osucookiezi727ppbluezenithtopplayhdhr" app.Use(async (context, next) => { + context.Request.EnableBuffering(); // Allows us to reset the position of Request.Body for later logging await next(); // Handle the request so we can get the status code from it Console.WriteLine($"{context.Response.StatusCode}: {context.Request.Method} {context.Request.Path}{context.Request.QueryString}"); + if(context.Request.Method == "POST") { + context.Request.Body.Position = 0; + Console.WriteLine(await new StreamReader(context.Request.Body).ReadToEndAsync()); + } }); app.UseRouting(); diff --git a/ProjectLighthouse/Types/Comment.cs b/ProjectLighthouse/Types/Comment.cs new file mode 100644 index 00000000..55f1f9b0 --- /dev/null +++ b/ProjectLighthouse/Types/Comment.cs @@ -0,0 +1,31 @@ +using System.ComponentModel.DataAnnotations; +using ProjectLighthouse.Serialization; + +namespace ProjectLighthouse.Types { + public class Comment { + [Key] public int CommentId { get; set; } + + public string Username { get; set; } + public long Timestamp { get; set; } + public string Message { get; set; } + public int ThumbsUp { get; set; } + public int ThumbsDown { get; set; } + + private string serialize() { + return LbpSerializer.StringElement("id", CommentId) + + LbpSerializer.StringElement("npHandle", Username) + + LbpSerializer.StringElement("timestamp", Timestamp) + + LbpSerializer.StringElement("message", Message) + + LbpSerializer.StringElement("thumbsup", ThumbsUp) + + LbpSerializer.StringElement("thumbsdown", ThumbsDown); + } + + public string Serialize(int yourThumb) { + return LbpSerializer.StringElement("comment", this.serialize() + LbpSerializer.StringElement("yourthumb", yourThumb)); + } + + public string Serialize() { + return LbpSerializer.StringElement("comment", this.serialize()); + } + } +} \ No newline at end of file