deleted all allowanonymous

This commit is contained in:
2025-12-08 11:29:39 +01:00
parent 1aeae34f34
commit 1b4bd523b1
23 changed files with 26 additions and 48 deletions

View File

@@ -9,8 +9,7 @@ public class CreateAuthorEndpoint(LibraryDbContext database) : Endpoint<CreateAu
public override void Configure() public override void Configure()
{ {
Post("/authors"); Post("/authors");
AllowAnonymous(); Roles("admin");
// Roles("admin");
} }
public override async Task HandleAsync(CreateAuthorDto req, CancellationToken ct) public override async Task HandleAsync(CreateAuthorDto req, CancellationToken ct)

View File

@@ -15,8 +15,7 @@ public class DeleteAuthorEndpoint(LibraryDbContext database) : Endpoint<DeleteAu
public override void Configure() public override void Configure()
{ {
Delete("/authors/{@Id}", x => new {x.Id}); Delete("/authors/{@Id}", x => new {x.Id});
// Roles("admin"); Roles("admin");
AllowAnonymous();
} }
public override async Task HandleAsync(DeleteAuthorRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteAuthorRequest req, CancellationToken ct)

View File

@@ -10,8 +10,7 @@ public class GetAllAuthorsEndpoint(LibraryDbContext database) : EndpointWithoutR
public override void Configure() public override void Configure()
{ {
Get("/authors"); Get("/authors");
// Roles("viewer", "admin", "librarian"); Roles("viewer", "admin", "librarian");
AllowAnonymous();
} }
public override async Task HandleAsync(CancellationToken ct) public override async Task HandleAsync(CancellationToken ct)

View File

@@ -16,8 +16,7 @@ public class GetAuthorEndpoint(LibraryDbContext database) : Endpoint<GetAuthorRe
public override void Configure() public override void Configure()
{ {
Get("/authors/{@Id}", x => new {x.Id}); Get("/authors/{@Id}", x => new {x.Id});
// Roles("viewer", "admin", "librarian"); Roles("viewer", "admin", "librarian");
AllowAnonymous();
} }
public override async Task HandleAsync(GetAuthorRequest req, CancellationToken ct) public override async Task HandleAsync(GetAuthorRequest req, CancellationToken ct)

View File

@@ -11,8 +11,7 @@ public class UpdateAuthorEndpoint(LibraryDbContext database) : Endpoint<UpdateAu
public override void Configure() public override void Configure()
{ {
Put("/authors/{@Id}", x => new {x.Id}); Put("/authors/{@Id}", x => new {x.Id});
// Roles("admin"); Roles("admin");
AllowAnonymous();
} }
public override async Task HandleAsync(UpdateAuthorDto req, CancellationToken ct) public override async Task HandleAsync(UpdateAuthorDto req, CancellationToken ct)

View File

@@ -10,8 +10,7 @@ public class CreateBookEndpoint(LibraryDbContext database) : Endpoint<CreateBook
public override void Configure() public override void Configure()
{ {
Post("/books"); Post("/books");
AllowAnonymous(); Roles("admin");
// Roles("admin");
} }
public override async Task HandleAsync(CreateBookDto req, CancellationToken ct) public override async Task HandleAsync(CreateBookDto req, CancellationToken ct)

View File

@@ -16,8 +16,7 @@ public class DeleteBookEndpoint(LibraryDbContext database) : Endpoint<DeleteBook
public override void Configure() public override void Configure()
{ {
Delete("/books/{@Id}", x => new {x.Id}); Delete("/books/{@Id}", x => new {x.Id});
// Roles("admin"); Roles("admin");
AllowAnonymous();
} }
public override async Task HandleAsync(DeleteBookRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteBookRequest req, CancellationToken ct)

View File

@@ -9,8 +9,7 @@ public class GetAllBooksEndpoint(LibraryDbContext database) : EndpointWithoutReq
public override void Configure() public override void Configure()
{ {
Get("/books"); Get("/books");
// Roles("viewer", "admin", "librarian"); Roles("viewer", "admin", "librarian");
AllowAnonymous();
} }
public override async Task HandleAsync(CancellationToken ct) public override async Task HandleAsync(CancellationToken ct)

View File

