diff --git a/Knots/DTO/Role/GetRoleDto.cs b/Knots/DTO/Role/GetRoleDto.cs index 4464cf2..ef944a7 100644 --- a/Knots/DTO/Role/GetRoleDto.cs +++ b/Knots/DTO/Role/GetRoleDto.cs @@ -2,5 +2,5 @@ namespace Knots.DTO.Role; public class GetRoleDto { - public string? Id { get; set; } + public string? Libelle { get; set; } } \ No newline at end of file diff --git a/Knots/Endpoints/Discussion/CreateDiscussionEndpoint.cs b/Knots/Endpoints/Discussion/CreateDiscussionEndpoint.cs index d523a01..5b7c500 100644 --- a/Knots/Endpoints/Discussion/CreateDiscussionEndpoint.cs +++ b/Knots/Endpoints/Discussion/CreateDiscussionEndpoint.cs @@ -1,6 +1,32 @@ +using FastEndpoints; +using Knots.DTO.Discussion; +using Knots.DTO.User; + namespace Knots.Endpoints.Discussion; -public class CreateDiscussionEndpoint +public class CreateUserEndpoint(KnotsDbContext knotsDbContext) : Endpoint { + public override void Configure() + { + Post("/users"); + AllowAnonymous(); + } + public override async Task HandleAsync(CreateDiscussionDto req, CancellationToken ct) + { + Models.Discussion discussion = new() + { + + }; + knotsDbContext.Add(discussion); + await knotsDbContext.SaveChangesAsync(ct); + + GetDiscussionDto response = new() + { + Id = discussion.Id, + }; + + await Send.OkAsync(response, ct); + + } } \ No newline at end of file diff --git a/Knots/Endpoints/Role/CreateRoleEndpoint.cs b/Knots/Endpoints/Role/CreateRoleEndpoint.cs index a1a9b16..7c683f4 100644 --- a/Knots/Endpoints/Role/CreateRoleEndpoint.cs +++ b/Knots/Endpoints/Role/CreateRoleEndpoint.cs @@ -1,6 +1,32 @@ +using FastEndpoints; +using Knots.DTO.Role; +using Knots.DTO.User; + namespace Knots.Endpoints.Role; -public class CreateRoleEndpoint +public class CreateRoleEndpoint(KnotsDbContext knotsDbContext) : Endpoint { + public override void Configure() + { + Post("/roles"); + AllowAnonymous(); + } + public override async Task HandleAsync(CreateRoleDto req, CancellationToken ct) + { + Models.Role role = new() + { + Libelle = req.Libelle + }; + knotsDbContext.Add(role); + await knotsDbContext.SaveChangesAsync(ct); + + GetRoleDto response = new() + { + Libelle = role.Libelle + }; + + await Send.OkAsync(response, ct); + + } } \ No newline at end of file diff --git a/Knots/Endpoints/Role/GetRoleEndpoint.cs b/Knots/Endpoints/Role/GetRoleEndpoint.cs index 8d3c682..22f86d5 100644 --- a/Knots/Endpoints/Role/GetRoleEndpoint.cs +++ b/Knots/Endpoints/Role/GetRoleEndpoint.cs @@ -1,6 +1,33 @@ +using FastEndpoints; +using Knots.DTO.Role; +using Knots.DTO.User; +using Microsoft.EntityFrameworkCore; + namespace Knots.Endpoints.Role; -public class GetRoleEndpoint +public class GetRoleEndpoint(KnotsDbContext knotsDbContext) : Endpoint { - + public override void Configure() + { + Get ("/roles/{@Id}", x => new { x.Libelle }); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetRoleDto req, CancellationToken ct) + { + Models.Role? databaseRole = await knotsDbContext.Roles.SingleOrDefaultAsync(x => x.Libelle == req.Libelle, cancellationToken: ct); + + if (databaseRole == null) + { + await Send.NotFoundAsync(ct); + return; + } + + GetRoleDto dto = new() + { + Libelle = databaseRole.Libelle, + }; + + await Send.OkAsync(dto, ct); + } } \ No newline at end of file diff --git a/Knots/Endpoints/Role/UpdateRoleEndpoint.cs b/Knots/Endpoints/Role/UpdateRoleEndpoint.cs deleted file mode 100644 index 283aff8..0000000 --- a/Knots/Endpoints/Role/UpdateRoleEndpoint.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Knots.Endpoints.Role; - -public class UpdateRoleEndpoint -{ - -} \ No newline at end of file diff --git a/Knots/Models/Role.cs b/Knots/Models/Role.cs index c8cce95..7ec4d50 100644 --- a/Knots/Models/Role.cs +++ b/Knots/Models/Role.cs @@ -5,5 +5,5 @@ namespace Knots.Models; public class Role { public int Id { get; set; } - [Required, MaxLength(50)] public string Libelle { get; set; } + [Required, MaxLength(50)] public string? Libelle { get; set; } } \ No newline at end of file