diff --git a/src/v2/CmnSoftwareBackend.API/Controllers/ArticlesController.cs b/src/v2/CmnSoftwareBackend.API/Controllers/ArticlesController.cs index 9943bfa..07161b6 100644 --- a/src/v2/CmnSoftwareBackend.API/Controllers/ArticlesController.cs +++ b/src/v2/CmnSoftwareBackend.API/Controllers/ArticlesController.cs @@ -27,24 +27,39 @@ public ArticlesController(IArticleService articleService) [HttpGet] [ProducesResponseType(200)] - [Route("[action]")] - public async Task GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy, bool includeArticlePicture) + public async Task GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy, bool includeArticlePicture, bool includeCommentWithoutUser, bool includeCommentWithUser) { - var result = await _articleService.GetAllAsync(isActive, isDeleted, isAscending, currentPage, pageSize, orderBy, includeArticlePicture); + var result = await _articleService.GetAllAsync(isActive, isDeleted, isAscending, currentPage, pageSize, orderBy, includeArticlePicture, includeCommentWithoutUser, includeCommentWithUser); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "Articles", Action = "GetAll" }))); } [HttpGet] [ProducesResponseType(200)] [Route("[action]")] - public async Task GetById(int articleId, bool includeArticlePicture) + public async Task GetById(int articleId, bool includeArticlePicture, bool commentWithUser ,bool commentWithoutUser) { - var result = await _articleService.GetByIdAsync(articleId, includeArticlePicture); + var result = await _articleService.GetByIdAsync(articleId, includeArticlePicture, commentWithUser, commentWithoutUser); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "Articles", Action = "GetById" }))); } [HttpGet] [ProducesResponseType(200)] [Route("[action]")] + public async Task GetArticleByCommentWithoutUserId(int commentWithoutUserId) + { + var result = await _articleService.GetArticleByCommentWithoutUserIdAsync(commentWithoutUserId); + return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "Articles", Action = "GetArticleByCommentWithoutUserId" }))); + } + [HttpGet] + [ProducesResponseType(200)] + [Route("[action]")] + public async Task GetArticleByCommentWithUserId(int commentWithUserId) + { + var result = await _articleService.GetArticleByCommentWithUserIdAsync(commentWithUserId); + return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "Articles", Action = "GetArticleByCommentWithUserId" }))); + } + [HttpGet] + [ProducesResponseType(200)] + [Route("[action]")] public async Task GetArticleByUserId(Guid userId) { var article = await _articleService.GetArticleByUserId(userId); @@ -55,8 +70,8 @@ public async Task GetArticleByUserId(Guid userId) [Route("[action]")] public async Task GetArticleByArticlePictureId(int ArticlePictureId) { - var articles =await _articleService.GetArticleByArticlePictureId(ArticlePictureId); - return Ok(new SuccessDataApiResult(articles,Url.Link("",new {Controller="Articles",Action="GetArticleByArticlePictureId" }))); + var articles = await _articleService.GetArticleByArticlePictureId(ArticlePictureId); + return Ok(new SuccessDataApiResult(articles, Url.Link("", new { Controller = "Articles", Action = "GetArticleByArticlePictureId" }))); } [HttpPost] @@ -72,9 +87,9 @@ public async Task AddAsync(ArticleAddDto articleAddDto) [ProducesResponseType(400)] [ProducesResponseType(500)] [Route("[action]")] - public async Task DeleteAsync(ArticleAddDto articleAddDto) + public async Task DeleteAsync(int articleId, Guid CreatedUserId) { - var result = await _articleService.AddAsync(articleAddDto); + var result = await _articleService.DeleteAsync(articleId, CreatedUserId); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "Articles", Action = "Delete" }))); } [HttpPost] @@ -82,9 +97,9 @@ public async Task DeleteAsync(ArticleAddDto articleAddDto) [ProducesResponseType(400)] [ProducesResponseType(500)] [Route("[action]")] - public async Task UpdateAsync(ArticleAddDto articleAddDto) + public async Task UpdateAsync(ArticleUpdateDto articleUpdateDto) { - var result = await _articleService.AddAsync(articleAddDto); + var result = await _articleService.UpdateAsync(articleUpdateDto); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "Articles", Action = "Update" }))); } [HttpPost] @@ -92,10 +107,10 @@ public async Task UpdateAsync(ArticleAddDto articleAddDto) [ProducesResponseType(400)] [ProducesResponseType(500)] [Route("[action]")] - public async Task HardDeleteAsync(ArticleAddDto articleAddDto) + public async Task HardDeleteAsync(int articleId) { - var result = await _articleService.AddAsync(articleAddDto); - return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "Articles", Action = "HardDelete" }))); + var result = await _articleService.HardDeleteAsync(articleId); + return Ok(new SuccessApiResult(result, Url.Link("", new { Controller = "Articles", Action = "HardDelete" }))); } } diff --git a/src/v2/CmnSoftwareBackend.API/Controllers/CommentWithUsersController.cs b/src/v2/CmnSoftwareBackend.API/Controllers/CommentWithUsersController.cs index 7bffee2..1dc7b06 100644 --- a/src/v2/CmnSoftwareBackend.API/Controllers/CommentWithUsersController.cs +++ b/src/v2/CmnSoftwareBackend.API/Controllers/CommentWithUsersController.cs @@ -24,43 +24,49 @@ public CommentWithUsersController(ICommentWithUserService commentWithUserService { _commentWithUserService = commentWithUserService; } + [HttpGet] [Route("[action]")] public async Task GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy, bool includeArticle, bool includeUser) { var result = await _commentWithUserService.GetAllAsync(isActive, isDeleted, isAscending, currentPage, pageSize, orderBy, includeArticle, includeUser); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "CommentWithUser", Action = "GetAll" }))); } + [HttpGet] [Route("[action]")] - public async Task GetByIdAsync(int commentWithUserId, bool includeArticle) + public async Task GetByIdAsync(int commentWithUserId, bool includeArticle,bool includeUser) { - var result = await _commentWithUserService.GetByIdAsync(commentWithUserId, includeArticle); + var result = await _commentWithUserService.GetByIdAsync(commentWithUserId, includeArticle,includeUser); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "CommentWithUser", Action = "GetById" }))); } + [HttpPost] [Route("[action]")] public async Task AddAsync(CommentWithUserAddDto commentWithUserAddDto) { var result = await _commentWithUserService.AddAsync(commentWithUserAddDto); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "CommentWithUser", Action = "Add" }))); } + [HttpPost] [Route("[action]")] public async Task UpdateAsync(CommentWithUserUpdateDto commentWithUserUpdateDto) { var result = await _commentWithUserService.UpdateAsync(commentWithUserUpdateDto); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "CommentWithUser", Action = "Update" }))); } + [HttpGet] [Route("[action]")] public async Task GetCommentByUserId(Guid userId, bool includeArticle) { var result =await _commentWithUserService.GetAllCommentByUserId(userId, includeArticle); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "CommentWithUser", Action = "GetCommentByUserId" }))); } + [HttpPost] [Route("[action]")] public async Task DeleteAsync(int commentWithUserId, Guid CreatedByUserId) { var result = await _commentWithUserService.DeleteAsync(commentWithUserId, CreatedByUserId); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "CommentWithUser", Action = "GetCommentByUserId" }))); } - + [HttpPost] [Route("[action]")] public async Task HardDeleteAsync(int commentId) { diff --git a/src/v2/CmnSoftwareBackend.API/Controllers/CommentWithoutUsersController.cs b/src/v2/CmnSoftwareBackend.API/Controllers/CommentWithoutUsersController.cs index 1f9b1bf..ccf5e3c 100644 --- a/src/v2/CmnSoftwareBackend.API/Controllers/CommentWithoutUsersController.cs +++ b/src/v2/CmnSoftwareBackend.API/Controllers/CommentWithoutUsersController.cs @@ -25,37 +25,42 @@ public CommentWithoutUsersController(ICommentWithoutUserService commentWithoutUs { _commentWithoutUserService = commentWithoutUserService; } - + [HttpGet] [Route("[action]")] public async Task GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy, bool includeArticle) { var result = await _commentWithoutUserService.GetAllAsync(isActive, isDeleted, isAscending, currentPage, pageSize, orderBy, includeArticle); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "CommentWithoutUser", Action = "GetAll" }))); } + [HttpGet] [Route("[action]")] public async Task GetByIdAsync(int commentWithoutUserId, bool includeArticle) { var result = await _commentWithoutUserService.GetByIdAsync(commentWithoutUserId, includeArticle); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "CommentWithoutUser", Action = "GetById" }))); } + [HttpPost] [Route("[action]")] public async Task AddAsync(CommentWithoutUserAddDto commentWithoutUserAddDto) { var result = await _commentWithoutUserService.AddAsync(commentWithoutUserAddDto); return Ok(new SuccessDataApiResult(result, Url.Link("", new { Controller = "CommentWithoutUser", Action = "Add" }))); } + [HttpPost] [Route("[action]")] public async Task DeleteAsync(int commentWithoutUserId) { var result = await _commentWithoutUserService.DeleteAsync(commentWithoutUserId); return Ok(new SuccessDataApiResult(result,Url.Link("",new {Controller="CommentWithotUser",Action="Delete" }))); } + [HttpPost] [Route("[action]")] public async Task HardDeleteAsync(int commentWithoutUserId) { var result = await _commentWithoutUserService.HardDeleteAsync(commentWithoutUserId); return Ok(new SuccessApiResult(result, Url.Link("", new { Controller = "CommentWithoutUser", Action = "HardDelete" }))); } + [HttpPost] [Route("[action]")] public async Task UpdateAsync(CommentWithoutUserUpdateDto commentWithoutUserUpdateDto) { diff --git "a/src/v2/CmnSoftwareBackend.API/c:\\temp\\cmn-internal-nlog.txt" "b/src/v2/CmnSoftwareBackend.API/c:\\temp\\cmn-internal-nlog.txt" index f73e74e..3c5bd92 100644 --- "a/src/v2/CmnSoftwareBackend.API/c:\\temp\\cmn-internal-nlog.txt" +++ "b/src/v2/CmnSoftwareBackend.API/c:\\temp\\cmn-internal-nlog.txt" @@ -6361,3 +6361,67 @@ ClientConnectionId:00000000-0000-0000-0000-000000000000 at NLog.Targets.DatabaseTarget.EnsureConnectionOpen(String connectionString, LogEventInfo logEventInfo) at NLog.Targets.DatabaseTarget.WriteLogEventToDatabase(LogEventInfo logEvent, String connectionString) ClientConnectionId:00000000-0000-0000-0000-000000000000 +2021-09-29 16:51:55.7066 Info Message Template Auto Format enabled +2021-09-29 16:51:55.7255 Info Loading assembly: NLog.Web.AspNetCore +2021-09-29 16:51:55.7613 Info Adding target FileTarget(Name=allfile) +2021-09-29 16:51:55.7625 Info Adding target FileTarget(Name=ownFile-web) +2021-09-29 16:51:55.7713 Info Adding target DatabaseTarget(Name=database) +2021-09-29 16:51:55.8414 Info Validating config: TargetNames=allfile, ownFile-web, database, ConfigItems=75, FilePath=/Users/yunus/Documents/GitHub/BlogApi-ASP.NET-Core/src/v2/CmnSoftwareBackend.API/bin/Debug/net5.0/NLog.config +2021-09-29 16:51:55.9466 Info Configuration initialized. +2021-09-29 16:51:55.9474 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.11.13229. Product version: 4.7.11+33ed3a9f86277651e93ddf39cda64a046a06778b. GlobalAssemblyCache: False +2021-09-29 16:54:07.4566 Info Message Template Auto Format enabled +2021-09-29 16:54:07.4780 Info Loading assembly: NLog.Web.AspNetCore +2021-09-29 16:54:07.5156 Info Adding target FileTarget(Name=allfile) +2021-09-29 16:54:07.5170 Info Adding target FileTarget(Name=ownFile-web) +2021-09-29 16:54:07.5267 Info Adding target DatabaseTarget(Name=database) +2021-09-29 16:54:07.6109 Info Validating config: TargetNames=allfile, ownFile-web, database, ConfigItems=75, FilePath=/Users/yunus/Documents/GitHub/BlogApi-ASP.NET-Core/src/v2/CmnSoftwareBackend.API/bin/Debug/net5.0/NLog.config +2021-09-29 16:54:07.6994 Info Configuration initialized. +2021-09-29 16:54:07.7019 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.11.13229. Product version: 4.7.11+33ed3a9f86277651e93ddf39cda64a046a06778b. GlobalAssemblyCache: False +2021-09-29 17:00:13.9639 Info Message Template Auto Format enabled +2021-09-29 17:00:13.9923 Info Loading assembly: NLog.Web.AspNetCore +2021-09-29 17:00:14.0430 Info Adding target FileTarget(Name=allfile) +2021-09-29 17:00:14.0445 Info Adding target FileTarget(Name=ownFile-web) +2021-09-29 17:00:14.0548 Info Adding target DatabaseTarget(Name=database) +2021-09-29 17:00:14.1550 Info Validating config: TargetNames=allfile, ownFile-web, database, ConfigItems=75, FilePath=/Users/yunus/Documents/GitHub/BlogApi-ASP.NET-Core/src/v2/CmnSoftwareBackend.API/bin/Debug/net5.0/NLog.config +2021-09-29 17:00:14.3285 Info Configuration initialized. +2021-09-29 17:00:14.3303 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.11.13229. Product version: 4.7.11+33ed3a9f86277651e93ddf39cda64a046a06778b. GlobalAssemblyCache: False +2021-09-29 17:13:21.5045 Info Message Template Auto Format enabled +2021-09-29 17:13:21.5210 Info Loading assembly: NLog.Web.AspNetCore +2021-09-29 17:13:21.5593 Info Adding target FileTarget(Name=allfile) +2021-09-29 17:13:21.5608 Info Adding target FileTarget(Name=ownFile-web) +2021-09-29 17:13:21.5712 Info Adding target DatabaseTarget(Name=database) +2021-09-29 17:13:21.6511 Info Validating config: TargetNames=allfile, ownFile-web, database, ConfigItems=75, FilePath=/Users/yunus/Documents/GitHub/BlogApi-ASP.NET-Core/src/v2/CmnSoftwareBackend.API/bin/Debug/net5.0/NLog.config +2021-09-29 17:13:21.7657 Info Configuration initialized. +2021-09-29 17:13:21.7657 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.11.13229. Product version: 4.7.11+33ed3a9f86277651e93ddf39cda64a046a06778b. GlobalAssemblyCache: False +2021-09-29 17:46:50.9922 Info Message Template Auto Format enabled +2021-09-29 17:46:51.0125 Info Loading assembly: NLog.Web.AspNetCore +2021-09-29 17:46:51.0497 Info Adding target FileTarget(Name=allfile) +2021-09-29 17:46:51.0508 Info Adding target FileTarget(Name=ownFile-web) +2021-09-29 17:46:51.0602 Info Adding target DatabaseTarget(Name=database) +2021-09-29 17:46:51.1538 Info Validating config: TargetNames=allfile, ownFile-web, database, ConfigItems=75, FilePath=/Users/yunus/Documents/GitHub/BlogApi-ASP.NET-Core/src/v2/CmnSoftwareBackend.API/bin/Debug/net5.0/NLog.config +2021-09-29 17:46:51.2403 Info Configuration initialized. +2021-09-29 17:46:51.2411 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.11.13229. Product version: 4.7.11+33ed3a9f86277651e93ddf39cda64a046a06778b. GlobalAssemblyCache: False +2021-09-29 17:49:31.3686 Info Message Template Auto Format enabled +2021-09-29 17:49:31.3895 Info Loading assembly: NLog.Web.AspNetCore +2021-09-29 17:49:31.4269 Info Adding target FileTarget(Name=allfile) +2021-09-29 17:49:31.4285 Info Adding target FileTarget(Name=ownFile-web) +2021-09-29 17:49:31.4381 Info Adding target DatabaseTarget(Name=database) +2021-09-29 17:49:31.5269 Info Validating config: TargetNames=allfile, ownFile-web, database, ConfigItems=75, FilePath=/Users/yunus/Documents/GitHub/BlogApi-ASP.NET-Core/src/v2/CmnSoftwareBackend.API/bin/Debug/net5.0/NLog.config +2021-09-29 17:49:31.6204 Info Configuration initialized. +2021-09-29 17:49:31.6212 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.11.13229. Product version: 4.7.11+33ed3a9f86277651e93ddf39cda64a046a06778b. GlobalAssemblyCache: False +2021-09-29 17:57:09.1053 Info Message Template Auto Format enabled +2021-09-29 17:57:09.1243 Info Loading assembly: NLog.Web.AspNetCore +2021-09-29 17:57:09.1601 Info Adding target FileTarget(Name=allfile) +2021-09-29 17:57:09.1613 Info Adding target FileTarget(Name=ownFile-web) +2021-09-29 17:57:09.1703 Info Adding target DatabaseTarget(Name=database) +2021-09-29 17:57:09.2386 Info Validating config: TargetNames=allfile, ownFile-web, database, ConfigItems=75, FilePath=/Users/yunus/Documents/GitHub/BlogApi-ASP.NET-Core/src/v2/CmnSoftwareBackend.API/bin/Debug/net5.0/NLog.config +2021-09-29 17:57:09.3245 Info Configuration initialized. +2021-09-29 17:57:09.3254 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.11.13229. Product version: 4.7.11+33ed3a9f86277651e93ddf39cda64a046a06778b. GlobalAssemblyCache: False +2021-09-29 18:28:32.8768 Info Message Template Auto Format enabled +2021-09-29 18:28:32.8979 Info Loading assembly: NLog.Web.AspNetCore +2021-09-29 18:28:32.9334 Info Adding target FileTarget(Name=allfile) +2021-09-29 18:28:32.9346 Info Adding target FileTarget(Name=ownFile-web) +2021-09-29 18:28:32.9440 Info Adding target DatabaseTarget(Name=database) +2021-09-29 18:28:33.0378 Info Validating config: TargetNames=allfile, ownFile-web, database, ConfigItems=75, FilePath=/Users/yunus/Documents/GitHub/BlogApi-ASP.NET-Core/src/v2/CmnSoftwareBackend.API/bin/Debug/net5.0/NLog.config +2021-09-29 18:28:33.1284 Info Configuration initialized. +2021-09-29 18:28:33.1291 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.11.13229. Product version: 4.7.11+33ed3a9f86277651e93ddf39cda64a046a06778b. GlobalAssemblyCache: False diff --git a/src/v2/CmnSoftwareBackend.Services/Abstract/IArticlePictureService.cs b/src/v2/CmnSoftwareBackend.Services/Abstract/IArticlePictureService.cs index d8c98a7..7604807 100644 --- a/src/v2/CmnSoftwareBackend.Services/Abstract/IArticlePictureService.cs +++ b/src/v2/CmnSoftwareBackend.Services/Abstract/IArticlePictureService.cs @@ -8,10 +8,10 @@ namespace CmnSoftwareBackend.Services.Abstract { public interface IArticlePictureService { - Task GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy,bool includeArticle); - Task GetAllWithoutPagingAsync(bool? isActive, bool? isDeleted, OrderBy orderBy, bool isAscending,bool includeArticle); - Task GetArticlePictureByArticleId(int articleId); - Task GetByIdAsync(int articlePictureId,bool includeArticle); + Task GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy, bool includeArticle); + Task GetAllWithoutPagingAsync(bool? isActive, bool? isDeleted, OrderBy orderBy, bool isAscending, bool includeArticle); + Task GetArticlePictureByArticleId(int articleId); + Task GetByIdAsync(int articlePictureId, bool includeArticle); Task AddAsync(ArticlePictureAddDto articlePictureAddDto); Task UpdateAsync(ArticlePictureUpdateDto articlePictureUpdateDto); Task DeleteAsync(int articlePictureId, Guid CreatedByUserId); diff --git a/src/v2/CmnSoftwareBackend.Services/Abstract/IArticleService.cs b/src/v2/CmnSoftwareBackend.Services/Abstract/IArticleService.cs index 92322b0..beba9d4 100644 --- a/src/v2/CmnSoftwareBackend.Services/Abstract/IArticleService.cs +++ b/src/v2/CmnSoftwareBackend.Services/Abstract/IArticleService.cs @@ -8,8 +8,11 @@ namespace CmnSoftwareBackend.Services.Abstract { public interface IArticleService { - Task GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy,bool includePicture); - Task GetByIdAsync(int articleId,bool includeArticlePicture); + Task GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, + int currentPage, int pageSize, OrderBy orderBy,bool includePicture, bool includeCommentWithoutUser, bool includeCommentWithUser); + Task GetByIdAsync(int articleId,bool includeArticlePicture,bool includeCommentWithUserId,bool includeCommentWithoutUserId); + Task GetArticleByCommentWithUserIdAsync(int commentWithUserId); + Task GetArticleByCommentWithoutUserIdAsync(int commentWithoutUserId); Task GetArticleByUserId(Guid userId); Task GetArticleByArticlePictureId(int articlePictureId); Task AddAsync(ArticleAddDto articleAddDto); diff --git a/src/v2/CmnSoftwareBackend.Services/Abstract/ICommentWithUserService.cs b/src/v2/CmnSoftwareBackend.Services/Abstract/ICommentWithUserService.cs index b804dd7..88e9aab 100644 --- a/src/v2/CmnSoftwareBackend.Services/Abstract/ICommentWithUserService.cs +++ b/src/v2/CmnSoftwareBackend.Services/Abstract/ICommentWithUserService.cs @@ -9,7 +9,7 @@ namespace CmnSoftwareBackend.Services.Abstract public interface ICommentWithUserService { Task GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy, bool includeArticle, bool includeUser); - Task GetByIdAsync(int commentWithUserId, bool includeArticle); + Task GetByIdAsync(int commentWithUserId, bool includeArticle,bool includeUser); Task GetAllCommentByUserId(Guid userId, bool includeArticle); Task AddAsync(CommentWithUserAddDto commentWithUserAddDto); Task UpdateAsync(CommentWithUserUpdateDto commentWithUserUpdateDto); diff --git a/src/v2/CmnSoftwareBackend.Services/AutoMapper/Profiles/CommentWithUserProfile.cs b/src/v2/CmnSoftwareBackend.Services/AutoMapper/Profiles/CommentWithUserProfile.cs index d7ade23..1f2ca34 100644 --- a/src/v2/CmnSoftwareBackend.Services/AutoMapper/Profiles/CommentWithUserProfile.cs +++ b/src/v2/CmnSoftwareBackend.Services/AutoMapper/Profiles/CommentWithUserProfile.cs @@ -15,6 +15,7 @@ public CommentWithUserProfile() // CreateMap(); // CreateMap().ForMember(dest=>dest.CreatedDate,x=>x.MapFrom(x=>DateTime.Now)).ForMember(dest=>dest.ModifiedDate,x=>x.MapFrom(x=>DateTime.Now)).ForMember(dest=>dest.IsActive,x=>x.MapFrom(x=>true)).ForMember(dest=>dest.IsDeleted,x=>x.MapFrom(x=>false)); + CreateMap().ForMember(dest=>dest.CreatedDate,x=>x.MapFrom(x=>DateTime.Now)).ForMember(dest=>dest.ModifiedDate,x=>x.MapFrom(x=>DateTime.Now)).ForMember(dest=>dest.IsActive,x=>x.MapFrom(x=>true)).ForMember(dest=>dest.IsDeleted,x=>x.MapFrom(x=>false)); CreateMap().ForMember(dest=>dest.ModifiedDate,x=>x.MapFrom(x=>DateTime.Now)); } diff --git a/src/v2/CmnSoftwareBackend.Services/AutoMapper/Profiles/CommentWithoutUserProfile.cs b/src/v2/CmnSoftwareBackend.Services/AutoMapper/Profiles/CommentWithoutUserProfile.cs index adf9bbe..ee61b13 100644 --- a/src/v2/CmnSoftwareBackend.Services/AutoMapper/Profiles/CommentWithoutUserProfile.cs +++ b/src/v2/CmnSoftwareBackend.Services/AutoMapper/Profiles/CommentWithoutUserProfile.cs @@ -10,6 +10,7 @@ public class CommentWithoutUserProfile:Profile public CommentWithoutUserProfile() { CreateMap().ForMember(dest => dest.CreatedDate, x => x.MapFrom(x => DateTime.Now)).ForMember(dest => dest.ModifiedDate, x => x.MapFrom(x => DateTime.Now)).ForMember(dest => dest.IsActive, x => x.MapFrom(x => true)).ForMember(dest => dest.IsDeleted, x => x.MapFrom(x => false)); + CreateMap().ForMember(dest => dest.CreatedDate, x => x.MapFrom(x => DateTime.Now)).ForMember(dest => dest.ModifiedDate, x => x.MapFrom(x => DateTime.Now)).ForMember(dest => dest.IsActive, x => x.MapFrom(x => true)).ForMember(dest => dest.IsDeleted, x => x.MapFrom(x => false)); CreateMap().ForMember(dest => dest.ModifiedDate, x => x.MapFrom(x => DateTime.Now)); } diff --git a/src/v2/CmnSoftwareBackend.Services/Concrete/ArticleManager.cs b/src/v2/CmnSoftwareBackend.Services/Concrete/ArticleManager.cs index 2c1be34..34dbf05 100644 --- a/src/v2/CmnSoftwareBackend.Services/Concrete/ArticleManager.cs +++ b/src/v2/CmnSoftwareBackend.Services/Concrete/ArticleManager.cs @@ -25,7 +25,7 @@ public ArticleManager(CmnDbContext dbContext, IMapper mapper) : base(dbContext, public async Task AddAsync(ArticleAddDto articleAddDto) { - var user = DbContext.Users.AsNoTracking().SingleOrDefaultAsync(u => u.Id == articleAddDto.UserId); + var user = await DbContext.Users.AsNoTracking().SingleOrDefaultAsync(u => u.Id == articleAddDto.UserId); if (user == null) throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir kullanıcı bulunamadı", "UserId")); if (await DbContext.Articles.AsNoTracking().AnyAsync(a => a.Title == articleAddDto.Title)) @@ -54,12 +54,14 @@ public async Task DeleteAsync(int articleId, Guid CreatedByUserId) return new DataResult(ResultStatus.Success, $"{article.Title} başlıklı makale başarıyla silinmiştir", article); } - public async Task GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy, bool includeArticlePicture) + public async Task GetAllAsync(bool? isActive, bool? isDeleted, bool isAscending, int currentPage, int pageSize, OrderBy orderBy, bool includeArticlePicture, bool includeCommentWithoutUser, bool includeCommentWithUser) { IQueryable
query = DbContext.Set
(); if (isActive.HasValue) query = query.AsNoTracking().Where(a => a.IsActive == isActive); if (isDeleted.HasValue) query = query.AsNoTracking().Where(a => a.IsDeleted == isDeleted); if (includeArticlePicture) query = query.AsNoTracking().Include(a => a.ArticlePictures); + if (includeCommentWithoutUser) query = query.AsNoTracking().Include(a => a.CommentWithoutUsers); + if (includeCommentWithUser) query = query.AsNoTracking().Include(a => a.CommentWithUsers); pageSize = pageSize > 100 ? 100 : pageSize; var articleCount = await query.AsNoTracking().CountAsync(); switch (orderBy) @@ -93,6 +95,25 @@ public async Task GetArticleByArticlePictureId(int articlePictureId return new DataResult(ResultStatus.Success, query); } + public async Task GetArticleByCommentWithoutUserIdAsync(int commentWithoutUserId) + { + IQueryable
query = DbContext.Set
(); + query = query.AsNoTracking().Where(a => a.CommentWithoutUsers.Any(ab => ab.Id == commentWithoutUserId)); + if (!await DbContext.CommentWithoutUsers.AnyAsync(a => a.Id == commentWithoutUserId)) + throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir mesaj bulunamadı", "commentWithoutUserId")); + + return new DataResult(ResultStatus.Success, query); + } + + public async Task GetArticleByCommentWithUserIdAsync(int commentWithUserId) + { + IQueryable
query = DbContext.Set
(); + var comment = query.AsNoTracking().Where(a => a.CommentWithUsers.Any(a=>a.Id == commentWithUserId)); + if (comment is null) + throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Bu kullanıcı Id'sine ait bir yorum bulunamadı","commentWithUserId")); + return new DataResult(ResultStatus.Success, query); + } + public async Task GetArticleByUserId(Guid userId) { IQueryable
query = DbContext.Set
(); @@ -103,15 +124,17 @@ public async Task GetArticleByUserId(Guid userId) return new DataResult(ResultStatus.Success, query); } - public async Task GetByIdAsync(int articleId, bool includeArticlePicture) + public async Task GetByIdAsync(int articleId, bool includeArticlePicture, bool includeCommentWithUserId, bool includeCommentWithoutUserId) { IQueryable
query = DbContext.Set
(); var article = await query.AsNoTracking().SingleOrDefaultAsync(a => a.Id == articleId); if (article == null) throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir makale bulunamadı", "Id")); if (includeArticlePicture) query = query.AsNoTracking().Include(a => a.ArticlePictures); - - return new DataResult(ResultStatus.Success, article); + if (includeCommentWithoutUserId) query = query.AsNoTracking().Include(a => a.CommentWithoutUsers); + if (includeCommentWithUserId) query = query.AsNoTracking().Include(a => a.CommentWithUsers); + + return new DataResult(ResultStatus.Success, query); } public async Task HardDeleteAsync(int articleId) diff --git a/src/v2/CmnSoftwareBackend.Services/Concrete/CategoryManager.cs b/src/v2/CmnSoftwareBackend.Services/Concrete/CategoryManager.cs index bbc93aa..ad39613 100644 --- a/src/v2/CmnSoftwareBackend.Services/Concrete/CategoryManager.cs +++ b/src/v2/CmnSoftwareBackend.Services/Concrete/CategoryManager.cs @@ -81,7 +81,7 @@ public async Task AddAsync(CategoryAddDto categoryAddDto) await DbContext.AddAsync(category); await DbContext.SaveChangesAsync(); return new DataResult(ResultStatus.Success, $"{category.Name} adlı kategori başarıyla eklendi", - categoryAddDto); + category); } public async Task UpdateAsync(CategoryUpdateDto categoryUpdateDto) diff --git a/src/v2/CmnSoftwareBackend.Services/Concrete/CommentWithUserManager.cs b/src/v2/CmnSoftwareBackend.Services/Concrete/CommentWithUserManager.cs index d6d7c77..895f72f 100644 --- a/src/v2/CmnSoftwareBackend.Services/Concrete/CommentWithUserManager.cs +++ b/src/v2/CmnSoftwareBackend.Services/Concrete/CommentWithUserManager.cs @@ -89,14 +89,15 @@ public async Task GetAllAsync(bool? isActive, bool? isDeleted, bool }); } - public async Task GetByIdAsync(int commentWithUserId, bool includeArticle) + public async Task GetByIdAsync(int commentWithUserId, bool includeArticle,bool includeUser) { IQueryable query = DbContext.Set(); var comment =await query.AsNoTracking().SingleOrDefaultAsync(a => a.Id == commentWithUserId); if (comment == null) throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir yorum bulunamadı", "Id")); if (includeArticle) query = query.AsNoTracking().Include(a => a.Article); - return new DataResult(ResultStatus.Success,comment); + if (includeUser) query = query.AsNoTracking().Include(a => a.User); + return new DataResult(ResultStatus.Success,query); } //test public async Task GetAllCommentByUserId(Guid userId, bool includeArticle) @@ -107,8 +108,8 @@ public async Task GetAllCommentByUserId(Guid userId, bool includeAr throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("böyle bir kullanıcı bulunamadı", "userId")); if (includeArticle) query = query.AsNoTracking().Include(a => a.Article); - var comment = query.AsNoTracking().Where(a => a.UserId == userId); - return new DataResult(ResultStatus.Success, comment); + var comment = query.AsNoTracking().Include(a=>a.User).Where(a => a.UserId == userId); + return new DataResult(ResultStatus.Success, query); } public async Task HardDeleteAsync(int commentWithUserId) diff --git a/src/v2/CmnSoftwareBackend.Services/Concrete/CommentWithoutUserManager.cs b/src/v2/CmnSoftwareBackend.Services/Concrete/CommentWithoutUserManager.cs index 3f9029d..9aa5978 100644 --- a/src/v2/CmnSoftwareBackend.Services/Concrete/CommentWithoutUserManager.cs +++ b/src/v2/CmnSoftwareBackend.Services/Concrete/CommentWithoutUserManager.cs @@ -37,9 +37,11 @@ public async Task AddAsync(CommentWithoutUserAddDto commentWithoutU public async Task DeleteAsync(int commentWithoutUserId) { - var comment = await DbContext.CommentWithoutUsers.Include(a => a.Article).AsNoTracking().SingleOrDefaultAsync(cwu => cwu.Id == commentWithoutUserId); - if (comment == null && comment.Article == null) - throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir comment bulunamadı", "Id")); + var comment = await DbContext.CommentWithoutUsers.Include(a => a.Article).SingleOrDefaultAsync(cwu => cwu.Id == commentWithoutUserId); + if (comment == null) + throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir yorum bulunamadı", "Id")); + if (comment.Article == null) + throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Bu yoruma ait bir makale bulunamadı", "Id")); comment.IsActive = false; comment.IsDeleted = true; @@ -53,14 +55,14 @@ public async Task GetAllAsync(bool? isActive, bool? isDeleted, bool IQueryable query = DbContext.Set(); if (isActive.HasValue) query = query.Where(a => a.IsActive == isActive); if (isDeleted.HasValue) query = query.Where(a => a.IsDeleted == isDeleted); - if (includeArticle) query = query.AsNoTracking().Include(a=>a.Article); + if (includeArticle) query = query.AsNoTracking().Include(a => a.Article); - var commentCount =await query.AsNoTracking().CountAsync(); + var commentCount = await query.AsNoTracking().CountAsync(); pageSize = pageSize > 100 ? 100 : pageSize; switch (orderBy) { case OrderBy.Id: - query = isAscending ? query.OrderBy(a => a.Id) : query.OrderByDescending(a => a.Id); + query = isAscending ? query.OrderBy(a => a.Id) : query.OrderByDescending(a => a.Id); break; case OrderBy.Az: query = isAscending ? query.OrderBy(a => a.UserName) : query.OrderByDescending(a => a.UserName); @@ -69,14 +71,14 @@ public async Task GetAllAsync(bool? isActive, bool? isDeleted, bool query = isAscending ? query.OrderBy(a => a.CreatedDate) : query.OrderByDescending(a => a.CreatedDate); break; } - return new DataResult(ResultStatus.Success,new CommentWithoutUserListDto + return new DataResult(ResultStatus.Success, new CommentWithoutUserListDto { // ArticlePictures = await query.Skip((currentPage - 1) * pageSize).Take(pageSize).Select(ap => Mapper.Map(ap)).ToListAsync(), - CommentWithoutUsers =await query.Skip((currentPage-1)*pageSize).Take(pageSize).Select(a=>Mapper.Map(a)).ToListAsync(), - CurrentPage=currentPage, - TotalCount=commentCount, - PageSize=pageSize, - IsAscending=isAscending + CommentWithoutUsers = await query.Skip((currentPage - 1) * pageSize).Take(pageSize).Select(a => Mapper.Map(a)).ToListAsync(), + CurrentPage = currentPage, + TotalCount = commentCount, + PageSize = pageSize, + IsAscending = isAscending }); } @@ -88,7 +90,7 @@ public async Task GetByIdAsync(int commentWithoutUserId, bool inclu throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir yorum bulunamadı", "Id")); if (includeArticle) query = query.AsNoTracking().Include(a => a.Article); - return new DataResult(ResultStatus.Success, comment); + return new DataResult(ResultStatus.Success, query); } public async Task HardDeleteAsync(int commentWithoutUserId) @@ -104,14 +106,19 @@ public async Task HardDeleteAsync(int commentWithoutUserId) public async Task UpdateAsync(CommentWithoutUserUpdateDto commentWithoutUserUpdateDto) { - var article = await DbContext.Articles.SingleOrDefaultAsync(cwu => cwu.Id == commentWithoutUserUpdateDto.ArticleId); + var article = await DbContext.Articles.AsNoTracking().SingleOrDefaultAsync(cwu => cwu.Id == commentWithoutUserUpdateDto.ArticleId); + var oldComment= await DbContext.CommentWithoutUsers.SingleOrDefaultAsync(a => a.Id == commentWithoutUserUpdateDto.Id); if (article == null) throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Böyle bir makale bulunamadı", "ArticleId")); + if (article.Id != commentWithoutUserUpdateDto.ArticleId) + throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Bu yorum bu makaleye ait değil", "ArticleId")); + if (commentWithoutUserUpdateDto.UserName != oldComment.UserName) + throw new NotFoundArgumentException(Messages.General.ValidationError(), new Error("Bu yorum bu kullanıcıya ait değil", "UserName")); - var newComment = Mapper.Map(commentWithoutUserUpdateDto); + var newComment = Mapper.Map(commentWithoutUserUpdateDto,oldComment); DbContext.CommentWithoutUsers.Update(newComment); await DbContext.SaveChangesAsync(); - return new DataResult(ResultStatus.Success, commentWithoutUserUpdateDto); + return new DataResult(ResultStatus.Success, newComment); } }