@@ -14,8 +14,7 @@ public class GetBookEndpoint(LibraryDbContext database) : Endpoint<GetBookReques
public override void Configure() public override void Configure()
{ {
Get("/books/{@Id}", x => new {x.Id}); Get("/books/{@Id}", x => new {x.Id});
// Roles("viewer", "admin", "librarian"); Roles("viewer", "admin", "librarian");
AllowAnonymous();
} }
public override async Task HandleAsync(GetBookRequest req, CancellationToken ct) public override async Task HandleAsync(GetBookRequest req, CancellationToken ct)

View File

@@ -10,8 +10,7 @@ public class UpdateBookEndpoint(LibraryDbContext database) : Endpoint<UpdateBook
public override void Configure() public override void Configure()
{ {
Put("/books/{@Id}", x => new {x.Id}); Put("/books/{@Id}", x => new {x.Id});
// Roles("admin"); Roles("admin");
AllowAnonymous();
} }
public override async Task HandleAsync(UpdateBookDto req, CancellationToken ct) public override async Task HandleAsync(UpdateBookDto req, CancellationToken ct)

View File

@@ -10,8 +10,7 @@ public class CreateLoanEndpoint(LibraryDbContext database) : Endpoint<CreateLoan
public override void Configure() public override void Configure()
{ {
Post("/loans"); Post("/loans");
// Roles("admin", "librarian"); Roles("admin", "librarian");
AllowAnonymous();
} }
public override async Task HandleAsync(CreateLoanDto req, CancellationToken ct) public override async Task HandleAsync(CreateLoanDto req, CancellationToken ct)

View File

@@ -16,8 +16,7 @@ public class DeleteLoanEndpoint(LibraryDbContext database) : Endpoint<DeleteLoan
public override void Configure() public override void Configure()
{ {
Delete("/loans/{@Id}", x => new {x.Id}); Delete("/loans/{@Id}", x => new {x.Id});
// Roles("admin"); Roles("admin");
AllowAnonymous();
} }
public override async Task HandleAsync(DeleteLoanRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteLoanRequest req, CancellationToken ct)

View File

@@ -9,8 +9,7 @@ public class GetAllLoanEndpoint(LibraryDbContext database) : EndpointWithoutRequ
public override void Configure() public override void Configure()
{ {
Get("/loans"); Get("/loans");
// Roles("viewer", "admin", "librarian"); Roles("viewer", "admin", "librarian");
AllowAnonymous();
} }
public override async Task HandleAsync(CancellationToken ct) public override async Task HandleAsync(CancellationToken ct)

View File

@@ -14,8 +14,7 @@ public class GetLoanEndpoint(LibraryDbContext database) : Endpoint<GetLoanReques
public override void Configure() public override void Configure()
{ {
Get("/loans/{@Id}", x => new {x.Id}); Get("/loans/{@Id}", x => new {x.Id});
// Roles("viewer", "admin", "librarian"); Roles("viewer", "admin", "librarian");
AllowAnonymous();
} }
public override async Task HandleAsync(GetLoanRequest req, CancellationToken ct) public override async Task HandleAsync(GetLoanRequest req, CancellationToken ct)

View File

@@ -10,8 +10,7 @@ public class PatchLoanEndpoint(LibraryDbContext database) : Endpoint<PatchLoanDt
public override void Configure() public override void Configure()
{ {
Patch("/loans/{@Id}/EffectiveReturningDate", x => new {x.Id}); Patch("/loans/{@Id}/EffectiveReturningDate", x => new {x.Id});
// Roles("admin", "librarian"); Roles("admin", "librarian");
AllowAnonymous();
} }
public override async Task HandleAsync(PatchLoanDto req, CancellationToken ct) public override async Task HandleAsync(PatchLoanDto req, CancellationToken ct)

View File

@@ -10,8 +10,7 @@ public class UpdateLoanEndpoint(LibraryDbContext database) : Endpoint<UpdateLoan
public override void Configure() public override void Configure()
{ {
Put("/loans/{@Id}", x => new {x.Id}); Put("/loans/{@Id}", x => new {x.Id});
// Roles("admin", "librarian"); Roles("admin", "librarian");
AllowAnonymous();
} }
public override async Task HandleAsync(UpdateLoanDto req, CancellationToken ct) public override async Task HandleAsync(UpdateLoanDto req, CancellationToken ct)

