Skip to content

Commit 00debf1

Browse files
committed
feat: Add filtering by author, category, and publisher to the book search endpoint.
1 parent 65b3aa4 commit 00debf1

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/ApiService/BookStore.ApiService/Endpoints/BookEndpoints.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ static async Task<Ok<PagedListDto<BookDto>>> SearchBooks(
3939
[FromServices] IOptions<LocalizationOptions> localizationOptions,
4040
[AsParameters] PagedRequest request,
4141
HttpContext context,
42-
[FromQuery] string? search = null)
42+
[FromQuery] string? search = null,
43+
[FromQuery] Guid? authorId = null,
44+
[FromQuery] Guid? categoryId = null,
45+
[FromQuery] Guid? publisherId = null)
4346
{
4447
var paging = request.Normalize(paginationOptions.Value);
4548

@@ -68,6 +71,21 @@ static async Task<Ok<PagedListDto<BookDto>>> SearchBooks(
6871
(b.Isbn != null && b.Isbn.Contains(searchQuery)));
6972
}
7073

74+
if (authorId.HasValue)
75+
{
76+
query = (Marten.Linq.IMartenQueryable<BookSearchProjection>)query.Where(b => b.AuthorIds.Contains(authorId.Value));
77+
}
78+
79+
if (categoryId.HasValue)
80+
{
81+
query = (Marten.Linq.IMartenQueryable<BookSearchProjection>)query.Where(b => b.CategoryIds.Contains(categoryId.Value));
82+
}
83+
84+
if (publisherId.HasValue)
85+
{
86+
query = (Marten.Linq.IMartenQueryable<BookSearchProjection>)query.Where(b => b.PublisherId == publisherId.Value);
87+
}
88+
7189
// Execute query with pagination
7290
var pagedList = await query
7391
.OrderBy(b => b.Title)

0 commit comments

Comments
 (0)