Skip to content
Snippets Groups Projects
Commit 3686be8e authored by Tomáš Zaťko's avatar Tomáš Zaťko
Browse files

updated Filter endpoint - added publisher

parent e83291a2
No related branches found
No related tags found
2 merge requests!31Milestone 1,!28fix: fixed BookController endpoints
...@@ -162,7 +162,14 @@ namespace WebAPI.Controllers ...@@ -162,7 +162,14 @@ namespace WebAPI.Controllers
[HttpGet] [HttpGet]
[Route("filter")] [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(); var query = _dbContext.Books.AsQueryable();
...@@ -196,6 +203,11 @@ namespace WebAPI.Controllers ...@@ -196,6 +203,11 @@ namespace WebAPI.Controllers
query = query.Where(book => book.AuthorId == authorId); query = query.Where(book => book.AuthorId == authorId);
} }
if (!string.IsNullOrWhiteSpace(publisher))
{
query = query.Where(book => book.Publisher.Contains(publisher));
}
var filteredBooks = await query.ToListAsync(); var filteredBooks = await query.ToListAsync();
if (!filteredBooks.Any()) if (!filteredBooks.Any())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment