casing i fe. detail embryo

This commit is contained in:
2025-09-17 15:38:29 +02:00
parent 6efa8aba8a
commit 910f500460
14 changed files with 238 additions and 48 deletions

View File

@@ -9,6 +9,7 @@ namespace Bibblan.Business.Services
public class BookFilter
{
public int? Id;
public int? Author;
public string? Query;
}
@@ -17,7 +18,7 @@ namespace Bibblan.Business.Services
{
readonly BibblanOptions settings = options.Value;
public IEnumerable<Books> GetBooks(int count, BookFilter filter = null)
public List<Books> GetBooks(int count, BookFilter filter = null)
{
var conn = new NpgsqlConnection(settings.BibblanConnection);
var query = "select * from books";
@@ -28,7 +29,12 @@ 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))
}
else if(filter.Id != null)
{
query += $"id = {filter.Id}";
}
else if(!String.IsNullOrWhiteSpace(query))
{
filter.Query = filter.Query.ToLowerInvariant();
query += $"lower(title) like @query or lower(author_sort) like @query";
@@ -38,6 +44,47 @@ namespace Bibblan.Business.Services
return conn.Query<Books>(query, parameters).Take(count).ToList();
}
public BookDetailVm GetBookDetails(int id)
{
var query = @"select * from books where id = @book;
select * from authors where id in (select author from books_authors_link where book = @book);
select * from books_languages_link where book = @book;
select * from publishers where id in (select publisher from books_publishers_link where book = @book);
select * from books_ratings_link where book = @book;
select * from series where id in (select series from books_series_link where book = @book);
select * from tags where id in (select tag from books_tags_link where book = @book);
select * from comments where book = @book;
select * from data where book = @book;";
using (var conn = new NpgsqlConnection(settings.BibblanConnection))
{
var results = conn.QueryMultiple(query, new { book = id });
var book = results.ReadFirst<Books>();
var authors = results.Read<Authors>();
var lang = results.Read<BooksLanguagesLink>();
var publishers = results.Read<Publishers>();
var ratings = results.Read<BooksRatingsLink>();
var series = results.Read<Series>();
var tags = results.Read<Tags>();
var comments = results.Read<Comments>();
var data = results.Read<Data>();
return new BookDetailVm
{
Book = book,
Authors = authors,
Language = lang,
Publishers = publishers,
Ratings = ratings,
Series = series,
Tags = tags,
Comments = comments,
Data = data
};
}
}
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 ";

View File

@@ -30,7 +30,7 @@ namespace Bibblan.Controllers
[HttpGet("books")]
public IActionResult GetBooks(string query = null)
{
BookFilter filter = query != null ? new BookFilter
BookFilter? filter = query != null ? new BookFilter
{
Query = query
} : null;
@@ -39,10 +39,17 @@ namespace Bibblan.Controllers
return Ok(books);
}
[HttpGet("books/{id}")]
public IActionResult GetBook(int id)
{
var book = _db.GetBookDetails(id);
return Ok(book);
}
[HttpGet("authors")]
public IActionResult GetAuthors(string query = null)
{
BookFilter filter = query != null ? new BookFilter
BookFilter? filter = query != null ? new BookFilter
{
Query = query
} : null;
@@ -72,7 +79,7 @@ namespace Bibblan.Controllers
[HttpGet("series")]
public IActionResult GetSeries(string query = null)
{
BookFilter filter = query != null ? new BookFilter
BookFilter? filter = query != null ? new BookFilter
{
Query = query
} : null;
@@ -84,7 +91,7 @@ namespace Bibblan.Controllers
[HttpGet("tags")]
public IActionResult GetTags(string query = null)
{
BookFilter filter = query != null ? new BookFilter
BookFilter? filter = query != null ? new BookFilter
{
Query = query
} : null;

View File

@@ -2,6 +2,19 @@
namespace Bibblan.ViewModels
{
public class BookDetailVm
{
public Books Book { get; internal set; }
public IEnumerable<Authors> Authors { get; internal set; }
public IEnumerable<Publishers> Publishers { get; internal set; }
public IEnumerable<BooksLanguagesLink> Language { get; internal set; }
public IEnumerable<BooksRatingsLink> Ratings { get; internal set; }
public IEnumerable<Series> Series { get; internal set; }
public IEnumerable<Tags> Tags { get; internal set; }
public IEnumerable<Comments> Comments { get; internal set; }
public IEnumerable<Data> Data { get; internal set; }
}
public class BookVm
{
public long Id { get; set; }