36 lines
883 B
C#
36 lines
883 B
C#
using FastEndpoints;
|
|
using Knots.DTO.User;
|
|
|
|
namespace Knots.Endpoints.User;
|
|
|
|
public class CreateUserEndpoint(KnotsDbContext knotsDbContext) : Endpoint<CreateUserDto, GetUserDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/users");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(CreateUserDto req, CancellationToken ct)
|
|
{
|
|
Models.User user = new()
|
|
{
|
|
Username = req.Username,
|
|
Description = req.Description,
|
|
Password = req.Password,
|
|
Email = req.Email,
|
|
Tel = req.Tel,
|
|
ProfilePicture = req.ProfilePicture
|
|
};
|
|
knotsDbContext.Add(user);
|
|
await knotsDbContext.SaveChangesAsync(ct);
|
|
|
|
GetUserDto response = new()
|
|
{
|
|
Username = user.Username
|
|
};
|
|
|
|
await Send.OkAsync(response, ct);
|
|
|
|
}
|
|
} |