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();
|
||||
|
||||
|
@@ -25,16 +25,26 @@ namespace Bibblan.Controllers
|
||||
}
|
||||
|
||||
[HttpGet("books")]
|
||||
public IActionResult GetBooks()
|
||||
public IActionResult GetBooks(string query = null)
|
||||
{
|
||||
var authors = _db.GetBooks(100).ToList();
|
||||
return Ok(authors);
|
||||
BookFilter filter = query != null ? new BookFilter
|
||||
{
|
||||
Query = query
|
||||
} : null;
|
||||
|
||||
var books = _db.GetBooks(100,filter).ToList();
|
||||
return Ok(books);
|
||||
}
|
||||
|
||||
[HttpGet("authors")]
|
||||
public IActionResult GetAuthors()
|
||||
public IActionResult GetAuthors(string query = null)
|
||||
{
|
||||
var authors = _db.GetAuthors(100).ToList();
|
||||
BookFilter filter = query != null ? new BookFilter
|
||||
{
|
||||
Query = query
|
||||
} : null;
|
||||
|
||||
var authors = _db.GetAuthors(100, filter).ToList();
|
||||
return Ok(authors);
|
||||
}
|
||||
|
||||
@@ -48,6 +58,13 @@ namespace Bibblan.Controllers
|
||||
return Ok(authors);
|
||||
}
|
||||
|
||||
[HttpGet("authorcover/{authorid}")]
|
||||
public IActionResult GetAuthorCover(int authorid)
|
||||
{
|
||||
//TODO: fixa vid tillfälle
|
||||
return Ok(new { desc = "picture of banana goes here"});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user