mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 18:18:39 +00:00
Rearrange methods so we can get serialized users without repeating code
This commit is contained in:
parent
41be6285dd
commit
e510857383
1 changed files with 38 additions and 6 deletions
|
@ -5,6 +5,7 @@ using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using LBPUnion.ProjectLighthouse.Serialization;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
@ -24,18 +25,49 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
this.database = database;
|
this.database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("user/{username}")]
|
public async Task<string> GetSerializedUser(string username)
|
||||||
public async Task<IActionResult> GetUser(string username)
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
User user = await this.database.Users.Include(u => u.Location).FirstOrDefaultAsync(u => u.Username == username);
|
User user = await this.database.Users.Include(u => u.Location).FirstOrDefaultAsync(u => u.Username == username);
|
||||||
|
return user.Serialize();
|
||||||
|
}
|
||||||
|
catch (NullReferenceException)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("play/user/{userId}")]
|
||||||
|
public async Task<IActionResult> Play([FromQuery] bool lbp2)
|
||||||
|
{
|
||||||
|
string bodyString = await new StreamReader(this.Request.Body).ReadToEndAsync();
|
||||||
|
Console.WriteLine(bodyString);
|
||||||
|
return this.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("user/{username}")]
|
||||||
|
public async Task<IActionResult> GetUser(string username) {
|
||||||
|
string? user = await this.GetSerializedUser(username);
|
||||||
if (user == null) return this.NotFound();
|
if (user == null) return this.NotFound();
|
||||||
|
return this.Ok(user);
|
||||||
return this.Ok(user.Serialize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("users")]
|
[HttpGet("users")]
|
||||||
public async Task<IActionResult> GetUserAlt([FromQuery] string u) => await this.GetUser(u);
|
public async Task<IActionResult> GetUserAlt([FromQuery] string[] u)
|
||||||
|
{
|
||||||
|
List<Task<string>> tasks = new();
|
||||||
|
foreach (string userId in u)
|
||||||
|
{
|
||||||
|
tasks.Add(this.GetSerializedUser(userId));
|
||||||
|
}
|
||||||
|
await Task.WhenAll(tasks).ConfigureAwait(true);
|
||||||
|
|
||||||
|
string serialized = tasks.Aggregate(string.Empty, (current, u) => u.Result == null ? current : current + u);
|
||||||
|
|
||||||
|
return this.Ok(LbpSerializer.StringElement("users", serialized));
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("user/{username}/playlists")]
|
[HttpGet("user/{username}/playlists")]
|
||||||
public IActionResult GetUserPlaylists(string username) => this.Ok();
|
public IActionResult GetUserPlaylists(string username) => this.Ok();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue