feat(backend): add RequestDiscordTokenAsync method

This commit is contained in:
sam 2024-06-12 16:19:49 +02:00
parent 2a7bd746aa
commit 6186eda092
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
12 changed files with 230 additions and 22 deletions

View file

@ -1,3 +1,4 @@
using Foxnouns.Backend.Controllers.Authentication;
using Foxnouns.Backend.Database;
using Foxnouns.Backend.Services;
using Microsoft.AspNetCore.Mvc;
@ -6,10 +7,15 @@ using NodaTime;
namespace Foxnouns.Backend.Controllers;
[Route("/api/v2/debug")]
public class DebugController(DatabaseContext db, AuthService authSvc, IClock clock, ILogger logger) : ApiControllerBase
public class DebugController(
DatabaseContext db,
AuthService authSvc,
UserRendererService userRendererSvc,
IClock clock,
ILogger logger) : ApiControllerBase
{
[HttpPost("users")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(AuthResponse))]
[ProducesResponseType<AuthController.AuthResponse>(StatusCodes.Status200OK)]
public async Task<IActionResult> CreateUserAsync([FromBody] CreateUserRequest req)
{
logger.Debug("Creating user with username {Username} and email {Email}", req.Username, req.Email);
@ -23,10 +29,12 @@ public class DebugController(DatabaseContext db, AuthService authSvc, IClock clo
await db.SaveChangesAsync();
return Ok(new AuthResponse(user.Id, user.Username, tokenStr));
return Ok(new AuthController.AuthResponse(
await userRendererSvc.RenderUserAsync(user, selfUser: user, renderMembers: false),
tokenStr,
token.ExpiresAt
));
}
public record CreateUserRequest(string Username, string Password, string Email);
private record AuthResponse(Snowflake Id, string Username, string Token);
}