diff --git a/VNH.Application/DTOs/Catalog/Posts/PostFpkDto.cs b/VNH.Application/DTOs/Catalog/Posts/PostFpkDto.cs index 7f1a0be..8363511 100644 --- a/VNH.Application/DTOs/Catalog/Posts/PostFpkDto.cs +++ b/VNH.Application/DTOs/Catalog/Posts/PostFpkDto.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VNH.Application.DTOs.Catalog.Posts +namespace VNH.Application.DTOs.Catalog.Posts { public class PostFpkDto { diff --git a/VNH.Application/Interfaces/Catalog/HashTags/IHashTag.cs b/VNH.Application/Interfaces/Catalog/HashTags/IHashTag.cs index e27359f..96c9198 100644 --- a/VNH.Application/Interfaces/Catalog/HashTags/IHashTag.cs +++ b/VNH.Application/Interfaces/Catalog/HashTags/IHashTag.cs @@ -1,4 +1,5 @@ using VNH.Application.DTOs.Catalog.HashTags; +using VNH.Application.DTOs.Common.ResponseNotification; using VNH.Domain; namespace VNH.Application.Interfaces.Catalog.HashTags @@ -7,5 +8,6 @@ public interface IHashTag { Task> GetAll(); Task AddTag(Tag tag); + Task>> GetAllTag(int numberTag); } } diff --git a/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs b/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs index 5cf5157..33deb32 100644 --- a/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs +++ b/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs @@ -20,11 +20,12 @@ public interface IPostService Task> GetReport(); Task> GetLike(PostFpkDto postFpk); Task> GetSave(PostFpkDto postFpk); - Task>> GetTopTags(int numberTag); Task>> GetPostByTag(string tag); Task>> GetComment(string postId); Task>> CreateComment(CommentPostDto comment); Task>> UpdateComment(CommentPostDto comment); Task> DeteleComment(string id); + Task>> GetMyPostSaved(string id); + Task>> GetMyPost(string id); } } \ No newline at end of file diff --git a/VNH.Infrastructure/Implement/Catalog/HashTags/TagService.cs b/VNH.Infrastructure/Implement/Catalog/HashTags/TagService.cs index 75e76ee..a472bdd 100644 --- a/VNH.Infrastructure/Implement/Catalog/HashTags/TagService.cs +++ b/VNH.Infrastructure/Implement/Catalog/HashTags/TagService.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using VNH.Application.DTOs.Catalog.HashTags; +using VNH.Application.DTOs.Common.ResponseNotification; using VNH.Application.Interfaces.Catalog.HashTags; using VNH.Domain; using VNH.Infrastructure.Presenters.Migrations; @@ -41,5 +42,29 @@ public async Task> GetAll() } return tagDtos; } + + public async Task>> GetAllTag(int numberTag) + { + if (numberTag <= 0) + { + var tags = await _dataContext.Tags + .GroupBy(x => x.Name) + .Select(group => new { Name = group.Key, Count = group.Sum(t => 1) }) + .OrderByDescending(tagName => tagName.Count) + .Select(group => group.Name) + .ToListAsync(); + return new ApiSuccessResult>(tags); + } else + { + var tags = await _dataContext.Tags + .GroupBy(x => x.Name) + .Select(group => new { Name = group.Key, Count = group.Sum(t => 1) }) + .OrderByDescending(tagName => tagName.Count) + .Take(numberTag) + .Select(group => group.Name) + .ToListAsync(); + return new ApiSuccessResult>(tags); + } + } } } diff --git a/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs b/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs index 34aaee2..d5e1548 100644 --- a/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs +++ b/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs @@ -421,19 +421,6 @@ public async Task> GetSave(PostFpkDto postFpk) return new ApiSuccessResult(reuslt); } - public async Task>> GetTopTags(int numberTag) - { - var tags = await _dataContext.Tags - .GroupBy(x => x.Name) - .Select(group => new { Name = group.Key, Count = group.Sum(t => 1) }) - .OrderByDescending(tagName => tagName.Count) - .Take(numberTag) - .Select(group => group.Name) - .ToListAsync(); - - return new ApiSuccessResult>(tags); - } - public async Task>> GetPostByTag(string tag) { var posts = await _dataContext.Posts @@ -563,5 +550,38 @@ public async Task> DeteleComment(string id) await _dataContext.SaveChangesAsync(); return new ApiSuccessResult(); } + + public async Task>> GetMyPostSaved(string id) + { + Guid userId = Guid.Parse(id); + var users = await _dataContext.User.ToListAsync(); + + var posts = await ( + from postSave in _dataContext.PostSaves + join post in _dataContext.Posts on postSave.PostId equals post.Id + where postSave.UserId == userId + select post + ).ToListAsync(); + + var result = new List(); + foreach (var item in posts) + { + var post = _mapper.Map(item); + var userShort = users.First(x => x.Id == item.UserId); + if (userShort is not null) + { + post.UserShort.FullName = userShort.Fullname; + post.UserShort.Id = userShort.Id; + post.UserShort.Image = userShort.Image; + } + post.Image = item.Image; + result.Add(post); + } + return new ApiSuccessResult>(result); + } + public Task>> GetMyPost(string id) + { + throw new NotImplementedException(); + } } } diff --git a/VNH.WebAPi/Controllers/HashTagController.cs b/VNH.WebAPi/Controllers/HashTagController.cs index 4e41ad3..5c930c6 100644 --- a/VNH.WebAPi/Controllers/HashTagController.cs +++ b/VNH.WebAPi/Controllers/HashTagController.cs @@ -17,9 +17,14 @@ public HashTagController(IHashTag hashTagService) { [HttpGet] public async Task GetAll() { - return Ok(await _hasgTagService.GetAll()); + var result = await _hasgTagService.GetAllTag(0); + return result is null ? BadRequest(result) : Ok(result); + } + [HttpGet("TopTag")] + public async Task GetTopTags(int numberTag) + { + var result = await _hasgTagService.GetAllTag(numberTag); + return result is null ? BadRequest(result) : Ok(result); } - - } } diff --git a/VNH.WebAPi/Controllers/PostController.cs b/VNH.WebAPi/Controllers/PostController.cs index d21aa9e..cda3bba 100644 --- a/VNH.WebAPi/Controllers/PostController.cs +++ b/VNH.WebAPi/Controllers/PostController.cs @@ -87,6 +87,23 @@ public async Task GetSavePost([FromQuery] PostFpkDto postFpk) var result = await _postService.GetSave(postFpk); return result is null ? BadRequest(result) : Ok(result); } + [HttpGet()] + [Authorize] + public async Task GetMyPostSaved() + { + var id = User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? ""; + var result = await _postService.GetMyPostSaved(id); + return result is null ? BadRequest(result) : Ok(result); + } + [HttpGet("MyPost")] + [Authorize] + public async Task GetMyPost() + { + var id = User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? ""; + var result = await _postService.GetMyPost(id); + return result is null ? BadRequest(result) : Ok(result); + } + [HttpPost("Save")] [Authorize] public async Task Save([FromForm] PostFpkDto postFpk) @@ -110,12 +127,6 @@ public async Task GetReport() var result = await _postService.GetReport(); return result is null ? BadRequest(result) : Ok(result); } - [HttpGet("TopTag")] - public async Task GetTopTags(int numberTag) - { - var result = await _postService.GetTopTags(numberTag); - return result is null ? BadRequest(result) : Ok(result); - } [HttpGet("FindByTag")] public async Task GetPostByTag(string tag) { diff --git a/VNH.WebAPi/wwwroot/Images/480bd1c7-64e6-4b48-bd03-e3ec56d8b12a.jpg b/VNH.WebAPi/wwwroot/Images/480bd1c7-64e6-4b48-bd03-e3ec56d8b12a.jpg new file mode 100644 index 0000000..38c6ca6 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/480bd1c7-64e6-4b48-bd03-e3ec56d8b12a.jpg differ