From 7c2e77ed995361ede07bc0b938bac062d04c4521 Mon Sep 17 00:00:00 2001 From: oistig Date: Thu, 19 Mar 2026 16:18:52 +0100 Subject: [PATCH] Changements dans le Group Model + endpoints Patch des Groupes et Users --- .../DTO/Group/UpdateGroupMembersAmountDto.cs | 7 +++++ Knots/DTO/Group/UpdateGroupNameDto.cs | 7 +++++ Knots/DTO/Group/UpdateGroupNomDto.cs | 6 ---- .../DTO/Group/UpdateGroupNombreMembresDto.cs | 6 ---- .../DTO/Group/UpdateGroupProfilePictureDto.cs | 1 + Knots/DTO/User/UpdateUserEmailDto.cs | 1 + Knots/DTO/User/UpdateUserPasswordDto.cs | 1 + Knots/DTO/User/UpdateUserProfilePictureDto.cs | 1 + Knots/DTO/User/UpdateUsernameDto.cs | 2 ++ .../Group/PatchGroupMembersAmountEndpoint.cs | 29 ++++++++++++++++++ .../Endpoints/Group/PatchGroupNameEndpoint.cs | 29 ++++++++++++++++++ .../Group/PatchGroupProfilePictureEndpoint.cs | 29 ++++++++++++++++++ .../Endpoints/User/PatchUserEmailEndpoint.cs | 29 ++++++++++++++++++ .../User/PatchUserPasswordEndpoint.cs | 29 ++++++++++++++++++ .../User/PatchUserProfilePictureEndpoint.cs | 29 ++++++++++++++++++ Knots/Endpoints/User/PatchUsernameEndpoint.cs | 30 +++++++++++++++++++ Knots/Models/Group.cs | 4 +-- 17 files changed, 226 insertions(+), 14 deletions(-) create mode 100644 Knots/DTO/Group/UpdateGroupMembersAmountDto.cs create mode 100644 Knots/DTO/Group/UpdateGroupNameDto.cs delete mode 100644 Knots/DTO/Group/UpdateGroupNomDto.cs delete mode 100644 Knots/DTO/Group/UpdateGroupNombreMembresDto.cs create mode 100644 Knots/Endpoints/Group/PatchGroupMembersAmountEndpoint.cs create mode 100644 Knots/Endpoints/Group/PatchGroupNameEndpoint.cs create mode 100644 Knots/Endpoints/Group/PatchGroupProfilePictureEndpoint.cs create mode 100644 Knots/Endpoints/User/PatchUserEmailEndpoint.cs create mode 100644 Knots/Endpoints/User/PatchUserPasswordEndpoint.cs create mode 100644 Knots/Endpoints/User/PatchUserProfilePictureEndpoint.cs create mode 100644 Knots/Endpoints/User/PatchUsernameEndpoint.cs diff --git a/Knots/DTO/Group/UpdateGroupMembersAmountDto.cs b/Knots/DTO/Group/UpdateGroupMembersAmountDto.cs new file mode 100644 index 0000000..2f460eb --- /dev/null +++ b/Knots/DTO/Group/UpdateGroupMembersAmountDto.cs @@ -0,0 +1,7 @@ +namespace Knots.DTO.Group; + +public class UpdateGroupMembersAmountDto +{ + public int Id { get; set; } + public int MembersAmount { get; set; } +} \ No newline at end of file diff --git a/Knots/DTO/Group/UpdateGroupNameDto.cs b/Knots/DTO/Group/UpdateGroupNameDto.cs new file mode 100644 index 0000000..4f212a9 --- /dev/null +++ b/Knots/DTO/Group/UpdateGroupNameDto.cs @@ -0,0 +1,7 @@ +namespace Knots.DTO.Group; + +public class UpdateGroupNameDto +{ + public int Id { get; set; } + public string? Name { get; set; } +} \ No newline at end of file diff --git a/Knots/DTO/Group/UpdateGroupNomDto.cs b/Knots/DTO/Group/UpdateGroupNomDto.cs deleted file mode 100644 index 6f6982d..0000000 --- a/Knots/DTO/Group/UpdateGroupNomDto.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Knots.DTO.Group; - -public class UpdateGroupNomDto -{ - public string? Nom { get; set; } -} \ No newline at end of file diff --git a/Knots/DTO/Group/UpdateGroupNombreMembresDto.cs b/Knots/DTO/Group/UpdateGroupNombreMembresDto.cs deleted file mode 100644 index 55791a9..0000000 --- a/Knots/DTO/Group/UpdateGroupNombreMembresDto.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Knots.DTO.Group; - -public class UpdateGroupNombreMembresDto -{ - public int NombreMembres { get; set; } -} \ No newline at end of file diff --git a/Knots/DTO/Group/UpdateGroupProfilePictureDto.cs b/Knots/DTO/Group/UpdateGroupProfilePictureDto.cs index e40f53c..022229a 100644 --- a/Knots/DTO/Group/UpdateGroupProfilePictureDto.cs +++ b/Knots/DTO/Group/UpdateGroupProfilePictureDto.cs @@ -2,5 +2,6 @@ namespace Knots.DTO.Group; public class UpdateGroupProfilePictureDto { + public int Id { get; set; } public string? ProfilePicture { get; set; } } \ No newline at end of file diff --git a/Knots/DTO/User/UpdateUserEmailDto.cs b/Knots/DTO/User/UpdateUserEmailDto.cs index 641ecae..2d02a39 100644 --- a/Knots/DTO/User/UpdateUserEmailDto.cs +++ b/Knots/DTO/User/UpdateUserEmailDto.cs @@ -2,5 +2,6 @@ namespace Knots.DTO.User; public class UpdateUserEmailDto { + public int Id { get; set; } public string? Email { get; set; } } \ No newline at end of file diff --git a/Knots/DTO/User/UpdateUserPasswordDto.cs b/Knots/DTO/User/UpdateUserPasswordDto.cs index 83660e0..db83ddb 100644 --- a/Knots/DTO/User/UpdateUserPasswordDto.cs +++ b/Knots/DTO/User/UpdateUserPasswordDto.cs @@ -2,5 +2,6 @@ namespace Knots.DTO.User; public class UpdateUserPasswordDto { + public int Id { get; set; } public string? Password { get; set; } } \ No newline at end of file diff --git a/Knots/DTO/User/UpdateUserProfilePictureDto.cs b/Knots/DTO/User/UpdateUserProfilePictureDto.cs index e84c2d9..9478cab 100644 --- a/Knots/DTO/User/UpdateUserProfilePictureDto.cs +++ b/Knots/DTO/User/UpdateUserProfilePictureDto.cs @@ -2,5 +2,6 @@ namespace Knots.DTO.User; public class UpdateUserProfilePictureDto { + public int Id { get; set; } public string? ProfilePicture { get; set; } } \ No newline at end of file diff --git a/Knots/DTO/User/UpdateUsernameDto.cs b/Knots/DTO/User/UpdateUsernameDto.cs index e47da7c..8c45a0e 100644 --- a/Knots/DTO/User/UpdateUsernameDto.cs +++ b/Knots/DTO/User/UpdateUsernameDto.cs @@ -2,5 +2,7 @@ namespace Knots.DTO.User; public class UpdateUsernameDto { + public int Id { get; set; } + public string? Username { get; set; } } \ No newline at end of file diff --git a/Knots/Endpoints/Group/PatchGroupMembersAmountEndpoint.cs b/Knots/Endpoints/Group/PatchGroupMembersAmountEndpoint.cs new file mode 100644 index 0000000..30de787 --- /dev/null +++ b/Knots/Endpoints/Group/PatchGroupMembersAmountEndpoint.cs @@ -0,0 +1,29 @@ +using FastEndpoints; +using Knots.DTO.Group; +using Microsoft.EntityFrameworkCore; + +namespace Knots.Endpoints.Group; + +public class PatchGroupMembersAmountEndpoint(KnotsDbContext knotsDbContext) : Endpoint +{ + public override void Configure() + { + Patch("/groups/{@Id}/membersAmount/", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(UpdateGroupMembersAmountDto req, CancellationToken ct) + { + Models.Group? databaseGroup = await knotsDbContext.Groups.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseGroup is null) + { + await Send.NotFoundAsync(ct); + return; + } + + databaseGroup.MembersAmount = req.MembersAmount; + await knotsDbContext.SaveChangesAsync(ct); + await Send.NoContentAsync(ct); + } +} \ No newline at end of file diff --git a/Knots/Endpoints/Group/PatchGroupNameEndpoint.cs b/Knots/Endpoints/Group/PatchGroupNameEndpoint.cs new file mode 100644 index 0000000..0df0a5d --- /dev/null +++ b/Knots/Endpoints/Group/PatchGroupNameEndpoint.cs @@ -0,0 +1,29 @@ +using FastEndpoints; +using Knots.DTO.Group; +using Microsoft.EntityFrameworkCore; + +namespace Knots.Endpoints.Group; + +public class PatchGroupNameEndpoint(KnotsDbContext knotsDbContext) : Endpoint +{ + public override void Configure() + { + Patch("/groups/{@Id}/name/", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(UpdateGroupNameDto req, CancellationToken ct) + { + Models.Group? databaseGroup = await knotsDbContext.Groups.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseGroup is null) + { + await Send.NotFoundAsync(ct); + return; + } + + databaseGroup.Name = req.Name; + await knotsDbContext.SaveChangesAsync(ct); + await Send.NoContentAsync(ct); + } +} \ No newline at end of file diff --git a/Knots/Endpoints/Group/PatchGroupProfilePictureEndpoint.cs b/Knots/Endpoints/Group/PatchGroupProfilePictureEndpoint.cs new file mode 100644 index 0000000..b91aae0 --- /dev/null +++ b/Knots/Endpoints/Group/PatchGroupProfilePictureEndpoint.cs @@ -0,0 +1,29 @@ +using FastEndpoints; +using Knots.DTO.Group; +using Microsoft.EntityFrameworkCore; + +namespace Knots.Endpoints.Group; + +public class PatchGroupProfilePictureEndpoint(KnotsDbContext knotsDbContext) : Endpoint +{ + public override void Configure() + { + Patch("/groups/{@Id}/profilePicture/", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(UpdateGroupProfilePictureDto req, CancellationToken ct) + { + Models.Group? databaseGroup = await knotsDbContext.Groups.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + + if (databaseGroup is null) + { + await Send.NotFoundAsync(ct); + return; + } + + databaseGroup.ProfilePicture = req.ProfilePicture; + 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 new file mode 100644 index 0000000..d09abc3 --- /dev/null +++ b/Knots/Endpoints/User/PatchUserEmailEndpoint.cs @@ -0,0 +1,29 @@ +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 diff --git a/Knots/Endpoints/User/PatchUserPasswordEndpoint.cs b/Knots/Endpoints/User/PatchUserPasswordEndpoint.cs new file mode 100644 index 0000000..cf84060 --- /dev/null +++ b/Knots/Endpoints/User/PatchUserPasswordEndpoint.cs @@ -0,0 +1,29 @@ +using FastEndpoints; +using Knots.DTO.User; +using Microsoft.EntityFrameworkCore; + +namespace Knots.Endpoints.User; + +public class PatchUserPasswordEndpoint(KnotsDbContext knotsDbContext) : Endpoint +{ + public override void Configure() + { + Patch("/users/{@Id}/password/", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(UpdateUserPasswordDto 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.Password = req.Password; + await knotsDbContext.SaveChangesAsync(ct); + await Send.NoContentAsync(ct); + } +} \ No newline at end of file diff --git a/Knots/Endpoints/User/PatchUserProfilePictureEndpoint.cs b/Knots/Endpoints/User/PatchUserProfilePictureEndpoint.cs new file mode 100644 index 0000000..979965c --- /dev/null +++ b/Knots/Endpoints/User/PatchUserProfilePictureEndpoint.cs @@ -0,0 +1,29 @@ +using FastEndpoints; +using Knots.DTO.User; +using Microsoft.EntityFrameworkCore; + +namespace Knots.Endpoints.User; + +public class PatchUserProfilePictureEndpoint(KnotsDbContext knotsDbContext) : Endpoint +{ + public override void Configure() + { + Patch("/users/{@Id}/profilePicture/", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(UpdateUserProfilePictureDto 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.ProfilePicture = req.ProfilePicture; + await knotsDbContext.SaveChangesAsync(ct); + await Send.NoContentAsync(ct); + } +} \ No newline at end of file diff --git a/Knots/Endpoints/User/PatchUsernameEndpoint.cs b/Knots/Endpoints/User/PatchUsernameEndpoint.cs new file mode 100644 index 0000000..ff326e3 --- /dev/null +++ b/Knots/Endpoints/User/PatchUsernameEndpoint.cs @@ -0,0 +1,30 @@ +using FastEndpoints; +using Knots.DTO.User; +using Microsoft.EntityFrameworkCore; + +namespace Knots.Endpoints.User; + + +public class PatchUsernameEndpoint(KnotsDbContext knotsDbContext) : Endpoint +{ + public override void Configure() + { + Patch("/users/{@Id}/username/", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(UpdateUsernameDto 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.Username = req.Username; + await knotsDbContext.SaveChangesAsync(ct); + await Send.NoContentAsync(ct); + } +} \ No newline at end of file diff --git a/Knots/Models/Group.cs b/Knots/Models/Group.cs index 47e22b2..727c91c 100644 --- a/Knots/Models/Group.cs +++ b/Knots/Models/Group.cs @@ -6,7 +6,7 @@ namespace Knots.Models; public class Group { [Key] public int Id { get; set; } - [Required, MaxLength(50)] public string? Nom { get; set; } - [Required] public int NombreMembres { get; set; } + [Required, MaxLength(50)] public string? Name { get; set; } + [Required] public int MembersAmount { get; set; } public string? ProfilePicture { get; set; } } \ No newline at end of file