serier och taggar
This commit is contained in:
@@ -51,5 +51,59 @@ namespace Bibblan.Business.Services
|
||||
return conn.Query<AuthorVm>(query).Take(count).ToList();
|
||||
|
||||
}
|
||||
|
||||
internal List<SeriesVm> GetSeries(int count, BookFilter? filter)
|
||||
{
|
||||
var query = @"select s.id as seriesid, s.name as seriesname, b.*, a.*
|
||||
--b.id as bookid, b.title, b.pubdate, b.series_index,
|
||||
--a.id as authorid, a.name as authorname
|
||||
from series s
|
||||
inner join books_series_link bsl on s.id = bsl.series
|
||||
inner join books b on bsl.book = b.id
|
||||
inner join books_authors_link bal on b.id = bal.book
|
||||
inner join authors a on bal.author = a.id";
|
||||
if (!String.IsNullOrWhiteSpace(filter?.Query))
|
||||
{
|
||||
filter.Query = filter.Query?.ToLowerInvariant().Trim() ?? "";
|
||||
query += $" where lower(s.name) like '%{filter.Query}%'";
|
||||
}
|
||||
var conn = new NpgsqlConnection(settings.BibblanConnection);
|
||||
var lookup = new Dictionary<long, SeriesVm>();
|
||||
conn.Query<SeriesVm, Books, Authors, SeriesVm>(query, (s,b,a) =>
|
||||
{
|
||||
SeriesVm svm;
|
||||
if (!lookup.TryGetValue(s.Id, out svm))
|
||||
{
|
||||
lookup.Add(s.Id, svm = s);
|
||||
}
|
||||
svm.Books.Add(new ListBook
|
||||
{
|
||||
AuthorId = a.Id,
|
||||
AuthorName = a.Name,
|
||||
Id = b.Id,
|
||||
PubDate = b.Pubdate,
|
||||
SeriesIndex = b.SeriesIndex,
|
||||
Title = b.Title
|
||||
|
||||
});
|
||||
return svm;
|
||||
}, splitOn: "id").Take(count).ToList();
|
||||
return lookup.Values.AsList();
|
||||
}
|
||||
|
||||
internal List<Tag> GetTags(BookFilter? filter)
|
||||
{
|
||||
var query = @"select t.id, t.name, count(btl.*) as bookcount from tags t
|
||||
inner join books_tags_link btl on t.id = btl.tag
|
||||
group by t.id, t.name
|
||||
order by bookcount desc";
|
||||
if (!String.IsNullOrWhiteSpace(filter?.Query))
|
||||
{
|
||||
filter.Query = filter.Query.ToLowerInvariant();
|
||||
query += $" having lower(name) like '%{filter.Query}%'";
|
||||
}
|
||||
var conn = new NpgsqlConnection(settings.BibblanConnection);
|
||||
return conn.Query<Tag>(query).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user