From 668ffac397b93bcd00876f1a75ad5d5cb77857dd Mon Sep 17 00:00:00 2001 From: Omar Faruk Date: Sat, 14 Dec 2024 18:34:48 +0000 Subject: [PATCH] Fixed more case error in queries --- .../Repositories/Library/AuthorRepository.cs | 8 ++++---- .../Repositories/Library/AuthorRepository.cs | 16 ++++++++-------- .../Repositories/Library/CategoryRepository.cs | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Adapters/Database/MySql/Repositories/Library/AuthorRepository.cs b/src/Adapters/Database/MySql/Repositories/Library/AuthorRepository.cs index a8568f56..3b4f8dbf 100644 --- a/src/Adapters/Database/MySql/Repositories/Library/AuthorRepository.cs +++ b/src/Adapters/Database/MySql/Repositories/Library/AuthorRepository.cs @@ -79,8 +79,8 @@ public async Task> 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 @@ -122,8 +122,8 @@ public async Task 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 diff --git a/src/Adapters/Database/SqlServer/Repositories/Library/AuthorRepository.cs b/src/Adapters/Database/SqlServer/Repositories/Library/AuthorRepository.cs index 46fde640..dff30437 100644 --- a/src/Adapters/Database/SqlServer/Repositories/Library/AuthorRepository.cs +++ b/src/Adapters/Database/SqlServer/Repositories/Library/AuthorRepository.cs @@ -66,8 +66,8 @@ public async Task> 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 @@ -106,8 +106,8 @@ public async Task 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 @@ -126,8 +126,8 @@ public async Task> 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 @@ -161,8 +161,8 @@ public async Task> 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 diff --git a/src/Adapters/Database/SqlServer/Repositories/Library/CategoryRepository.cs b/src/Adapters/Database/SqlServer/Repositories/Library/CategoryRepository.cs index 67ddfd35..cb6d8fb0 100644 --- a/src/Adapters/Database/SqlServer/Repositories/Library/CategoryRepository.cs +++ b/src/Adapters/Database/SqlServer/Repositories/Library/CategoryRepository.cs @@ -56,8 +56,8 @@ public async Task> 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); @@ -73,8 +73,8 @@ public async Task 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); @@ -90,8 +90,8 @@ public async Task> 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);