Changements dans le Group Model + endpoints Patch des Groupes et Users
This commit is contained in:
7
Knots/DTO/Group/UpdateGroupMembersAmountDto.cs
Normal file
7
Knots/DTO/Group/UpdateGroupMembersAmountDto.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Knots.DTO.Group;
|
||||||
|
|
||||||
|
public class UpdateGroupMembersAmountDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int MembersAmount { get; set; }
|
||||||
|
}
|
||||||
7
Knots/DTO/Group/UpdateGroupNameDto.cs
Normal file
7
Knots/DTO/Group/UpdateGroupNameDto.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Knots.DTO.Group;
|
||||||
|
|
||||||
|
public class UpdateGroupNameDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Knots.DTO.Group;
|
|
||||||
|
|
||||||
public class UpdateGroupNomDto
|
|
||||||
{
|
|
||||||
public string? Nom { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Knots.DTO.Group;
|
|
||||||
|
|
||||||
public class UpdateGroupNombreMembresDto
|
|
||||||
{
|
|
||||||
public int NombreMembres { get; set; }
|
|
||||||
}
|
|
||||||
@@ -2,5 +2,6 @@ namespace Knots.DTO.Group;
|
|||||||
|
|
||||||
public class UpdateGroupProfilePictureDto
|
public class UpdateGroupProfilePictureDto
|
||||||
{
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
public string? ProfilePicture { get; set; }
|
public string? ProfilePicture { get; set; }
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,6 @@ namespace Knots.DTO.User;
|
|||||||
|
|
||||||
public class UpdateUserEmailDto
|
public class UpdateUserEmailDto
|
||||||
{
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
public string? Email { get; set; }
|
public string? Email { get; set; }
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,6 @@ namespace Knots.DTO.User;
|
|||||||
|
|
||||||
public class UpdateUserPasswordDto
|
public class UpdateUserPasswordDto
|
||||||
{
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
public string? Password { get; set; }
|
public string? Password { get; set; }
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,6 @@ namespace Knots.DTO.User;
|
|||||||
|
|
||||||
public class UpdateUserProfilePictureDto
|
public class UpdateUserProfilePictureDto
|
||||||
{
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
public string? ProfilePicture { get; set; }
|
public string? ProfilePicture { get; set; }
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,7 @@ namespace Knots.DTO.User;
|
|||||||
|
|
||||||
public class UpdateUsernameDto
|
public class UpdateUsernameDto
|
||||||
{
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
public string? Username { get; set; }
|
public string? Username { get; set; }
|
||||||
}
|
}
|
||||||
29
Knots/Endpoints/Group/PatchGroupMembersAmountEndpoint.cs
Normal file
29
Knots/Endpoints/Group/PatchGroupMembersAmountEndpoint.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Knots.DTO.Group;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Knots.Endpoints.Group;
|
||||||
|
|
||||||
|
public class PatchGroupMembersAmountEndpoint(KnotsDbContext knotsDbContext) : Endpoint<UpdateGroupMembersAmountDto>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
Knots/Endpoints/Group/PatchGroupNameEndpoint.cs
Normal file
29
Knots/Endpoints/Group/PatchGroupNameEndpoint.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Knots.DTO.Group;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Knots.Endpoints.Group;
|
||||||
|
|
||||||
|
public class PatchGroupNameEndpoint(KnotsDbContext knotsDbContext) : Endpoint<UpdateGroupNameDto>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
Knots/Endpoints/Group/PatchGroupProfilePictureEndpoint.cs
Normal file
29
Knots/Endpoints/Group/PatchGroupProfilePictureEndpoint.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Knots.DTO.Group;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Knots.Endpoints.Group;
|
||||||
|
|
||||||
|
public class PatchGroupProfilePictureEndpoint(KnotsDbContext knotsDbContext) : Endpoint<UpdateGroupProfilePictureDto>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
Knots/Endpoints/User/PatchUserEmailEndpoint.cs
Normal file
29
Knots/Endpoints/User/PatchUserEmailEndpoint.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
Knots/Endpoints/User/PatchUserPasswordEndpoint.cs
Normal file
29
Knots/Endpoints/User/PatchUserPasswordEndpoint.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Knots.DTO.User;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Knots.Endpoints.User;
|
||||||
|
|
||||||
|
public class PatchUserPasswordEndpoint(KnotsDbContext knotsDbContext) : Endpoint<UpdateUserPasswordDto>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
Knots/Endpoints/User/PatchUserProfilePictureEndpoint.cs
Normal file
29
Knots/Endpoints/User/PatchUserProfilePictureEndpoint.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Knots.DTO.User;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Knots.Endpoints.User;
|
||||||
|
|
||||||
|
public class PatchUserProfilePictureEndpoint(KnotsDbContext knotsDbContext) : Endpoint<UpdateUserProfilePictureDto>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
Knots/Endpoints/User/PatchUsernameEndpoint.cs
Normal file
30
Knots/Endpoints/User/PatchUsernameEndpoint.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Knots.DTO.User;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace Knots.Endpoints.User;
|
||||||
|
|
||||||
|
|
||||||
|
public class PatchUsernameEndpoint(KnotsDbContext knotsDbContext) : Endpoint<UpdateUsernameDto>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ namespace Knots.Models;
|
|||||||
public class Group
|
public class Group
|
||||||
{
|
{
|
||||||
[Key] public int Id { get; set; }
|
[Key] public int Id { get; set; }
|
||||||
[Required, MaxLength(50)] public string? Nom { get; set; }
|
[Required, MaxLength(50)] public string? Name { get; set; }
|
||||||
[Required] public int NombreMembres { get; set; }
|
[Required] public int MembersAmount { get; set; }
|
||||||
public string? ProfilePicture { get; set; }
|
public string? ProfilePicture { get; set; }
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user