From ecd038f0202617ad5dc1fe41822d9e0830cd7574 Mon Sep 17 00:00:00 2001 From: oistig Date: Thu, 19 Mar 2026 16:25:34 +0100 Subject: [PATCH] Fusion des patchs Tel et Email en un Patch Contact --- ...serEmailDto.cs => UpdateUserContactDto.cs} | 3 +- .../User/PatchUserContactEndpoint.cs | 45 +++++++++++++++++++ .../Endpoints/User/PatchUserEmailEndpoint.cs | 29 ------------ 3 files changed, 47 insertions(+), 30 deletions(-) rename Knots/DTO/User/{UpdateUserEmailDto.cs => UpdateUserContactDto.cs} (58%) create mode 100644 Knots/Endpoints/User/PatchUserContactEndpoint.cs delete mode 100644 Knots/Endpoints/User/PatchUserEmailEndpoint.cs diff --git a/Knots/DTO/User/UpdateUserEmailDto.cs b/Knots/DTO/User/UpdateUserContactDto.cs similarity index 58% rename from Knots/DTO/User/UpdateUserEmailDto.cs rename to Knots/DTO/User/UpdateUserContactDto.cs index 2d02a39..94363f9 100644 --- a/Knots/DTO/User/UpdateUserEmailDto.cs +++ b/Knots/DTO/User/UpdateUserContactDto.cs @@ -1,7 +1,8 @@ namespace Knots.DTO.User; -public class UpdateUserEmailDto +public class UpdateUserContactDto { public int Id { get; set; } public string? Email { get; set; } + public string? Tel { get; set; } } \ No newline at end of file diff --git a/Knots/Endpoints/User/PatchUserContactEndpoint.cs b/Knots/Endpoints/User/PatchUserContactEndpoint.cs new file mode 100644 index 0000000..ba38c26 --- /dev/null +++ b/Knots/Endpoints/User/PatchUserContactEndpoint.cs @@ -0,0 +1,45 @@ +using FastEndpoints; +using Knots.DTO.User; +using Microsoft.EntityFrameworkCore; + +namespace Knots.Endpoints.User; + +public class PatchUserContactEndpoint(KnotsDbContext knotsDbContext) : Endpoint +{ + 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); + } +} \ No newline at end of file diff --git a/Knots/Endpoints/User/PatchUserEmailEndpoint.cs b/Knots/Endpoints/User/PatchUserEmailEndpoint.cs deleted file mode 100644 index d09abc3..0000000 --- a/Knots/Endpoints/User/PatchUserEmailEndpoint.cs +++ /dev/null @@ -1,29 +0,0 @@ -using FastEndpoints; -using Knots.DTO.User; -using Microsoft.EntityFrameworkCore; - -namespace Knots.Endpoints.User; - -public class PatchUserEmailEndpoint(KnotsDbContext knotsDbContext) : Endpoint -{ - 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); - } -} \ No newline at end of file