Commit endpoints
This commit is contained in:
@@ -2,5 +2,5 @@ namespace Knots.DTO.Role;
|
|||||||
|
|
||||||
public class GetRoleDto
|
public class GetRoleDto
|
||||||
{
|
{
|
||||||
public string? Id { get; set; }
|
public string? Libelle { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,32 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Knots.DTO.Discussion;
|
||||||
|
using Knots.DTO.User;
|
||||||
|
|
||||||
namespace Knots.Endpoints.Discussion;
|
namespace Knots.Endpoints.Discussion;
|
||||||
|
|
||||||
public class CreateDiscussionEndpoint
|
public class CreateUserEndpoint(KnotsDbContext knotsDbContext) : Endpoint<CreateDiscussionDto, GetDiscussionDto>
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,32 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Knots.DTO.Role;
|
||||||
|
using Knots.DTO.User;
|
||||||
|
|
||||||
namespace Knots.Endpoints.Role;
|
namespace Knots.Endpoints.Role;
|
||||||
|
|
||||||
public class CreateRoleEndpoint
|
public class CreateRoleEndpoint(KnotsDbContext knotsDbContext) : Endpoint<CreateRoleDto, GetRoleDto>
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,33 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Knots.DTO.Role;
|
||||||
|
using Knots.DTO.User;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Knots.Endpoints.Role;
|
namespace Knots.Endpoints.Role;
|
||||||
|
|
||||||
public class GetRoleEndpoint
|
public class GetRoleEndpoint(KnotsDbContext knotsDbContext) : Endpoint <GetRoleDto>
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Knots.Endpoints.Role;
|
|
||||||
|
|
||||||
public class UpdateRoleEndpoint
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -5,5 +5,5 @@ namespace Knots.Models;
|
|||||||
public class Role
|
public class Role
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[Required, MaxLength(50)] public string Libelle { get; set; }
|
[Required, MaxLength(50)] public string? Libelle { get; set; }
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user