From 55d50cf3df50efd98ab297cbb30fd55554913119 Mon Sep 17 00:00:00 2001 From: oistig Date: Thu, 12 Mar 2026 17:11:48 +0100 Subject: [PATCH 1/2] Endpoint de User --- Knots/Endpoints/User/CreateUserEndpoint.cs | 32 +++++++++++++- Knots/Endpoints/User/DeleteUserEndpoint.cs | 26 ++++++++++- Knots/Endpoints/User/GetAllUsersEndpoint.cs | 22 +++++++++- Knots/Endpoints/User/GetUserEndpoint.cs | 35 ++++++++++++++- Knots/Endpoints/User/UpdateUserEndpoint.cs | 44 ++++++++++++++++++- Knots/obj/Debug/net9.0/Knots.AssemblyInfo.cs | 2 +- .../net9.0/Knots.AssemblyInfoInputs.cache | 2 +- 7 files changed, 152 insertions(+), 11 deletions(-) diff --git a/Knots/Endpoints/User/CreateUserEndpoint.cs b/Knots/Endpoints/User/CreateUserEndpoint.cs index 6176133..54e562a 100644 --- a/Knots/Endpoints/User/CreateUserEndpoint.cs +++ b/Knots/Endpoints/User/CreateUserEndpoint.cs @@ -1,6 +1,36 @@ +using FastEndpoints; +using Knots.DTO.User; + namespace Knots.Endpoints.User; -public class CreateUserEndpoint +public class CreateUserEndpoint(KnotsDbContext knotsDbContext) : Endpoint { + 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); + + } } \ No newline at end of file diff --git a/Knots/Endpoints/User/DeleteUserEndpoint.cs b/Knots/Endpoints/User/DeleteUserEndpoint.cs index 7f76d8b..ceb6b70 100644 --- a/Knots/Endpoints/User/DeleteUserEndpoint.cs +++ b/Knots/Endpoints/User/DeleteUserEndpoint.cs @@ -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 { - + 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); + } } \ No newline at end of file diff --git a/Knots/Endpoints/User/GetAllUsersEndpoint.cs b/Knots/Endpoints/User/GetAllUsersEndpoint.cs index 0ca85fd..20dd935 100644 --- a/Knots/Endpoints/User/GetAllUsersEndpoint.cs +++ b/Knots/Endpoints/User/GetAllUsersEndpoint.cs @@ -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> { - + public override void Configure() + { + Get ("/users"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken ct) + { + List users= await knotsDbContext.Users.Select(x => new GetUserDto() + { + Username = x.Username, + }).ToListAsync(ct); + + await Send.OkAsync(users, ct); + } } \ No newline at end of file diff --git a/Knots/Endpoints/User/GetUserEndpoint.cs b/Knots/Endpoints/User/GetUserEndpoint.cs index d6a6916..619a803 100644 --- a/Knots/Endpoints/User/GetUserEndpoint.cs +++ b/Knots/Endpoints/User/GetUserEndpoint.cs @@ -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 { - + 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); + } } \ No newline at end of file diff --git a/Knots/Endpoints/User/UpdateUserEndpoint.cs b/Knots/Endpoints/User/UpdateUserEndpoint.cs index c58ec6c..1bbc6d0 100644 --- a/Knots/Endpoints/User/UpdateUserEndpoint.cs +++ b/Knots/Endpoints/User/UpdateUserEndpoint.cs @@ -1,6 +1,46 @@ +using FastEndpoints; +using Knots.DTO.User; +using Microsoft.EntityFrameworkCore; + namespace Knots.Endpoints.User; -public class UpdateUserEndpoint +public class UpdateLoginEndpoint(KnotsDbContext knotsDbContext) : Endpoint { - + 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); + } } \ No newline at end of file diff --git a/Knots/obj/Debug/net9.0/Knots.AssemblyInfo.cs b/Knots/obj/Debug/net9.0/Knots.AssemblyInfo.cs index 5d02ab2..ef75dd3 100644 --- a/Knots/obj/Debug/net9.0/Knots.AssemblyInfo.cs +++ b/Knots/obj/Debug/net9.0/Knots.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Knots")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2258e5ad8e56b01ea799bd6859bf45e6499a9f5f")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+747cb84f883d7a7c2bec1f2b214de7b1218908ae")] [assembly: System.Reflection.AssemblyProductAttribute("Knots")] [assembly: System.Reflection.AssemblyTitleAttribute("Knots")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/Knots/obj/Debug/net9.0/Knots.AssemblyInfoInputs.cache b/Knots/obj/Debug/net9.0/Knots.AssemblyInfoInputs.cache index f5d1813..3f70543 100644 --- a/Knots/obj/Debug/net9.0/Knots.AssemblyInfoInputs.cache +++ b/Knots/obj/Debug/net9.0/Knots.AssemblyInfoInputs.cache @@ -1 +1 @@ -1ec67d9f775d898443e3ca901e3936ca7eac382476d451d905e395f125dd8665 +24ed5b64fb7def1bc849d59ad0bbd7ac0548dd62d095101b06edd438ba621217 From b7ad3c9af3559bf28d83d844a64aca14de1d0cd7 Mon Sep 17 00:00:00 2001 From: oistig Date: Thu, 12 Mar 2026 17:12:35 +0100 Subject: [PATCH 2/2] changement de nom de classe --- Knots/Endpoints/User/UpdateUserEndpoint.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Knots/Endpoints/User/UpdateUserEndpoint.cs b/Knots/Endpoints/User/UpdateUserEndpoint.cs index 1bbc6d0..22c61b7 100644 --- a/Knots/Endpoints/User/UpdateUserEndpoint.cs +++ b/Knots/Endpoints/User/UpdateUserEndpoint.cs @@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore; namespace Knots.Endpoints.User; -public class UpdateLoginEndpoint(KnotsDbContext knotsDbContext) : Endpoint +public class UpdateUserEndpoint(KnotsDbContext knotsDbContext) : Endpoint { public override void Configure() {