mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-26 15:08:39 +00:00
Add user endpoints
This commit is contained in:
parent
c806b3bf6b
commit
e95f3a0439
5 changed files with 107 additions and 3 deletions
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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue