From 2547ce0985ae2ec1ee044502087100294eac7990 Mon Sep 17 00:00:00 2001 From: diddnwjd Date: Tue, 12 Mar 2024 23:55:11 +0900 Subject: [PATCH 1/3] =?UTF-8?q?#7=20Fix:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20=ED=95=9C=EB=B2=88=EB=A7=8C=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ixxp/culpop/dto/post/PostList.java | 28 +++++++++++++++++++ .../ixxp/culpop/dto/post/PostResponse.java | 24 ++++------------ .../ixxp/culpop/dto/user/ProfileResponse.java | 5 ++-- .../com/ixxp/culpop/mapper/PostMapper.java | 1 + .../com/ixxp/culpop/service/UserService.java | 14 ++++++---- src/main/resources/mapper/post-mapper.xml | 3 ++ 6 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/ixxp/culpop/dto/post/PostList.java diff --git a/src/main/java/com/ixxp/culpop/dto/post/PostList.java b/src/main/java/com/ixxp/culpop/dto/post/PostList.java new file mode 100644 index 0000000..1d58d69 --- /dev/null +++ b/src/main/java/com/ixxp/culpop/dto/post/PostList.java @@ -0,0 +1,28 @@ +package com.ixxp.culpop.dto.post; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Getter +@NoArgsConstructor +public class PostList { + private int postId; + private String username; + private String title; + private String cateName; + private int viewCount; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") + private LocalDateTime createdAt; + + public PostList(int postId, String username, String title, String cateName, int viewCount, LocalDateTime createdAt) { + this.postId = postId; + this.username = username; + this.title = title; + this.cateName = cateName; + this.viewCount = viewCount; + this.createdAt = createdAt; + } +} diff --git a/src/main/java/com/ixxp/culpop/dto/post/PostResponse.java b/src/main/java/com/ixxp/culpop/dto/post/PostResponse.java index 1d6c1f8..ac7e9aa 100644 --- a/src/main/java/com/ixxp/culpop/dto/post/PostResponse.java +++ b/src/main/java/com/ixxp/culpop/dto/post/PostResponse.java @@ -1,30 +1,18 @@ package com.ixxp.culpop.dto.post; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Getter; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; +import java.util.List; @Getter @NoArgsConstructor public class PostResponse { - private int postId; - private String username; - private String title; - private String cateName; - private int viewCount; - private int postCount; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") - private LocalDateTime createdAt; + private List data; + private int total; - public PostResponse(int postId, String username, String title, String cateName, int viewCount, int postCount, LocalDateTime createdAt) { - this.postId = postId; - this.username = username; - this.title = title; - this.cateName = cateName; - this.viewCount = viewCount; - this.postCount = postCount; - this.createdAt = createdAt; + public PostResponse(List data, int total) { + this.data = data; + this.total = total; } } diff --git a/src/main/java/com/ixxp/culpop/dto/user/ProfileResponse.java b/src/main/java/com/ixxp/culpop/dto/user/ProfileResponse.java index 7e7ae54..a5bba3f 100644 --- a/src/main/java/com/ixxp/culpop/dto/user/ProfileResponse.java +++ b/src/main/java/com/ixxp/culpop/dto/user/ProfileResponse.java @@ -1,5 +1,6 @@ package com.ixxp.culpop.dto.user; +import com.ixxp.culpop.dto.post.PostList; import com.ixxp.culpop.dto.post.PostResponse; import com.ixxp.culpop.entity.User; import lombok.Getter; @@ -13,9 +14,9 @@ public class ProfileResponse { private int userId; private String username; private String email; - private List postList; + private PostResponse postList; - public ProfileResponse(User user, List postList) { + public ProfileResponse(User user, PostResponse postList) { this.userId = user.getId(); this.username = user.getUsername(); this.email = user.getEmail(); diff --git a/src/main/java/com/ixxp/culpop/mapper/PostMapper.java b/src/main/java/com/ixxp/culpop/mapper/PostMapper.java index 8e0f3f1..acbb7d8 100644 --- a/src/main/java/com/ixxp/culpop/mapper/PostMapper.java +++ b/src/main/java/com/ixxp/culpop/mapper/PostMapper.java @@ -12,6 +12,7 @@ public interface PostMapper { Post selectPostDetail(int postId); List selectSearchPost(String word, int offset); List selectPostByUserId(int userId, int offset); + int selectUserPostCount(int userId); int selectPostViewCount(int postId); void updatePostViewCount(int postId); void updatePost(Post post); diff --git a/src/main/java/com/ixxp/culpop/service/UserService.java b/src/main/java/com/ixxp/culpop/service/UserService.java index b5b8eee..dd67e98 100644 --- a/src/main/java/com/ixxp/culpop/service/UserService.java +++ b/src/main/java/com/ixxp/culpop/service/UserService.java @@ -1,6 +1,7 @@ package com.ixxp.culpop.service; import com.ixxp.culpop.dto.popup.PopupResponse; +import com.ixxp.culpop.dto.post.PostList; import com.ixxp.culpop.dto.post.PostResponse; import com.ixxp.culpop.dto.user.ProfileResponse; import com.ixxp.culpop.dto.user.ProfileUpdateRequest; @@ -15,7 +16,6 @@ import com.ixxp.culpop.mapper.UserMapper; import com.ixxp.culpop.util.jwtutil.JwtUtil; -import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseCookie; @@ -25,7 +25,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.time.Duration; import java.util.List; import java.util.stream.Collectors; @@ -94,11 +93,16 @@ public void updateProfile(int userId, ProfileUpdateRequest profileUpdateRequest) public ProfileResponse getProfile(int userId, int page) { int offset = (page - 1) * 5; User user = userMapper.getProfile(userId); + List posts = postMapper.selectPostByUserId(userId, offset); - List postList = posts.stream().map(post -> - new PostResponse(post.getId(), post.getUser().getUsername(), post.getTitle(), post.getCategory().getCateName(), postMapper.selectPostViewCount(post.getId()), posts.size(), post.getCreatedAt()) + List postList = posts.stream().map(post -> + new PostList(post.getId(), post.getUser().getUsername(), post.getTitle(), post.getCategory().getCateName(), postMapper.selectPostViewCount(post.getId()), post.getCreatedAt()) ).collect(Collectors.toList()); - return new ProfileResponse(user, postList); + + int total = postMapper.selectUserPostCount(userId); + PostResponse postResponse = new PostResponse(postList, total); + + return new ProfileResponse(user, postResponse); } // 프로필 관심 팝업 조회 diff --git a/src/main/resources/mapper/post-mapper.xml b/src/main/resources/mapper/post-mapper.xml index bfc8d11..d90b408 100644 --- a/src/main/resources/mapper/post-mapper.xml +++ b/src/main/resources/mapper/post-mapper.xml @@ -75,6 +75,9 @@ ORDER BY p.createdAt DESC LIMIT 5 OFFSET #{offset}; + From 32be8459a50d9a90393b9138e97ce00e8033a5f1 Mon Sep 17 00:00:00 2001 From: diddnwjd Date: Wed, 13 Mar 2024 00:16:00 +0900 Subject: [PATCH 2/3] =?UTF-8?q?#13=20Fix:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20=ED=95=9C=EB=B2=88=EB=A7=8C=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ixxp/culpop/controller/PostController.java | 2 +- src/main/java/com/ixxp/culpop/mapper/PostMapper.java | 1 + .../java/com/ixxp/culpop/service/PostService.java | 11 ++++++++--- src/main/resources/mapper/post-mapper.xml | 9 +++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ixxp/culpop/controller/PostController.java b/src/main/java/com/ixxp/culpop/controller/PostController.java index fb34da2..3fbd400 100644 --- a/src/main/java/com/ixxp/culpop/controller/PostController.java +++ b/src/main/java/com/ixxp/culpop/controller/PostController.java @@ -33,7 +33,7 @@ public ResponseEntity createPost(@AuthenticationPrincipal UserDe // 게시글 전체 조회 @GetMapping() - public ResponseEntity> getPost(@RequestParam(name = "category", defaultValue = "전체") String category + public ResponseEntity getPost(@RequestParam(name = "category", defaultValue = "전체") String category , @RequestParam(name = "page", defaultValue = "1") int page) { return ResponseEntity.ok(postService.getPost(category, page)); } diff --git a/src/main/java/com/ixxp/culpop/mapper/PostMapper.java b/src/main/java/com/ixxp/culpop/mapper/PostMapper.java index acbb7d8..201e9a2 100644 --- a/src/main/java/com/ixxp/culpop/mapper/PostMapper.java +++ b/src/main/java/com/ixxp/culpop/mapper/PostMapper.java @@ -12,6 +12,7 @@ public interface PostMapper { Post selectPostDetail(int postId); List selectSearchPost(String word, int offset); List selectPostByUserId(int userId, int offset); + int selectCategoryPostCount(String category); int selectUserPostCount(int userId); int selectPostViewCount(int postId); void updatePostViewCount(int postId); diff --git a/src/main/java/com/ixxp/culpop/service/PostService.java b/src/main/java/com/ixxp/culpop/service/PostService.java index 3ada506..25f3031 100644 --- a/src/main/java/com/ixxp/culpop/service/PostService.java +++ b/src/main/java/com/ixxp/culpop/service/PostService.java @@ -2,7 +2,9 @@ import com.ixxp.culpop.dto.post.PostDetailResponse; import com.ixxp.culpop.dto.post.PostRequest; +import com.ixxp.culpop.dto.post.PostList; import com.ixxp.culpop.dto.post.PostResponse; +import com.ixxp.culpop.dto.user.ProfileResponse; import com.ixxp.culpop.entity.Category; import com.ixxp.culpop.entity.Post; import com.ixxp.culpop.entity.PostLike; @@ -46,12 +48,15 @@ public void createPost(User user, PostRequest postRequest) { } // 게시글 전체 조회 - public List getPost(String category, int page) { + public PostResponse getPost(String category, int page) { int offset = (page - 1) * 10; List posts = postMapper.selectPost(category, offset); - return posts.stream().map(post -> - new PostResponse(post.getId(), post.getUser().getUsername(), post.getTitle(), post.getCategory().getCateName(), postMapper.selectPostViewCount(post.getId()), posts.size(), post.getCreatedAt()) + List postList = posts.stream().map(post -> + new PostList(post.getId(), post.getUser().getUsername(), post.getTitle(), post.getCategory().getCateName(), postMapper.selectPostViewCount(post.getId()), post.getCreatedAt()) ).collect(Collectors.toList()); + + int total = postMapper.selectCategoryPostCount(category); + return new PostResponse(postList, total); } // 게시글 개별 조회 diff --git a/src/main/resources/mapper/post-mapper.xml b/src/main/resources/mapper/post-mapper.xml index d90b408..bd80b96 100644 --- a/src/main/resources/mapper/post-mapper.xml +++ b/src/main/resources/mapper/post-mapper.xml @@ -75,6 +75,15 @@ ORDER BY p.createdAt DESC LIMIT 5 OFFSET #{offset}; + From 3a7e16186735949cec3e7594e6bae1a0fe33e851 Mon Sep 17 00:00:00 2001 From: diddnwjd Date: Wed, 13 Mar 2024 00:26:39 +0900 Subject: [PATCH 3/3] =?UTF-8?q?#25=20Fix:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20=ED=95=9C=EB=B2=88=EB=A7=8C=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ixxp/culpop/controller/PostController.java | 4 ++-- src/main/java/com/ixxp/culpop/mapper/PostMapper.java | 1 + src/main/java/com/ixxp/culpop/service/PostService.java | 8 +++++--- src/main/resources/mapper/post-mapper.xml | 4 ++++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/ixxp/culpop/controller/PostController.java b/src/main/java/com/ixxp/culpop/controller/PostController.java index 3fbd400..9e299cb 100644 --- a/src/main/java/com/ixxp/culpop/controller/PostController.java +++ b/src/main/java/com/ixxp/culpop/controller/PostController.java @@ -85,9 +85,9 @@ public ResponseEntity unlikePost(@AuthenticationPrincipal UserDe // 게시글 검색 @GetMapping("/search") - public ResponseEntity> getSearchPost(@RequestParam("word") String word, + public ResponseEntity getSearchPost(@RequestParam("word") String word, @RequestParam(name = "page", defaultValue = "1") int page) { - List postResponses = postService.getSearchPost(word, page); + PostResponse postResponses = postService.getSearchPost(word, page); return ResponseEntity.ok(postResponses); } diff --git a/src/main/java/com/ixxp/culpop/mapper/PostMapper.java b/src/main/java/com/ixxp/culpop/mapper/PostMapper.java index 201e9a2..d9ff6ed 100644 --- a/src/main/java/com/ixxp/culpop/mapper/PostMapper.java +++ b/src/main/java/com/ixxp/culpop/mapper/PostMapper.java @@ -13,6 +13,7 @@ public interface PostMapper { List selectSearchPost(String word, int offset); List selectPostByUserId(int userId, int offset); int selectCategoryPostCount(String category); + int selectWordPostCount(String word); int selectUserPostCount(int userId); int selectPostViewCount(int postId); void updatePostViewCount(int postId); diff --git a/src/main/java/com/ixxp/culpop/service/PostService.java b/src/main/java/com/ixxp/culpop/service/PostService.java index 25f3031..b3fc049 100644 --- a/src/main/java/com/ixxp/culpop/service/PostService.java +++ b/src/main/java/com/ixxp/culpop/service/PostService.java @@ -150,11 +150,13 @@ public void unlikePost(User user, int postId) { } // 게시글 검색 - public List getSearchPost(String word, int page) { + public PostResponse getSearchPost(String word, int page) { int offset = (page - 1) * 10; List posts = postMapper.selectSearchPost(word, offset); - return posts.stream().map(post -> - new PostResponse(post.getId(), post.getUser().getUsername(), post.getTitle(), post.getCategory().getCateName(), postMapper.selectPostViewCount(post.getId()), posts.size(), post.getCreatedAt()) + List postList = posts.stream().map(post -> + new PostList(post.getId(), post.getUser().getUsername(), post.getTitle(), post.getCategory().getCateName(), postMapper.selectPostViewCount(post.getId()), post.getCreatedAt()) ).collect(Collectors.toList()); + int total = postMapper.selectWordPostCount(word); + return new PostResponse(postList, total); } } diff --git a/src/main/resources/mapper/post-mapper.xml b/src/main/resources/mapper/post-mapper.xml index bd80b96..3bece32 100644 --- a/src/main/resources/mapper/post-mapper.xml +++ b/src/main/resources/mapper/post-mapper.xml @@ -84,6 +84,10 @@ +