deleted all var
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using ApiEfCoreLibrary.DTO.Author.Request;
|
||||
using ApiEfCoreLibrary.DTO.Author.Response;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace ApiEfCoreLibrary.Endpoints.Author;
|
||||
using FastEndpoints;
|
||||
|
||||
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)
|
||||
{
|
||||
var author = new Models.Author()
|
||||
Models.Author author = new Models.Author()
|
||||
{
|
||||
Name = req.Name,
|
||||
FirstName = req.FirstName
|
||||
|
||||
@@ -20,7 +20,7 @@ public class DeleteAuthorEndpoint(LibraryDbContext database) : Endpoint<DeleteAu
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ public class GetAllAuthorsEndpoint(LibraryDbContext database) : EndpointWithoutR
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var authors = await database.Authors
|
||||
List<GetAuthorDto> authors = await database.Authors
|
||||
.Include(x => x.Books)
|
||||
.Select(author => new GetAuthorDto()
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ public class GetAuthorEndpoint(LibraryDbContext database) : Endpoint<GetAuthorRe
|
||||
|
||||
public override async Task HandleAsync(GetAuthorRequest req, CancellationToken ct)
|
||||
{
|
||||
var author = await database.Authors
|
||||
Models.Author? author = await database.Authors
|
||||
.Include(x => x.Books)
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class UpdateAuthorEndpoint(LibraryDbContext database) : Endpoint<UpdateAu
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ public class CreateBookEndpoint(LibraryDbContext database) : Endpoint<CreateBook
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -23,7 +23,7 @@ public class CreateBookEndpoint(LibraryDbContext database) : Endpoint<CreateBook
|
||||
return;
|
||||
}
|
||||
|
||||
var book = new Models.Book()
|
||||
Models.Book book = new Models.Book()
|
||||
{
|
||||
Title = req.Title,
|
||||
AuthorId = req.AuthorId,
|
||||
|
||||
@@ -21,7 +21,7 @@ public class DeleteBookEndpoint(LibraryDbContext database) : Endpoint<DeleteBook
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ public class GetAllBooksEndpoint(LibraryDbContext database) : EndpointWithoutReq
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var books = await database.Books
|
||||
List<GetBookDto> books = await database.Books
|
||||
.Include(b => b.Author)
|
||||
.Select(book => new GetBookDto()
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ public class GetBookEndpoint(LibraryDbContext database) : Endpoint<GetBookReques
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ public class UpdateBookEndpoint(LibraryDbContext database) : Endpoint<UpdateBook
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -23,7 +23,7 @@ public class UpdateBookEndpoint(LibraryDbContext database) : Endpoint<UpdateBook
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ public class CreateLoanEndpoint(LibraryDbContext database) : Endpoint<CreateLoan
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -23,7 +23,7 @@ public class CreateLoanEndpoint(LibraryDbContext database) : Endpoint<CreateLoan
|
||||
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)
|
||||
{
|
||||
@@ -31,7 +31,7 @@ public class CreateLoanEndpoint(LibraryDbContext database) : Endpoint<CreateLoan
|
||||
return;
|
||||
}
|
||||
|
||||
var loan = new Models.Loan()
|
||||
Models.Loan loan = new Models.Loan()
|
||||
{
|
||||
BookId = req.BookId,
|
||||
UserId = req.UserId,
|
||||
|
||||
@@ -21,7 +21,7 @@ public class DeleteLoanEndpoint(LibraryDbContext database) : Endpoint<DeleteLoan
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ public class GetAllLoanEndpoint(LibraryDbContext database) : EndpointWithoutRequ
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var loans = await database.Loans
|
||||
List<GetLoanDto> loans = await database.Loans
|
||||
.Include(l => l.Book)
|
||||
.ThenInclude(b => b.Author)
|
||||
.Include(l => l.User)
|
||||
|
||||
@@ -18,7 +18,7 @@ public class GetLoanEndpoint(LibraryDbContext database) : Endpoint<GetLoanReques
|
||||
|
||||
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)
|
||||
.Include(l => l.User)
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
using ApiEfCoreLibrary.DTO.Loan.Request;
|
||||
using ApiEfCoreLibrary.DTO.Loan.Response;
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiEfCoreLibrary.Endpoints.Loan;
|
||||
|
||||
public class PatchLoanEndpoint(LibraryDbContext database) : Endpoint<PatchLoanDto, GetLoanDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/loans/{@Id}/EffectiveReturningDate", x => new {x.Id});
|
||||
Roles("admin", "librarian");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchLoanDto req, CancellationToken ct)
|
||||
{
|
||||
var loan = await database.Loans.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (loan == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.EffectiveReturningDate <= DateOnly.FromDateTime(DateTime.Now))
|
||||
{
|
||||
await Send.StringAsync("Erreur de date. La date est inférieure à la date actuelle.", 400);
|
||||
return;
|
||||
}
|
||||
|
||||
if (loan.EffectiveReturningDate != null)
|
||||
{
|
||||
await Send.StringAsync("Impossible de modifier la date de retour.", 400);
|
||||
return;
|
||||
}
|
||||
|
||||
loan.EffectiveReturningDate = req.EffectiveReturningDate;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetLoanDto responseDto = new()
|
||||
{
|
||||
Id = loan.Id,
|
||||
BookId = loan.BookId,
|
||||
UserId = loan.UserId,
|
||||
Date = loan.Date,
|
||||
PlannedReturningDate = loan.PlannedReturningDate,
|
||||
EffectiveReturningDate = loan.EffectiveReturningDate
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
using ApiEfCoreLibrary.DTO.Loan.Request;
|
||||
using ApiEfCoreLibrary.DTO.Loan.Response;
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ApiEfCoreLibrary.Endpoints.Loan;
|
||||
|
||||
public class PatchLoanEndpoint(LibraryDbContext database) : Endpoint<PatchLoanDto, GetLoanDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/loans/{@Id}/EffectiveReturningDate", x => new {x.Id});
|
||||
Roles("admin", "librarian");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchLoanDto req, CancellationToken ct)
|
||||
{
|
||||
Models.Loan? loan = await database.Loans.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (loan == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.EffectiveReturningDate <= DateOnly.FromDateTime(DateTime.Now))
|
||||
{
|
||||
await Send.StringAsync("Erreur de date. La date est inférieure à la date actuelle.", 400);
|
||||
return;
|
||||
}
|
||||
|
||||
if (loan.EffectiveReturningDate != null)
|
||||
{
|
||||
await Send.StringAsync("Impossible de modifier la date de retour.", 400);
|
||||
return;
|
||||
}
|
||||
|
||||
loan.EffectiveReturningDate = req.EffectiveReturningDate;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetLoanDto responseDto = new()
|
||||
{
|
||||
Id = loan.Id,
|
||||
BookId = loan.BookId,
|
||||
UserId = loan.UserId,
|
||||
Date = loan.Date,
|
||||
PlannedReturningDate = loan.PlannedReturningDate,
|
||||
EffectiveReturningDate = loan.EffectiveReturningDate
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class UpdateLoanEndpoint(LibraryDbContext database) : Endpoint<UpdateLoan
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -23,7 +23,7 @@ public class UpdateLoanEndpoint(LibraryDbContext database) : Endpoint<UpdateLoan
|
||||
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)
|
||||
{
|
||||
@@ -31,7 +31,7 @@ public class UpdateLoanEndpoint(LibraryDbContext database) : Endpoint<UpdateLoan
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ public class CreateLoginEndpoint(LibraryDbContext database) : Endpoint<CreateLog
|
||||
{
|
||||
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
|
||||
|
||||
var login = new Models.Login()
|
||||
Models.Login login = new Models.Login()
|
||||
{
|
||||
Username = req.Username,
|
||||
FullName = req.FullName,
|
||||
|
||||
@@ -19,7 +19,7 @@ public class DeleteLoginEndpoint(LibraryDbContext database) : Endpoint<DeleteLog
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ public class GetAllLoginEndpoint(LibraryDbContext database) : EndpointWithoutReq
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var logins = await database.Logins
|
||||
List<GetLoginDto> logins = await database.Logins
|
||||
.Select(login => new GetLoginDto()
|
||||
{
|
||||
Id = login.Id,
|
||||
|
||||
@@ -18,7 +18,7 @@ public class GetLoginEndpoint(LibraryDbContext database) : Endpoint<GetLoginRequ
|
||||
|
||||
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);
|
||||
|
||||
if (login == null)
|
||||
|
||||
@@ -16,7 +16,7 @@ public class UpdateLoginEndpoint(LibraryDbContext database) : Endpoint<UpdateLog
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@ public class UserLoginEndpoint(LibraryDbContext database) : Endpoint<ConnectLogi
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -26,7 +26,7 @@ public class UserLoginEndpoint(LibraryDbContext database) : Endpoint<ConnectLogi
|
||||
|
||||
if (BCrypt.Net.BCrypt.Verify(req.Password + login.Salt, login.Password))
|
||||
{
|
||||
var jwtToken = JwtBearer.CreateToken(
|
||||
string jwtToken = JwtBearer.CreateToken(
|
||||
o =>
|
||||
{
|
||||
o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong";
|
||||
|
||||
@@ -14,7 +14,7 @@ public class CreateUserEndpoint(LibraryDbContext database) : Endpoint<CreateUser
|
||||
|
||||
public override async Task HandleAsync(CreateUserDto req, CancellationToken ct)
|
||||
{
|
||||
var user = new Models.User()
|
||||
Models.User user = new Models.User()
|
||||
{
|
||||
Name = req.Name,
|
||||
FirstName = req.FirstName,
|
||||
|
||||
@@ -20,7 +20,7 @@ public class DeleteUserEndpoint(LibraryDbContext database) : Endpoint<DeleteUser
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ public class GetAllUsersEndpoint(LibraryDbContext database) : EndpointWithoutReq
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var user = await database.Users
|
||||
List<GetUserDto> user = await database.Users
|
||||
.Include(x => x.Loans)!
|
||||
.ThenInclude(l => l.Book)
|
||||
.ThenInclude(b => b!.Author)
|
||||
|
||||
@@ -20,7 +20,7 @@ public class GetUserEndpoint(LibraryDbContext database) : Endpoint<GetUserReques
|
||||
|
||||
public override async Task HandleAsync(GetUserRequest req, CancellationToken ct)
|
||||
{
|
||||
var user = await database.Users
|
||||
Models.User? user = await database.Users
|
||||
.Include(x => x.Loans)!
|
||||
.ThenInclude(l => l.Book)
|
||||
.ThenInclude(b => b!.Author)
|
||||
|
||||
@@ -15,7 +15,7 @@ public class UpdateUserEndpoint(LibraryDbContext database) : Endpoint<UpdateUser
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user