Skip to content
Snippets Groups Projects

fix: fixed BookController endpoints

Merged Tomáš Zaťko requested to merge fix/fixed-book-controller-endpoint into milestone-1
1 file
+ 13
1
Compare changes
  • Side-by-side
  • Inline
@@ -162,7 +162,14 @@ namespace WebAPI.Controllers
[HttpGet]
[Route("filter")]
public async Task<IActionResult> FilterBooks(string? name, string? description, decimal? minPrice, decimal? maxPrice, BookGenre? genre, int? authorId)
public async Task<IActionResult> FilterBooks(
string? name,
string? description,
decimal? minPrice,
decimal? maxPrice,
BookGenre? genre,
int? authorId,
string? publisher)
{
var query = _dbContext.Books.AsQueryable();
@@ -196,6 +203,11 @@ namespace WebAPI.Controllers
query = query.Where(book => book.AuthorId == authorId);
}
if (!string.IsNullOrWhiteSpace(publisher))
{
query = query.Where(book => book.Publisher.Contains(publisher));
}
var filteredBooks = await query.ToListAsync();
if (!filteredBooks.Any())
Loading