embryo till sök
This commit is contained in:
@@ -10,6 +10,7 @@ namespace Bibblan.Business.Services
|
||||
public class BookFilter
|
||||
{
|
||||
public int? Author;
|
||||
public string? Query;
|
||||
}
|
||||
|
||||
public class DatabaseService
|
||||
@@ -29,14 +30,23 @@ namespace Bibblan.Business.Services
|
||||
if(filter.Author != null)
|
||||
{
|
||||
query += $"id in (select book from books_authors_link where author = {filter.Author})";
|
||||
} else if(!String.IsNullOrWhiteSpace(query))
|
||||
{
|
||||
filter.Query = filter.Query.ToLowerInvariant();
|
||||
query += $"lower(title) like '%{filter.Query}%' or lower(author_sort) like '%{filter.Query}%'";
|
||||
}
|
||||
}
|
||||
return conn.Query<Books>(query).Take(count).ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<AuthorVm> GetAuthors(int count)
|
||||
public IEnumerable<AuthorVm> GetAuthors(int count, BookFilter filter = null)
|
||||
{
|
||||
var query = "select a.id, a.name, count(bal.*) as bookcount\r\nfrom authors a\r\nleft join books_authors_link bal on a.id = bal.author\r\ngroup by a.id , a.name ";
|
||||
if(!String.IsNullOrWhiteSpace(filter?.Query))
|
||||
{
|
||||
filter.Query = filter.Query.ToLowerInvariant();
|
||||
query += $" having lower(a.name) like '%{filter.Query}%'";
|
||||
}
|
||||
var conn = new NpgsqlConnection(settings.BibblanConnection);
|
||||
return conn.Query<AuthorVm>(query).Take(count).ToList();
|
||||
|
||||
|
Reference in New Issue
Block a user