View File

@@ -1,5 +1,4 @@
using System.IdentityModel.Tokens.Jwt; using System.IdentityModel.Tokens.Jwt;
using ApiEfCoreLibrary.DTO.Login.Response;
using ApiEfCoreLibrary.DTO.Refresh.Request; using ApiEfCoreLibrary.DTO.Refresh.Request;
using ApiEfCoreLibrary.DTO.Refresh.Response; using ApiEfCoreLibrary.DTO.Refresh.Response;
using FastEndpoints; using FastEndpoints;

View File

@@ -9,8 +9,7 @@ public class CreateUserEndpoint(LibraryDbContext database) : Endpoint<CreateUser
public override void Configure() public override void Configure()
{ {
Post("/users"); Post("/users");
// Roles("admin"); Roles("admin");
AllowAnonymous();
} }
public override async Task HandleAsync(CreateUserDto req, CancellationToken ct) public override async Task HandleAsync(CreateUserDto req, CancellationToken ct)

View File

@@ -15,8 +15,7 @@ public class DeleteUserEndpoint(LibraryDbContext database) : Endpoint<DeleteUser
public override void Configure() public override void Configure()
{ {
Delete("/users/{@Id}", x => new {x.Id}); Delete("/users/{@Id}", x => new {x.Id});
// Roles("admin"); Roles("admin");
AllowAnonymous();
} }
public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct)

View File

@@ -10,8 +10,7 @@ public class GetAllUsersEndpoint(LibraryDbContext database) : EndpointWithoutReq
public override void Configure() public override void Configure()
{ {
Get("/users"); Get("/users");
// Roles("viewer", "admin", "librarian"); Roles("viewer", "admin", "librarian");
AllowAnonymous();
} }
public override async Task HandleAsync(CancellationToken ct) public override async Task HandleAsync(CancellationToken ct)

View File

@@ -16,8 +16,7 @@ public class GetUserEndpoint(LibraryDbContext database) : Endpoint<GetUserReques
public override void Configure() public override void Configure()
{ {
Get("/users/{@Id}", x => new {x.Id}); Get("/users/{@Id}", x => new {x.Id});
// Roles("viewer", "admin", "librarian"); Roles("viewer", "admin", "librarian");
AllowAnonymous();
} }
public override async Task HandleAsync(GetUserRequest req, CancellationToken ct) public override async Task HandleAsync(GetUserRequest req, CancellationToken ct)

View File

@@ -10,8 +10,7 @@ public class UpdateUserEndpoint(LibraryDbContext database) : Endpoint<UpdateUser
public override void Configure() public override void Configure()
{ {
Put("/users/{@Id}", x => new {x.Id}); Put("/users/{@Id}", x => new {x.Id});
// Roles("admin"); Roles("admin");
AllowAnonymous();
} }
public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct) public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct)

View File

@@ -7,8 +7,8 @@ WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// On ajoute ici FastEndpoints, un framework REPR et Swagger aux services disponibles dans le projet // On ajoute ici FastEndpoints, un framework REPR et Swagger aux services disponibles dans le projet
builder.Services builder.Services
//.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong") .AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong")
//.AddAuthorization() .AddAuthorization()
.AddFastEndpoints() .AddFastEndpoints()
.AddCors(options => .AddCors(options =>
{ {
@@ -29,8 +29,8 @@ builder.Services.AddDbContext<LibraryDbContext>();
// On construit l'application en lui donnant vie // On construit l'application en lui donnant vie
WebApplication app = builder.Build(); WebApplication app = builder.Build();
app//.UseAuthentication() app.UseAuthentication()
//.UseAuthorization() .UseAuthorization()
.UseFastEndpoints(options => .UseFastEndpoints(options =>
{ {
options.Endpoints.ShortNames = true; options.Endpoints.ShortNames = true;
@@ -38,7 +38,7 @@ app//.UseAuthentication()
}) })
.UseSwaggerGen(); .UseSwaggerGen();
app.UseHttpsRedirection(); // app.UseHttpsRedirection();
app.UseCors(); app.UseCors();