Foxnouns.NET/Foxnouns.Backend/Controllers/UsersController.cs

34 lines
No EOL
1 KiB
C#

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