deleted all var

This commit is contained in:
2025-11-17 22:23:53 +01:00
parent ca0e074362
commit 95d321234d
27 changed files with 86 additions and 86 deletions

View File

@@ -1,8 +1,8 @@
using ApiEfCoreLibrary.DTO.Author.Request; using ApiEfCoreLibrary.DTO.Author.Request;
using ApiEfCoreLibrary.DTO.Author.Response; using ApiEfCoreLibrary.DTO.Author.Response;
using FastEndpoints;
namespace ApiEfCoreLibrary.Endpoints.Author; namespace ApiEfCoreLibrary.Endpoints.Author;
using FastEndpoints;
public class CreateAuthorEndpoint(LibraryDbContext database) : Endpoint<CreateAuthorDto, GetAuthorDto> public class CreateAuthorEndpoint(LibraryDbContext database) : Endpoint<CreateAuthorDto, GetAuthorDto>
{ {
@@ -14,7 +14,7 @@ public class CreateAuthorEndpoint(LibraryDbContext database) : Endpoint<CreateAu
public override async Task HandleAsync(CreateAuthorDto req, CancellationToken ct) public override async Task HandleAsync(CreateAuthorDto req, CancellationToken ct)
{ {
var author = new Models.Author() Models.Author author = new Models.Author()
{ {
Name = req.Name, Name = req.Name,
FirstName = req.FirstName FirstName = req.FirstName

View File

@@ -20,7 +20,7 @@ public class DeleteAuthorEndpoint(LibraryDbContext database) : Endpoint<DeleteAu
public override async Task HandleAsync(DeleteAuthorRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteAuthorRequest req, CancellationToken ct)
{ {
var author = await database.Authors.SingleOrDefaultAsync(x => x.Id == req.Id, ct); Models.Author? author = await database.Authors.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (author == null) if (author == null)
{ {

View File

@@ -15,7 +15,7 @@ public class GetAllAuthorsEndpoint(LibraryDbContext database) : EndpointWithoutR
public override async Task HandleAsync(CancellationToken ct) public override async Task HandleAsync(CancellationToken ct)
{ {
var authors = await database.Authors List<GetAuthorDto> authors = await database.Authors
.Include(x => x.Books) .Include(x => x.Books)
.Select(author => new GetAuthorDto() .Select(author => new GetAuthorDto()
{ {

View File

@@ -21,7 +21,7 @@ public class GetAuthorEndpoint(LibraryDbContext database) : Endpoint<GetAuthorRe
public override async Task HandleAsync(GetAuthorRequest req, CancellationToken ct) public override async Task HandleAsync(GetAuthorRequest req, CancellationToken ct)
{ {
var author = await database.Authors Models.Author? author = await database.Authors
.Include(x => x.Books) .Include(x => x.Books)
.SingleOrDefaultAsync(x => x.Id == req.Id, ct); .SingleOrDefaultAsync(x => x.Id == req.Id, ct);

View File

@@ -16,7 +16,7 @@ public class UpdateAuthorEndpoint(LibraryDbContext database) : Endpoint<UpdateAu
public override async Task HandleAsync(UpdateAuthorDto req, CancellationToken ct) public override async Task HandleAsync(UpdateAuthorDto req, CancellationToken ct)
{ {
var author = await database.Authors.SingleOrDefaultAsync(x => x.Id == req.Id, ct); Models.Author? author = await database.Authors.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (author == null) if (author == null)
{ {

View File

@@ -15,7 +15,7 @@ public class CreateBookEndpoint(LibraryDbContext database) : Endpoint<CreateBook
public override async Task HandleAsync(CreateBookDto req, CancellationToken ct) public override async Task HandleAsync(CreateBookDto req, CancellationToken ct)
{ {
var authorExists = await database.Authors.FirstOrDefaultAsync(a => a.Id == req.AuthorId, ct); Models.Author? authorExists = await database.Authors.FirstOrDefaultAsync(a => a.Id == req.AuthorId, ct);
if (authorExists == null) if (authorExists == null)
{ {
@@ -23,7 +23,7 @@ public class CreateBookEndpoint(LibraryDbContext database) : Endpoint<CreateBook
return; return;
} }
var book = new Models.Book() Models.Book book = new Models.Book()
{ {
Title = req.Title, Title = req.Title,
AuthorId = req.AuthorId, AuthorId = req.AuthorId,

View File

@@ -21,7 +21,7 @@ public class DeleteBookEndpoint(LibraryDbContext database) : Endpoint<DeleteBook
public override async Task HandleAsync(DeleteBookRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteBookRequest req, CancellationToken ct)
{ {
var book = await database.Books.SingleOrDefaultAsync(x => x.Id == req.Id, ct); Models.Book? book = await database.Books.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (book == null) if (book == null)
{ {

View File

@@ -13,7 +13,7 @@ public class GetAllBooksEndpoint(LibraryDbContext database) : EndpointWithoutReq
public override async Task HandleAsync(CancellationToken ct) public override async Task HandleAsync(CancellationToken ct)
{ {
var books = await database.Books List<GetBookDto> books = await database.Books
.Include(b => b.Author) .Include(b => b.Author)
.Select(book => new GetBookDto() .Select(book => new GetBookDto()
{ {

View File

@@ -18,7 +18,7 @@ public class GetBookEndpoint(LibraryDbContext database) : Endpoint<GetBookReques
public override async Task HandleAsync(GetBookRequest req, CancellationToken ct) public override async Task HandleAsync(GetBookRequest req, CancellationToken ct)
{ {
var book = await database.Books.Include(b => b.Author).SingleOrDefaultAsync(x => x.Id == req.Id, ct); Models.Book? book = await database.Books.Include(b => b.Author).SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (book == null) if (book == null)
{ {

View File

@@ -15,7 +15,7 @@ public class UpdateBookEndpoint(LibraryDbContext database) : Endpoint<UpdateBook
public override async Task HandleAsync(UpdateBookDto req, CancellationToken ct) public override async Task HandleAsync(UpdateBookDto req, CancellationToken ct)
{ {
var book = await database.Books.SingleOrDefaultAsync(x => x.Id == req.Id, ct); Models.Book? book = await database.Books.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (book == null) if (book == null)
{ {
@@ -23,7 +23,7 @@ public class UpdateBookEndpoint(LibraryDbContext database) : Endpoint<UpdateBook
return; return;
} }
var authorExists = await database.Authors.FirstOrDefaultAsync(a => a.Id == req.AuthorId, ct); Models.Author? authorExists = await database.Authors.FirstOrDefaultAsync(a => a.Id == req.AuthorId, ct);
if (authorExists == null) if (authorExists == null)
{ {

View File

@@ -15,7 +15,7 @@ public class CreateLoanEndpoint(LibraryDbContext database) : Endpoint<CreateLoan
public override async Task HandleAsync(CreateLoanDto req, CancellationToken ct) public override async Task HandleAsync(CreateLoanDto req, CancellationToken ct)
{ {
var bookExists = await database.Books.FirstOrDefaultAsync(a => a.Id == req.BookId, ct); Models.Book? bookExists = await database.Books.FirstOrDefaultAsync(a => a.Id == req.BookId, ct);
if (bookExists == null) if (bookExists == null)
{ {
@@ -23,7 +23,7 @@ public class CreateLoanEndpoint(LibraryDbContext database) : Endpoint<CreateLoan
return; return;
} }
var userExists = await database.Users.FirstOrDefaultAsync(a => a.Id == req.UserId, ct); Models.User? userExists = await database.Users.FirstOrDefaultAsync(a => a.Id == req.UserId, ct);
if (userExists == null) if (userExists == null)
{ {
@@ -31,7 +31,7 @@ public class CreateLoanEndpoint(LibraryDbContext database) : Endpoint<CreateLoan
return; return;
} }
var loan = new Models.Loan() Models.Loan loan = new Models.Loan()
{ {
BookId = req.BookId, BookId = req.BookId,
UserId = req.UserId, UserId = req.UserId,

View File

@@ -21,7 +21,7 @@ public class DeleteLoanEndpoint(LibraryDbContext database) : Endpoint<DeleteLoan
public override async Task HandleAsync(DeleteLoanRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteLoanRequest req, CancellationToken ct)
{ {
var loan = await database.Loans.SingleOrDefaultAsync(x => x.Id == req.Id, ct); Models.Loan? loan = await database.Loans.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (loan == null) if (loan == null)
{ {

View File

@@ -13,7 +13,7 @@ public class GetAllLoanEndpoint(LibraryDbContext database) : EndpointWithoutRequ
public override async Task HandleAsync(CancellationToken ct) public override async Task HandleAsync(CancellationToken ct)
{ {
var loans = await database.Loans List<GetLoanDto> loans = await database.Loans
.Include(l => l.Book) .Include(l => l.Book)
.ThenInclude(b => b.Author) .ThenInclude(b => b.Author)
.Include(l => l.User) .Include(l => l.User)

View File

@@ -18,7 +18,7 @@ public class GetLoanEndpoint(LibraryDbContext database) : Endpoint<GetLoanReques
public override async Task HandleAsync(GetLoanRequest req, CancellationToken ct) public override async Task HandleAsync(GetLoanRequest req, CancellationToken ct)
{ {
var loan = await database.Loans.Include(l => l.Book) Models.Loan? loan = await database.Loans.Include(l => l.Book)
.ThenInclude(b => b.Author) .ThenInclude(b => b.Author)
.Include(l => l.User) .Include(l => l.User)
.SingleOrDefaultAsync(x => x.Id == req.Id, ct); .SingleOrDefaultAsync(x => x.Id == req.Id, ct);

View File

@@ -1,53 +1,53 @@
using ApiEfCoreLibrary.DTO.Loan.Request; using ApiEfCoreLibrary.DTO.Loan.Request;
using ApiEfCoreLibrary.DTO.Loan.Response; using ApiEfCoreLibrary.DTO.Loan.Response;
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace ApiEfCoreLibrary.Endpoints.Loan; namespace ApiEfCoreLibrary.Endpoints.Loan;
public class PatchLoanEndpoint(LibraryDbContext database) : Endpoint<PatchLoanDto, GetLoanDto> public class PatchLoanEndpoint(LibraryDbContext database) : Endpoint<PatchLoanDto, GetLoanDto>
{ {
public override void Configure() public override void Configure()
{ {
Patch("/api/loans/{@Id}/EffectiveReturningDate", x => new {x.Id}); Patch("/api/loans/{@Id}/EffectiveReturningDate", x => new {x.Id});
Roles("admin", "librarian"); Roles("admin", "librarian");
} }
public override async Task HandleAsync(PatchLoanDto req, CancellationToken ct) public override async Task HandleAsync(PatchLoanDto req, CancellationToken ct)
{ {
var loan = await database.Loans.SingleOrDefaultAsync(x => x.Id == req.Id, ct); Models.Loan? loan = await database.Loans.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (loan == null) if (loan == null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
if (req.EffectiveReturningDate <= DateOnly.FromDateTime(DateTime.Now)) if (req.EffectiveReturningDate <= DateOnly.FromDateTime(DateTime.Now))
{ {
await Send.StringAsync("Erreur de date. La date est inférieure à la date actuelle.", 400); await Send.StringAsync("Erreur de date. La date est inférieure à la date actuelle.", 400);
return; return;
} }
if (loan.EffectiveReturningDate != null) if (loan.EffectiveReturningDate != null)
{ {
await Send.StringAsync("Impossible de modifier la date de retour.", 400); await Send.StringAsync("Impossible de modifier la date de retour.", 400);
return; return;
} }
loan.EffectiveReturningDate = req.EffectiveReturningDate; loan.EffectiveReturningDate = req.EffectiveReturningDate;
await database.SaveChangesAsync(ct); await database.SaveChangesAsync(ct);
GetLoanDto responseDto = new() GetLoanDto responseDto = new()
{ {
Id = loan.Id, Id = loan.Id,
BookId = loan.BookId, BookId = loan.BookId,
UserId = loan.UserId, UserId = loan.UserId,
Date = loan.Date, Date = loan.Date,
PlannedReturningDate = loan.PlannedReturningDate, PlannedReturningDate = loan.PlannedReturningDate,
EffectiveReturningDate = loan.EffectiveReturningDate EffectiveReturningDate = loan.EffectiveReturningDate
}; };
await Send.OkAsync(responseDto, ct); await Send.OkAsync(responseDto, ct);
} }
} }

View File

@@ -15,7 +15,7 @@ public class UpdateLoanEndpoint(LibraryDbContext database) : Endpoint<UpdateLoan
public override async Task HandleAsync(UpdateLoanDto req, CancellationToken ct) public override async Task HandleAsync(UpdateLoanDto req, CancellationToken ct)
{ {
var loan = await database.Loans.SingleOrDefaultAsync(x => x.Id == req.Id, ct); Models.Loan? loan = await database.Loans.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (loan == null) if (loan == null)
{ {
@@ -23,7 +23,7 @@ public class UpdateLoanEndpoint(LibraryDbContext database) : Endpoint<UpdateLoan
return; return;
} }
var bookExists = await database.Books.FirstOrDefaultAsync(a => a.Id == req.BookId, ct); Models.Book? bookExists = await database.Books.FirstOrDefaultAsync(a => a.Id == req.BookId, ct);
if (bookExists == null) if (bookExists == null)
{ {
@@ -31,7 +31,7 @@ public class UpdateLoanEndpoint(LibraryDbContext database) : Endpoint<UpdateLoan
return; return;
} }
var userExists = await database.Users.FirstOrDefaultAsync(a => a.Id == req.UserId, ct); Models.User? userExists = await database.Users.FirstOrDefaultAsync(a => a.Id == req.UserId, ct);
if (userExists == null) if (userExists == null)
{ {

View File

@@ -17,7 +17,7 @@ public class CreateLoginEndpoint(LibraryDbContext database) : Endpoint<CreateLog
{ {
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next(); string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
var login = new Models.Login() Models.Login login = new Models.Login()
{ {
Username = req.Username, Username = req.Username,
FullName = req.FullName, FullName = req.FullName,

View File

@@ -19,7 +19,7 @@ public class DeleteLoginEndpoint(LibraryDbContext database) : Endpoint<DeleteLog
public override async Task HandleAsync(DeleteLoginRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteLoginRequest req, CancellationToken ct)
{ {
var login = await database.Logins.SingleOrDefaultAsync(x => x.Id == req.Id, ct); Models.Login? login = await database.Logins.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (login == null) if (login == null)
{ {

View File

@@ -14,7 +14,7 @@ public class GetAllLoginEndpoint(LibraryDbContext database) : EndpointWithoutReq
public override async Task HandleAsync(CancellationToken ct) public override async Task HandleAsync(CancellationToken ct)
{ {
var logins = await database.Logins List<GetLoginDto> logins = await database.Logins
.Select(login => new GetLoginDto() .Select(login => new GetLoginDto()
{ {
Id = login.Id, Id = login.Id,

View File

@@ -18,7 +18,7 @@ public class GetLoginEndpoint(LibraryDbContext database) : Endpoint<GetLoginRequ
public override async Task HandleAsync(GetLoginRequest req, CancellationToken ct) public override async Task HandleAsync(GetLoginRequest req, CancellationToken ct)
{ {
var login = await database.Logins Models.Login? login = await database.Logins
.SingleOrDefaultAsync(x => x.Id == req.Id, ct); .SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (login == null) if (login == null)

View File

@@ -16,7 +16,7 @@ public class UpdateLoginEndpoint(LibraryDbContext database) : Endpoint<UpdateLog
public override async Task HandleAsync(UpdateLoginDto req, CancellationToken ct) public override async Task HandleAsync(UpdateLoginDto req, CancellationToken ct)
{ {
var login = await database.Logins.SingleOrDefaultAsync(x => x.Id == req.Id, ct); Models.Login? login = await database.Logins.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (login == null) if (login == null)
{ {

View File

@@ -16,7 +16,7 @@ public class UserLoginEndpoint(LibraryDbContext database) : Endpoint<ConnectLogi
public override async Task HandleAsync(ConnectLoginDto req, CancellationToken ct) public override async Task HandleAsync(ConnectLoginDto req, CancellationToken ct)
{ {
var login = await database.Logins.SingleOrDefaultAsync(x => x.Username == req.Username, ct); Models.Login? login = await database.Logins.SingleOrDefaultAsync(x => x.Username == req.Username, ct);
if (login == null) if (login == null)
{ {
@@ -26,7 +26,7 @@ public class UserLoginEndpoint(LibraryDbContext database) : Endpoint<ConnectLogi
if (BCrypt.Net.BCrypt.Verify(req.Password + login.Salt, login.Password)) if (BCrypt.Net.BCrypt.Verify(req.Password + login.Salt, login.Password))
{ {
var jwtToken = JwtBearer.CreateToken( string jwtToken = JwtBearer.CreateToken(
o => o =>
{ {
o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong"; o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong";

View File

@@ -14,7 +14,7 @@ public class CreateUserEndpoint(LibraryDbContext database) : Endpoint<CreateUser
public override async Task HandleAsync(CreateUserDto req, CancellationToken ct) public override async Task HandleAsync(CreateUserDto req, CancellationToken ct)
{ {
var user = new Models.User() Models.User user = new Models.User()
{ {
Name = req.Name, Name = req.Name,
FirstName = req.FirstName, FirstName = req.FirstName,

View File

@@ -20,7 +20,7 @@ public class DeleteUserEndpoint(LibraryDbContext database) : Endpoint<DeleteUser
public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct)
{ {
var user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct); Models.User? user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (user == null) if (user == null)
{ {

View File

@@ -14,7 +14,7 @@ public class GetAllUsersEndpoint(LibraryDbContext database) : EndpointWithoutReq
public override async Task HandleAsync(CancellationToken ct) public override async Task HandleAsync(CancellationToken ct)
{ {
var user = await database.Users List<GetUserDto> user = await database.Users
.Include(x => x.Loans)! .Include(x => x.Loans)!
.ThenInclude(l => l.Book) .ThenInclude(l => l.Book)
.ThenInclude(b => b!.Author) .ThenInclude(b => b!.Author)

View File

@@ -20,7 +20,7 @@ public class GetUserEndpoint(LibraryDbContext database) : Endpoint<GetUserReques
public override async Task HandleAsync(GetUserRequest req, CancellationToken ct) public override async Task HandleAsync(GetUserRequest req, CancellationToken ct)
{ {
var user = await database.Users Models.User? user = await database.Users
.Include(x => x.Loans)! .Include(x => x.Loans)!
.ThenInclude(l => l.Book) .ThenInclude(l => l.Book)
.ThenInclude(b => b!.Author) .ThenInclude(b => b!.Author)

View File

@@ -15,7 +15,7 @@ public class UpdateUserEndpoint(LibraryDbContext database) : Endpoint<UpdateUser
public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct) public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct)
{ {
var user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct); Models.User? user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (user == null) if (user == null)
{ {