Skip to content

Commit

Permalink
Fixed more case error in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
umerfaruk committed Dec 14, 2024
1 parent 6b5ea24 commit 668ffac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public async Task<Page<AuthorModel>> GetAuthors(int libraryId, AuthorTypes? auth
{
var sql = @"SELECT a.Id, a.Name, a.Description, a.AuthorType, f.Id As ImageId, f.FilePath AS ImageUrl,
(SELECT Count(*) FROM BookAuthor WHERE AuthorId = a.Id) AS BookCount,
(SELECT Count(*) FROM articleauthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM articleauthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 2) AS PoetryCount
(SELECT Count(*) FROM ArticleAuthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM ArticleAuthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 2) AS PoetryCount
FROM Author AS a
LEFT OUTER JOIN `File` f ON f.Id = a.ImageId
WHERE a.LibraryId = @LibraryId
Expand Down Expand Up @@ -122,8 +122,8 @@ public async Task<AuthorModel> GetAuthorById(int libraryId, int authorId, Cancel
{
var sql = @"SELECT a.Id, a.Name, a.Description, a.AuthorType as AuthorType, f.Id As ImageId, f.FilePath AS ImageUrl,
(SELECT Count(*) FROM BookAuthor WHERE AuthorId = a.Id) AS BookCount,
(SELECT Count(*) FROM articleauthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM articleauthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 2) AS PoetryCount
(SELECT Count(*) FROM ArticleAuthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM ArticleAuthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 2) AS PoetryCount
FROM Author AS a
LEFT OUTER JOIN `File` f ON f.Id = a.ImageId
WHERE a.LibraryId = @LibraryId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public async Task<Page<AuthorModel>> GetAuthors(int libraryId, AuthorTypes? auth
{
var sql = @"SELECT a.Id, a.Name, a.Description, a.AuthorType, f.Id As ImageId, f.FilePath AS ImageUrl,
(SELECT Count(*) FROM BookAuthor WHERE AuthorId = a.Id) AS BookCount,
(SELECT Count(*) FROM articleauthor INNER JOIN article on articleauthor.ArticleId = article.Id WHERE articleauthor.AuthorId = a.Id AND article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM articleauthor INNER JOIN article on articleauthor.ArticleId = article.Id WHERE articleauthor.AuthorId = a.Id AND article.`Type` = 2) AS PoetryCount
(SELECT Count(*) FROM ArticleAuthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM ArticleAuthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 2) AS PoetryCount
FROM Author AS a
LEFT OUTER JOIN [File] f ON f.Id = a.ImageId
Where a.LibraryId = @LibraryId
Expand Down Expand Up @@ -106,8 +106,8 @@ public async Task<AuthorModel> GetAuthorById(int libraryId, int authorId, Cancel
{
var sql = @"SELECT a.Id, a.Name, a.Description, a.AuthorType as AuthorType, f.Id As ImageId, f.FilePath AS ImageUrl,
(SELECT Count(*) FROM BookAuthor WHERE AuthorId = a.Id) AS BookCount,
(SELECT Count(*) FROM articleauthor INNER JOIN article on articleauthor.ArticleId = article.Id WHERE articleauthor.AuthorId = a.Id AND article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM articleauthor INNER JOIN article on articleauthor.ArticleId = article.Id WHERE articleauthor.AuthorId = a.Id AND article.`Type` = 2) AS PoetryCount
(SELECT Count(*) FROM ArticleAuthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM ArticleAuthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 2) AS PoetryCount
FROM Author AS a
LEFT OUTER JOIN [File] f ON f.Id = a.ImageId
Where a.LibraryId = @LibraryId
Expand All @@ -126,8 +126,8 @@ public async Task<Page<AuthorModel>> FindAuthors(int libraryId, string query, Au
{
var sql = @"SELECT a.Id, a.Name, a.Description, a.AuthorType, f.Id As ImageId, f.FilePath AS ImageUrl,
(SELECT Count(*) FROM BookAuthor WHERE AuthorId = a.Id) AS BookCount,
(SELECT Count(*) FROM articleauthor INNER JOIN article on articleauthor.ArticleId = article.Id WHERE articleauthor.AuthorId = a.Id AND article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM articleauthor INNER JOIN article on articleauthor.ArticleId = article.Id WHERE articleauthor.AuthorId = a.Id AND article.`Type` = 2) AS PoetryCount
(SELECT Count(*) FROM ArticleAuthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM ArticleAuthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 2) AS PoetryCount
FROM Author AS a
LEFT OUTER JOIN [File] f ON f.Id = a.ImageId
Where a.LibraryId = @LibraryId
Expand Down Expand Up @@ -161,8 +161,8 @@ public async Task<IEnumerable<AuthorModel>> GetAuthorByIds(int libraryId, IEnume
{
var sql = @"SELECT a.Id, a.Name, a.Description, a.AuthorType, f.Id As ImageId, f.FilePath AS ImageUrl,
(SELECT Count(*) FROM BookAuthor WHERE AuthorId = a.Id) AS BookCount,
(SELECT Count(*) FROM articleauthor INNER JOIN article on articleauthor.ArticleId = article.Id WHERE articleauthor.AuthorId = a.Id AND article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM articleauthor INNER JOIN article on articleauthor.ArticleId = article.Id WHERE articleauthor.AuthorId = a.Id AND article.`Type` = 2) AS PoetryCount
(SELECT Count(*) FROM ArticleAuthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM ArticleAuthor INNER JOIN Article on ArticleAuthor.ArticleId = Article.Id WHERE ArticleAuthor.AuthorId = a.Id AND Article.`Type` = 2) AS PoetryCount
FROM Author AS a
LEFT OUTER JOIN [File] f ON f.Id = a.ImageId
Where a.LibraryId = @LibraryId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public async Task<IEnumerable<CategoryModel>> GetCategories(int libraryId, Cance
var sql = @"Select c.Id, c.Name,
(Select Count(*) From BookCategory b Where b.CategoryId = c.Id) AS BookCount,
(SELECT Count(*) FROM PeriodicalCategory pc WHERE pc.CategoryId = c.Id) AS PeriodicalCount,
(SELECT Count(*) FROM articlecategory INNER JOIN article on articlecategory.ArticleId = article.Id WHERE articlecategory.CategoryId = c.Id AND article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM articlecategory INNER JOIN article on articlecategory.ArticleId = article.Id WHERE articlecategory.CategoryId = c.Id AND article.`Type` = 2) AS PoetryCount
(SELECT Count(*) FROM articlecategory INNER JOIN Article on articlecategory.ArticleId = Article.Id WHERE articlecategory.CategoryId = c.Id AND Article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM articlecategory INNER JOIN Article on articlecategory.ArticleId = Article.Id WHERE articlecategory.CategoryId = c.Id AND Article.`Type` = 2) AS PoetryCount
FROM Category AS c
Where LibraryId = @LibraryId";
var command = new CommandDefinition(sql, new { LibraryId = libraryId }, cancellationToken: cancellationToken);
Expand All @@ -73,8 +73,8 @@ public async Task<CategoryModel> GetCategoryById(int libraryId, int categoryId,
var sql = @"Select c.Id, c.Name,
(Select Count(*) From BookCategory b Where b.CategoryId = c.Id) AS BookCount,
(SELECT Count(*) FROM PeriodicalCategory pc WHERE pc.CategoryId = c.Id) AS PeriodicalCount,
(SELECT Count(*) FROM articlecategory INNER JOIN article on articlecategory.ArticleId = article.Id WHERE articlecategory.CategoryId = c.Id AND article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM articlecategory INNER JOIN article on articlecategory.ArticleId = article.Id WHERE articlecategory.CategoryId = c.Id AND article.`Type` = 2) AS PoetryCount
(SELECT Count(*) FROM articlecategory INNER JOIN Article on articlecategory.ArticleId = Article.Id WHERE articlecategory.CategoryId = c.Id AND Article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM articlecategory INNER JOIN Article on articlecategory.ArticleId = Article.Id WHERE articlecategory.CategoryId = c.Id AND Article.`Type` = 2) AS PoetryCount
FROM Category AS c
Where c.LibraryId = @LibraryId And c.Id = @Id";
var command = new CommandDefinition(sql, new { LibraryId = libraryId, Id = categoryId }, cancellationToken: cancellationToken);
Expand All @@ -90,8 +90,8 @@ public async Task<IEnumerable<CategoryModel>> GetCategoriesByIds(int libraryId,
var sql = @"Select c.Id, c.Name,
(Select Count(*) From BookCategory b Where b.CategoryId = c.Id) AS BookCount,
(SELECT Count(*) FROM PeriodicalCategory pc WHERE pc.CategoryId = c.Id) AS PeriodicalCount,
(SELECT Count(*) FROM articlecategory INNER JOIN article on articlecategory.ArticleId = article.Id WHERE articlecategory.CategoryId = c.Id AND article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM articlecategory INNER JOIN article on articlecategory.ArticleId = article.Id WHERE articlecategory.CategoryId = c.Id AND article.`Type` = 2) AS PoetryCount
(SELECT Count(*) FROM articlecategory INNER JOIN Article on articlecategory.ArticleId = Article.Id WHERE articlecategory.CategoryId = c.Id AND Article.`Type` = 1) AS ArticleCount,
(SELECT Count(*) FROM articlecategory INNER JOIN Article on articlecategory.ArticleId = Article.Id WHERE articlecategory.CategoryId = c.Id AND Article.`Type` = 2) AS PoetryCount
FROM Category AS c
Where c.LibraryId = @LibraryId And c.Id IN @Id";
var command = new CommandDefinition(sql, new { LibraryId = libraryId, Id = categoryIds }, cancellationToken: cancellationToken);
Expand Down

0 comments on commit 668ffac

Please sign in to comment.