Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -1,6 +1,36 @@
|
||||
using FastEndpoints;
|
||||
using Knots.DTO.User;
|
||||
|
||||
namespace Knots.Endpoints.User;
|
||||
|
||||
public class CreateUserEndpoint
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,28 @@
|
||||
using FastEndpoints;
|
||||
using Knots.DTO.User;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Knots.Endpoints.User;
|
||||
|
||||
public class DeleteUserEndpoint
|
||||
public class DeleteUserEndpoint(KnotsDbContext knotsDbContext) : Endpoint <GetUserDto, GetUserDetailsDto>
|
||||
{
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Delete ("/users/{@Id}", x => new { x.Username });
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetUserDto req, CancellationToken ct)
|
||||
{
|
||||
Models.User? databaseUser = await knotsDbContext.Users.SingleOrDefaultAsync(x => x.Username == req.Username, cancellationToken: ct);
|
||||
|
||||
if (databaseUser == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
knotsDbContext.Users.Remove(databaseUser);
|
||||
await knotsDbContext.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,24 @@
|
||||
using FastEndpoints;
|
||||
using Knots.DTO.User;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Knots.Endpoints.User;
|
||||
|
||||
public class GetAllUsersEndpoint
|
||||
public class GetAllUsersEndpoint(KnotsDbContext knotsDbContext) : EndpointWithoutRequest<List<GetUserDto>>
|
||||
{
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/users");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetUserDto> users= await knotsDbContext.Users.Select(x => new GetUserDto()
|
||||
{
|
||||
Username = x.Username,
|
||||
}).ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(users, ct);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,37 @@
|
||||
using FastEndpoints;
|
||||
using Knots.DTO.User;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Knots.Endpoints.User;
|
||||
|
||||
public class GetUserEndpoint
|
||||
public class GetUserEndpoint(KnotsDbContext knotsDbContext) : Endpoint <GetUserDto, GetUserDetailsDto>
|
||||
{
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/users/{@Id}", x => new { x.Username });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetUserDto req, CancellationToken ct)
|
||||
{
|
||||
Models.User? databaseLogin = await knotsDbContext.Users.SingleOrDefaultAsync(x => x.Username == req.Username, cancellationToken: ct);
|
||||
|
||||
if (databaseLogin == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetUserDetailsDto dto = new()
|
||||
{
|
||||
Username = databaseLogin.Username,
|
||||
Description = databaseLogin.Description,
|
||||
Password = databaseLogin.Password,
|
||||
Email = databaseLogin.Email,
|
||||
Tel = databaseLogin.Tel,
|
||||
ProfilePicture = databaseLogin.ProfilePicture
|
||||
};
|
||||
|
||||
await Send.OkAsync(dto, ct);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,46 @@
|
||||
using FastEndpoints;
|
||||
using Knots.DTO.User;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Knots.Endpoints.User;
|
||||
|
||||
public class UpdateUserEndpoint
|
||||
public class UpdateUserEndpoint(KnotsDbContext knotsDbContext) : Endpoint <UpdateUserDto, GetUserDetailsDto>
|
||||
{
|
||||
|
||||
public override void Configure()
|
||||
{
|
||||
Put ("/users/{@Id}", x => new { x.Username });
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct)
|
||||
{
|
||||
Models.User? databaseUser = await knotsDbContext.Users.SingleOrDefaultAsync(x => x.Username == req.Username, cancellationToken: ct);
|
||||
|
||||
if (databaseUser == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
databaseUser.Username = req.Username;
|
||||
databaseUser.Password = req.Password;
|
||||
databaseUser.Description = req.Description;
|
||||
databaseUser.Tel = req.Tel;
|
||||
databaseUser.Email = req.Email;
|
||||
databaseUser.ProfilePicture = req.ProfilePicture;
|
||||
}
|
||||
await knotsDbContext.SaveChangesAsync(ct);
|
||||
|
||||
GetUserDetailsDto dto = new()
|
||||
{
|
||||
Username = databaseUser.Username,
|
||||
Password = databaseUser.Password,
|
||||
Description = databaseUser.Description,
|
||||
Tel = databaseUser.Tel,
|
||||
Email = databaseUser.Email,
|
||||
ProfilePicture = databaseUser.ProfilePicture
|
||||
};
|
||||
|
||||
await Send.OkAsync(dto, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user