mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-24 14:11:29 +00:00
Add user endpoints
This commit is contained in:
parent
c806b3bf6b
commit
e95f3a0439
5 changed files with 107 additions and 3 deletions
|
@ -1,4 +1,6 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=ezoiar/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=lbpme/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=lolcatftw/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=lolcatftw/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=thumbsup/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=yourthumb/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
59
ProjectLighthouse/Controllers/UserController.cs
Normal file
59
ProjectLighthouse/Controllers/UserController.cs
Normal file
|
@ -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<IActionResult> 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<IActionResult> 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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
31
ProjectLighthouse/Types/Comment.cs
Normal file
31
ProjectLighthouse/Types/Comment.cs
Normal file
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue