2024-05-28 15:29:18 +02:00
|
|
|
using System.Diagnostics;
|
|
|
|
using Foxnouns.Backend.Database;
|
|
|
|
using Foxnouns.Backend.Middleware;
|
2024-05-28 17:09:50 +02:00
|
|
|
using Foxnouns.Backend.Services;
|
2024-05-28 15:29:18 +02:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
namespace Foxnouns.Backend.Controllers;
|
|
|
|
|
|
|
|
[Route("/api/v2/users")]
|
2024-05-28 17:09:50 +02:00
|
|
|
public class UsersController(DatabaseContext db, UserRendererService userRendererService) : ApiControllerBase
|
2024-05-28 15:29:18 +02:00
|
|
|
{
|
|
|
|
[HttpGet("{userRef}")]
|
|
|
|
public async Task<IActionResult> GetUser(string userRef)
|
|
|
|
{
|
|
|
|
var user = await db.ResolveUserAsync(userRef);
|
2024-05-30 16:59:40 +02:00
|
|
|
return Ok(await userRendererService.RenderUserAsync(user, selfUser: User));
|
2024-05-28 15:29:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("@me")]
|
|
|
|
[Authorize("identify")]
|
2024-05-30 16:59:40 +02:00
|
|
|
public async Task<IActionResult> GetMe()
|
2024-05-28 15:29:18 +02:00
|
|
|
{
|
2024-05-30 16:59:40 +02:00
|
|
|
var user = await db.ResolveUserAsync(User!.Id);
|
|
|
|
return Ok(await userRendererService.RenderUserAsync(user, selfUser: User));
|
2024-05-28 15:29:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPatch("@me")]
|
|
|
|
public Task<IActionResult> UpdateUser([FromBody] UpdateUserRequest req)
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
public record UpdateUserRequest(string? Username, string? DisplayName);
|
|
|
|
}
|