Fusion des patchs Tel et Email en un Patch Contact
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
namespace Knots.DTO.User;
|
namespace Knots.DTO.User;
|
||||||
|
|
||||||
public class UpdateUserEmailDto
|
public class UpdateUserContactDto
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string? Email { get; set; }
|
public string? Email { get; set; }
|
||||||
|
public string? Tel { get; set; }
|
||||||
}
|
}
|
||||||
45
Knots/Endpoints/User/PatchUserContactEndpoint.cs
Normal file
45
Knots/Endpoints/User/PatchUserContactEndpoint.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Knots.DTO.User;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Knots.Endpoints.User;
|
||||||
|
|
||||||
|
public class PatchUserContactEndpoint(KnotsDbContext knotsDbContext) : Endpoint<UpdateUserContactDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Patch("/users/{@Id}/contact/", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateUserContactDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.User? databaseUser = await knotsDbContext.Users.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
|
if (databaseUser is null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (databaseUser.Email != req.Email)
|
||||||
|
{
|
||||||
|
databaseUser.Email = req.Email;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
databaseUser.Email = databaseUser.Email;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (databaseUser.Tel != req.Tel)
|
||||||
|
{
|
||||||
|
databaseUser.Tel = req.Tel;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
databaseUser.Tel = databaseUser.Tel;
|
||||||
|
}
|
||||||
|
|
||||||
|
await knotsDbContext.SaveChangesAsync(ct);
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Knots.DTO.User;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace Knots.Endpoints.User;
|
|
||||||
|
|
||||||
public class PatchUserEmailEndpoint(KnotsDbContext knotsDbContext) : Endpoint<UpdateUserEmailDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Patch("/users/{@Id}/email/", x => new {x.Id});
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateUserEmailDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.User? databaseUser = await knotsDbContext.Users.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (databaseUser is null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
databaseUser.Email = req.Email;
|
|
||||||
await knotsDbContext.SaveChangesAsync(ct);
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user