From 561544f6d1fa1144523b46deb999c5405e8dba55 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Thu, 11 Jan 2024 23:01:05 +0900 Subject: [PATCH 01/19] =?UTF-8?q?[feat]=20#34=20=EB=82=B4=EA=B0=80=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=ED=95=9C=20=EA=B2=8C=EC=8B=9C=EB=AC=BC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20api=20controller=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checkmate/domain/post/controller/PostController.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java index ff131fa..f5848d1 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java +++ b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java @@ -42,6 +42,13 @@ public ResponseEntity> searchTextPost(@UserId final Long user return SuccessResponse.ok(responseDto); } + @GetMapping("/my") + public ResponseEntity> getMyPosts(@UserId final Long userId, + final Pageable pageable) { + final PostSearchResponseDto responseDto = postService.getMyPosts(userId, pageable); + return SuccessResponse.ok(responseDto); + } + @PostMapping public ResponseEntity> createPost(@UserId final Long userId, @RequestBody @Valid final PostCreateRequestDto requestDto) { From 17d622a83bae6c6879830dfe001aa1f0db45f613 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Thu, 11 Jan 2024 23:01:13 +0900 Subject: [PATCH 02/19] =?UTF-8?q?[feat]=20#34=20=EB=82=B4=EA=B0=80=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=ED=95=9C=20=EA=B2=8C=EC=8B=9C=EB=AC=BC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20api=20service=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/service/PostService.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java index 68494a4..70bf4df 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java +++ b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java @@ -14,6 +14,7 @@ import org.gachon.checkmate.domain.post.dto.response.PostSearchElementResponseDto; import org.gachon.checkmate.domain.post.dto.response.PostSearchResponseDto; import org.gachon.checkmate.domain.post.dto.support.PostDetailDto; +import org.gachon.checkmate.domain.post.dto.support.PostPagingSearchCondition; import org.gachon.checkmate.domain.post.dto.support.PostSearchCondition; import org.gachon.checkmate.domain.post.dto.support.PostSearchDto; import org.gachon.checkmate.domain.post.entity.Post; @@ -53,6 +54,14 @@ public void createPost(Long userId, PostCreateRequestDto requestDto) { createPostCheckListAndSave(requestDto.checkList(), post); } + public PostSearchResponseDto getMyPosts(Long userId, Pageable pageable) { + CheckList checkList = getCheckList(userId); + PostPagingSearchCondition condition = PostPagingSearchCondition.searchSelectedUser(userId, pageable); + Page postSearchList = getTextSearchResults(condition); + List searchResults = createPostSearchResponseDto(postSearchList, checkList); + return PostSearchResponseDto.of(searchResults, postSearchList.getTotalPages(), postSearchList.getTotalElements()); + } + public PostSearchResponseDto getAllPosts(Long userId, String key, String type, String gender, Pageable pageable) { CheckList checkList = getCheckList(userId); PostSearchCondition condition = PostSearchCondition.of(type, key, gender, pageable); @@ -72,7 +81,8 @@ public PostDetailResponseDto getPostDetails(Long postId) { public PostSearchResponseDto searchTextPost(Long userId, String text, Pageable pageable) { CheckList checkList = getCheckList(userId); - Page postSearchList = getTextSearchResults(text, pageable); + PostPagingSearchCondition condition = PostPagingSearchCondition.searchText(text, pageable); + Page postSearchList = getTextSearchResults(condition); List searchResults = createPostSearchResponseDto(postSearchList, checkList); return PostSearchResponseDto.of(searchResults, postSearchList.getTotalPages(), postSearchList.getTotalElements()); } @@ -149,18 +159,17 @@ private Post createPostAndSave(PostCreateRequestDto postCreateRequestDto, User u return post; } - private PostCheckList createPostCheckListAndSave(CheckListRequestDto checkListRequestDto, Post post) { + private void createPostCheckListAndSave(CheckListRequestDto checkListRequestDto, Post post) { PostCheckList postCheckList = PostCheckList.createPostCheckList(checkListRequestDto, post); postCheckListRepository.save(postCheckList); - return postCheckList; } private Page getSearchResults(PostSearchCondition condition) { return postRepository.searchPosts(condition); } - private Page getTextSearchResults(String text, Pageable pageable) { - return postRepository.searchTextPost(text, pageable); + private Page getTextSearchResults(PostPagingSearchCondition condition) { + return postRepository.searchPostsWithPaging(condition); } private CheckList getCheckList(Long userId) { From 004effaaddd88586fc130ba41872601c1287fc51 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Thu, 11 Jan 2024 23:01:55 +0900 Subject: [PATCH 03/19] =?UTF-8?q?[fix]=20#34=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EC=BF=BC=EB=A6=AC=EB=A5=BC=20custom=20?= =?UTF-8?q?paging=EA=B3=BC=20spring=20paging=20=EC=82=AC=EC=9A=A9=EC=97=AC?= =?UTF-8?q?=EB=B6=80=EB=A1=9C=20=EA=B5=AC=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/repository/PostCustomRepository.java | 4 ++-- .../repository/PostCustomRepositoryImpl.java | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepository.java b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepository.java index 3db1f83..9429d88 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepository.java +++ b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepository.java @@ -1,15 +1,15 @@ package org.gachon.checkmate.domain.post.repository; import org.gachon.checkmate.domain.post.dto.support.PostDetailDto; +import org.gachon.checkmate.domain.post.dto.support.PostPagingSearchCondition; import org.gachon.checkmate.domain.post.dto.support.PostSearchCondition; import org.gachon.checkmate.domain.post.dto.support.PostSearchDto; import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import java.util.Optional; public interface PostCustomRepository { Optional findPostDetail(Long postId); Page searchPosts(PostSearchCondition condition); - Page searchTextPost(String text, Pageable pageable); + Page searchPostsWithPaging(PostPagingSearchCondition condition); } diff --git a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java index 08742b9..4dfcf12 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java +++ b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java @@ -9,7 +9,6 @@ import org.gachon.checkmate.domain.post.entity.ImportantKeyType; import org.gachon.checkmate.domain.post.entity.Post; import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.data.support.PageableExecutionUtils; import java.time.LocalDate; @@ -75,7 +74,7 @@ public Page searchPosts(PostSearchCondition condition) { } @Override - public Page searchTextPost(String text, Pageable pageable) { + public Page searchPostsWithPaging(PostPagingSearchCondition condition) { List content = queryFactory .select(new QPostSearchDto( post.id, @@ -92,16 +91,21 @@ public Page searchTextPost(String text, Pageable pageable) { .leftJoin(post.postCheckList, postCheckList) .leftJoin(post.user, user) .where( - containTextCondition(text), + containTextCondition(condition.text()), + eqUserId(condition.selectedUser()), validatePostDate() ) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) + .offset(condition.pageable().getOffset()) + .limit(condition.pageable().getPageSize()) .fetch(); JPAQuery countQuery = queryFactory .selectFrom(post); - return PageableExecutionUtils.getPage(content, pageable, countQuery::fetchCount); + return PageableExecutionUtils.getPage(content, condition.pageable(), countQuery::fetchCount); + } + + private BooleanExpression eqUserId(Long userId) { + return userId != null ? user.id.eq(userId) : null; } private BooleanExpression eqPostId(Long postId) { From 2fb03197594c6191cfd375df116bd1d43eb6c421 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Thu, 11 Jan 2024 23:02:18 +0900 Subject: [PATCH 04/19] =?UTF-8?q?[feat]=20#34=20spring=20paging=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=20=EC=A1=B0=ED=9A=8C=20condition=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../support/PostPagingSearchCondition.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/post/dto/support/PostPagingSearchCondition.java diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostPagingSearchCondition.java b/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostPagingSearchCondition.java new file mode 100644 index 0000000..1a40ca5 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostPagingSearchCondition.java @@ -0,0 +1,27 @@ +package org.gachon.checkmate.domain.post.dto.support; + +import lombok.Builder; +import org.springframework.data.domain.Pageable; + +@Builder +public record PostPagingSearchCondition( + String text, + Long selectedUser, + Pageable pageable +) { + public static PostPagingSearchCondition searchText(String text, Pageable pageable) { + return PostPagingSearchCondition.builder() + .text(text) + .selectedUser(null) + .pageable(pageable) + .build(); + } + + public static PostPagingSearchCondition searchSelectedUser(Long userId, Pageable pageable) { + return PostPagingSearchCondition.builder() + .text(null) + .selectedUser(userId) + .pageable(pageable) + .build(); + } +} From 0503746d0cfab4c995ae612315a7c1d164444094 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Thu, 11 Jan 2024 23:58:18 +0900 Subject: [PATCH 05/19] =?UTF-8?q?[feat]=20#34=20scrap=20mapping=20?= =?UTF-8?q?=EA=B4=80=EA=B3=84=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gachon/checkmate/domain/member/entity/User.java | 7 +++++++ .../org/gachon/checkmate/domain/post/entity/Post.java | 4 ++++ .../gachon/checkmate/domain/scrap/entity/Scrap.java | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/member/entity/User.java b/src/main/java/org/gachon/checkmate/domain/member/entity/User.java index dcfb23d..855e362 100644 --- a/src/main/java/org/gachon/checkmate/domain/member/entity/User.java +++ b/src/main/java/org/gachon/checkmate/domain/member/entity/User.java @@ -5,6 +5,7 @@ import org.gachon.checkmate.domain.checkList.entity.CheckList; import org.gachon.checkmate.domain.member.converter.GenderTypeConverter; import org.gachon.checkmate.domain.member.converter.MbtiTypeConverter; +import org.gachon.checkmate.domain.member.converter.UserStateConverter; import org.gachon.checkmate.domain.post.entity.Post; import org.gachon.checkmate.domain.scrap.entity.Scrap; import org.gachon.checkmate.global.common.BaseTimeEntity; @@ -29,6 +30,8 @@ public class User extends BaseTimeEntity { private String profile; private String school; private String major; + @Convert(converter = UserStateConverter.class) + private UserState userState; @Convert(converter = MbtiTypeConverter.class) private MbtiType mbtiType; @Convert(converter = GenderTypeConverter.class) @@ -70,4 +73,8 @@ public void setProfile(String profile) { public void addPost(Post post) { this.postList.add(post); } + + public void addScrap(Scrap scrap) { + this.scrapList.add(scrap); + } } diff --git a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java index e38dfe1..fb8f552 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java +++ b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java @@ -60,4 +60,8 @@ public static Post createPost(PostCreateRequestDto postCreateRequestDto, User us public void setPostCheckList(PostCheckList postCheckList) { this.postCheckList = postCheckList; } + + public void addScrap(Scrap scrap) { + this.scrapList.add(scrap); + } } diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/entity/Scrap.java b/src/main/java/org/gachon/checkmate/domain/scrap/entity/Scrap.java index b4b4212..fbc0206 100644 --- a/src/main/java/org/gachon/checkmate/domain/scrap/entity/Scrap.java +++ b/src/main/java/org/gachon/checkmate/domain/scrap/entity/Scrap.java @@ -22,4 +22,14 @@ public class Scrap extends BaseTimeEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "post_id") private Post post; + + public static Scrap createScrap(User user, Post post) { + Scrap scrap = Scrap.builder() + .user(user) + .post(post) + .build(); + user.addScrap(scrap); + post.addScrap(scrap); + return scrap; + } } From 5313b7ae5e49c569a5948be66c47ce97d6dee673 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Thu, 11 Jan 2024 23:58:57 +0900 Subject: [PATCH 06/19] =?UTF-8?q?[feat]=20#34=20scrap=20crd=20api=20contro?= =?UTF-8?q?ller=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scrap/controller/ScrapController.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/scrap/controller/ScrapController.java diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/controller/ScrapController.java b/src/main/java/org/gachon/checkmate/domain/scrap/controller/ScrapController.java new file mode 100644 index 0000000..c2ca579 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/scrap/controller/ScrapController.java @@ -0,0 +1,38 @@ +package org.gachon.checkmate.domain.scrap.controller; + +import lombok.RequiredArgsConstructor; +import org.gachon.checkmate.domain.post.dto.response.PostSearchResponseDto; +import org.gachon.checkmate.domain.scrap.dto.request.ScrapRequestDto; +import org.gachon.checkmate.domain.scrap.service.ScrapService; +import org.gachon.checkmate.global.common.SuccessResponse; +import org.gachon.checkmate.global.config.auth.UserId; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RequestMapping("/api/scrap") +@RestController +public class ScrapController { + private final ScrapService scrapService; + + @GetMapping + public ResponseEntity> getScrapPosts(@UserId final Long userId, + final Pageable pageable) { + final PostSearchResponseDto responseDto = scrapService.getScrapPosts(userId, pageable); + return SuccessResponse.ok(responseDto); + } + + @PostMapping + public ResponseEntity> createScrapPost(@UserId final Long userId, + @RequestBody final ScrapRequestDto requestDto) { + scrapService.creatScrapPost(userId, requestDto); + return SuccessResponse.created(null); + } + + @DeleteMapping("/{id}") + public ResponseEntity> deleteScrapPost(@PathVariable("id") final Long scrapId) { + scrapService.deleteScrapPost(scrapId); + return SuccessResponse.ok(null); + } +} From 9489190b4ec2b908edecf6876996cf99cb680c2d Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Thu, 11 Jan 2024 23:59:08 +0900 Subject: [PATCH 07/19] =?UTF-8?q?[feat]=20#34=20scrap=20crd=20api=20servic?= =?UTF-8?q?e=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/scrap/service/ScrapService.java | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/scrap/service/ScrapService.java diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/service/ScrapService.java b/src/main/java/org/gachon/checkmate/domain/scrap/service/ScrapService.java new file mode 100644 index 0000000..84e0460 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/scrap/service/ScrapService.java @@ -0,0 +1,110 @@ +package org.gachon.checkmate.domain.scrap.service; + +import lombok.RequiredArgsConstructor; +import org.gachon.checkmate.domain.checkList.entity.CheckList; +import org.gachon.checkmate.domain.checkList.entity.PostCheckList; +import org.gachon.checkmate.domain.checkList.repository.CheckListRepository; +import org.gachon.checkmate.domain.member.entity.User; +import org.gachon.checkmate.domain.member.repository.UserRepository; +import org.gachon.checkmate.domain.post.dto.response.PostSearchElementResponseDto; +import org.gachon.checkmate.domain.post.dto.response.PostSearchResponseDto; +import org.gachon.checkmate.domain.post.dto.support.PostSearchDto; +import org.gachon.checkmate.domain.post.entity.Post; +import org.gachon.checkmate.domain.post.repository.PostRepository; +import org.gachon.checkmate.domain.scrap.dto.request.ScrapRequestDto; +import org.gachon.checkmate.domain.scrap.dto.support.ScrapSearchCondition; +import org.gachon.checkmate.domain.scrap.entity.Scrap; +import org.gachon.checkmate.domain.scrap.repository.ScrapRepository; +import org.gachon.checkmate.global.error.exception.EntityNotFoundException; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.List; +import java.util.stream.Collectors; + +import static org.gachon.checkmate.global.error.ErrorCode.*; + +@RequiredArgsConstructor +@Transactional +@Service +public class ScrapService { + private final ScrapRepository scrapRepository; + private final UserRepository userRepository; + private final PostRepository postRepository; + private final CheckListRepository checkListRepository; + + public PostSearchResponseDto getScrapPosts(Long userId, Pageable pageable) { + CheckList checkList = getCheckList(userId); + ScrapSearchCondition condition = ScrapSearchCondition.of(userId, pageable); + Page myScrapPosts = findMyScrapPosts(condition); + List searchResults = createPostSearchResponseDto(myScrapPosts, checkList); + return PostSearchResponseDto.of(searchResults, myScrapPosts.getTotalPages(), myScrapPosts.getTotalElements()); + } + + public void creatScrapPost(Long userId, ScrapRequestDto scrapRequestDto) { + User user = findUserOrThrow(userId); + Post post = findPostOrThrow(scrapRequestDto.postId()); + createScrapAndSave(user, post); + } + + public void deleteScrapPost(Long scrapId) { + scrapRepository.deleteById(scrapId); + } + + private List createPostSearchResponseDto(Page postSearchDtoList, CheckList checkList) { + return postSearchDtoList.stream() + .map(postSearchDto -> + PostSearchElementResponseDto.of( + postSearchDto, + getRemainDate(postSearchDto.endDate()), + getAccuracy(postSearchDto.postCheckList(), checkList))) + .collect(Collectors.toList()); + } + + private int getAccuracy(PostCheckList postCheckList, CheckList checkList) { + int count = 0; + count += getRateForFrequencyElement(postCheckList.getCleanType().getCode(), checkList.getCleanType().getCode(), 4); + count += getRateForFrequencyElement(postCheckList.getDrinkType().getCode(), checkList.getDrinkType().getCode(), 3); + count += getRateForFrequencyElement(postCheckList.getHomeType().getCode(), checkList.getHomeType().getCode(), 3); + count = postCheckList.getLifePatterType().equals(checkList.getLifePatterType()) ? count + 1 : count; + count = postCheckList.getNoiseType().equals(checkList.getNoiseType()) ? count + 1 : count; + count = postCheckList.getSleepType().equals(checkList.getSleepType()) ? count + 1 : count; + return (int) (count / 6) * 100; + } + + private int getRateForFrequencyElement(String firstEnumCode, String secondEnumCode, int size) { + return 1 - Math.abs(Integer.parseInt(firstEnumCode) - Integer.parseInt(secondEnumCode)) / size; + } + + private int getRemainDate(LocalDate endDate) { + return (int) LocalDate.now().until(endDate, ChronoUnit.DAYS); + } + + private void createScrapAndSave(User user, Post post) { + Scrap scrap = Scrap.createScrap(user, post); + scrapRepository.save(scrap); + } + + private CheckList getCheckList(Long userId) { + return checkListRepository.findByUserId(userId) + .orElseThrow(() -> new EntityNotFoundException(CHECK_LIST_NOT_FOUND)); + } + + private Page findMyScrapPosts(ScrapSearchCondition condition) { + return scrapRepository.searchMyScrapPosts(condition); + } + + private User findUserOrThrow(Long userId) { + return userRepository.findById(userId) + .orElseThrow(() -> new EntityNotFoundException(USER_NOT_FOUND)); + } + + private Post findPostOrThrow(Long postId) { + return postRepository.findById(postId) + .orElseThrow(() -> new EntityNotFoundException(POST_NOT_FOUND)); + } +} From 4f26b0f35639bc74ec704d1c502c5e5a60c361d4 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Fri, 12 Jan 2024 00:00:10 +0900 Subject: [PATCH 08/19] =?UTF-8?q?[feat]=20#34=20user=20=EC=83=81=ED=83=9C?= =?UTF-8?q?=20=EA=B4=80=EB=A6=AC=20enum=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/converter/UserStateConverter.java | 10 ++++++++++ .../domain/member/entity/UserState.java | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/member/converter/UserStateConverter.java create mode 100644 src/main/java/org/gachon/checkmate/domain/member/entity/UserState.java diff --git a/src/main/java/org/gachon/checkmate/domain/member/converter/UserStateConverter.java b/src/main/java/org/gachon/checkmate/domain/member/converter/UserStateConverter.java new file mode 100644 index 0000000..23ae85e --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/converter/UserStateConverter.java @@ -0,0 +1,10 @@ +package org.gachon.checkmate.domain.member.converter; + +import org.gachon.checkmate.domain.member.entity.UserState; +import org.gachon.checkmate.global.utils.AbstractEnumCodeAttributeConverter; + +public class UserStateConverter extends AbstractEnumCodeAttributeConverter { + public UserStateConverter() { + super(UserState.class); + } +} diff --git a/src/main/java/org/gachon/checkmate/domain/member/entity/UserState.java b/src/main/java/org/gachon/checkmate/domain/member/entity/UserState.java new file mode 100644 index 0000000..385253c --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/member/entity/UserState.java @@ -0,0 +1,16 @@ +package org.gachon.checkmate.domain.member.entity; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.gachon.checkmate.global.utils.EnumField; + +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +public enum UserState implements EnumField { + JOIN("1", "가입"), + WITHDRAW("2", "탈퇴"); + + private final String code; + private final String desc; +} From 29d99ec8729b026c70e01ac3f8504d9f21ba76f1 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Fri, 12 Jan 2024 00:00:24 +0900 Subject: [PATCH 09/19] =?UTF-8?q?[feat]=20#34=20scrap=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=20=EC=A1=B0=EA=B1=B4=20=EA=B0=9D=EC=B2=B4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scrap/dto/support/ScrapSearchCondition.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/scrap/dto/support/ScrapSearchCondition.java diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/dto/support/ScrapSearchCondition.java b/src/main/java/org/gachon/checkmate/domain/scrap/dto/support/ScrapSearchCondition.java new file mode 100644 index 0000000..d18ed1d --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/scrap/dto/support/ScrapSearchCondition.java @@ -0,0 +1,17 @@ +package org.gachon.checkmate.domain.scrap.dto.support; + +import lombok.Builder; +import org.springframework.data.domain.Pageable; + +@Builder +public record ScrapSearchCondition( + Long userId, + Pageable pageable +) { + public static ScrapSearchCondition of(Long userId, Pageable pageable) { + return ScrapSearchCondition.builder() + .userId(userId) + .pageable(pageable) + .build(); + } +} From 7373838e330a0f866f4ba04d34bedd77c06e6180 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Fri, 12 Jan 2024 00:00:40 +0900 Subject: [PATCH 10/19] =?UTF-8?q?[feat]=20#34=20scrap=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20request=20dto=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checkmate/domain/scrap/dto/request/ScrapRequestDto.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/scrap/dto/request/ScrapRequestDto.java diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/dto/request/ScrapRequestDto.java b/src/main/java/org/gachon/checkmate/domain/scrap/dto/request/ScrapRequestDto.java new file mode 100644 index 0000000..2cab650 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/scrap/dto/request/ScrapRequestDto.java @@ -0,0 +1,6 @@ +package org.gachon.checkmate.domain.scrap.dto.request; + +public record ScrapRequestDto( + Long postId +) { +} From 78a6fa3b0380c4fb1eef45ee5c0e9cce8e05cb9c Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Fri, 12 Jan 2024 00:00:58 +0900 Subject: [PATCH 11/19] =?UTF-8?q?[feat]=20#34=20scrap=20query=20dsl=20?= =?UTF-8?q?=EC=B6=94=EC=83=81=ED=99=94=20=EB=B0=8F=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ScrapCustomRepository.java | 9 +++ .../repository/ScrapCustomRepositoryImpl.java | 70 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepository.java create mode 100644 src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepository.java b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepository.java new file mode 100644 index 0000000..ec98b3c --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepository.java @@ -0,0 +1,9 @@ +package org.gachon.checkmate.domain.scrap.repository; + +import org.gachon.checkmate.domain.post.dto.support.PostSearchDto; +import org.gachon.checkmate.domain.scrap.dto.support.ScrapSearchCondition; +import org.springframework.data.domain.Page; + +public interface ScrapCustomRepository { + Page searchMyScrapPosts(ScrapSearchCondition condition); +} diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java new file mode 100644 index 0000000..df925c3 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java @@ -0,0 +1,70 @@ +package org.gachon.checkmate.domain.scrap.repository; + +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.gachon.checkmate.domain.member.entity.UserState; +import org.gachon.checkmate.domain.post.dto.support.PostSearchDto; +import org.gachon.checkmate.domain.post.dto.support.QPostSearchDto; +import org.gachon.checkmate.domain.post.entity.Post; +import org.gachon.checkmate.domain.scrap.dto.support.ScrapSearchCondition; +import org.springframework.data.domain.Page; +import org.springframework.data.support.PageableExecutionUtils; + +import java.time.LocalDate; +import java.util.List; + +import static org.gachon.checkmate.domain.checkList.entity.QPostCheckList.postCheckList; +import static org.gachon.checkmate.domain.member.entity.QUser.user; +import static org.gachon.checkmate.domain.post.entity.QPost.post; +import static org.gachon.checkmate.domain.scrap.entity.QScrap.scrap; + +@RequiredArgsConstructor +public class ScrapCustomRepositoryImpl implements ScrapCustomRepository { + private final JPAQueryFactory queryFactory; + + @Override + public Page searchMyScrapPosts(ScrapSearchCondition condition) { + List content = queryFactory + .select(new QPostSearchDto( + post.id, + post.title, + post.content, + post.importantKeyType, + post.similarityKeyType, + post.endDate, + post.scrapList.size(), + postCheckList, + user.gender + )) + .from(scrap) + .leftJoin(scrap.post, post) + .leftJoin(scrap.post.postCheckList, postCheckList) + .leftJoin(scrap.user, user) + .where( + eqUserId(condition.userId()), + validateUserState(), + validatePostDate() + ) + .offset(condition.pageable().getOffset()) + .limit(condition.pageable().getPageSize()) + .fetch(); + + JPAQuery countQuery = queryFactory + .selectFrom(post); + return PageableExecutionUtils.getPage(content, condition.pageable(), countQuery::fetchCount); + } + + private BooleanExpression eqUserId(Long userId) { + return userId != null ? user.id.eq(userId) : null; + } + + private BooleanExpression validateUserState() { + return user.userState.eq(UserState.JOIN); + } + + private BooleanExpression validatePostDate() { + return post.endDate.after(LocalDate.now()); + } +} From 6fbe42eae6e4fbc828bb8943713d8c909bc17385 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Fri, 12 Jan 2024 00:01:24 +0900 Subject: [PATCH 12/19] =?UTF-8?q?[feat]=20#34=20scrap=20jpa=20repository?= =?UTF-8?q?=20=EB=B0=8F=20custom=20repository=20=EC=B6=94=EC=83=81?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checkmate/domain/scrap/repository/ScrapRepository.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java new file mode 100644 index 0000000..b1e8a90 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java @@ -0,0 +1,7 @@ +package org.gachon.checkmate.domain.scrap.repository; + +import org.gachon.checkmate.domain.scrap.entity.Scrap; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ScrapRepository extends JpaRepository, ScrapCustomRepository { +} From b025c826f3728eb0fc92122da0d146c8e40b3f0c Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Fri, 12 Jan 2024 00:01:55 +0900 Subject: [PATCH 13/19] =?UTF-8?q?[feat]=20#34=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=EA=B4=80=EB=A6=AC=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EC=A1=B0=ED=9A=8C=20=EC=A1=B0=EA=B1=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/repository/PostCustomRepositoryImpl.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java index 4dfcf12..e908b5f 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java +++ b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java @@ -5,6 +5,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; import org.gachon.checkmate.domain.member.entity.GenderType; +import org.gachon.checkmate.domain.member.entity.UserState; import org.gachon.checkmate.domain.post.dto.support.*; import org.gachon.checkmate.domain.post.entity.ImportantKeyType; import org.gachon.checkmate.domain.post.entity.Post; @@ -64,6 +65,7 @@ public Page searchPosts(PostSearchCondition condition) { .where( eqImportantKey(condition.importantKeyType()), eqGenderType(condition.genderType()), + validateUserState(), validatePostDate() ) .fetch(); @@ -93,6 +95,7 @@ public Page searchPostsWithPaging(PostPagingSearchCondition condi .where( containTextCondition(condition.text()), eqUserId(condition.selectedUser()), + validateUserState(), validatePostDate() ) .offset(condition.pageable().getOffset()) @@ -124,6 +127,10 @@ private BooleanExpression containTextCondition(String text) { return hasText(text) ? post.title.contains(text) : null; } + private BooleanExpression validateUserState() { + return user.userState.eq(UserState.JOIN); + } + private BooleanExpression validatePostDate() { return post.endDate.after(LocalDate.now()); } From b426f79b58b3a81d77fb27daf594761518d54012 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Fri, 12 Jan 2024 00:02:20 +0900 Subject: [PATCH 14/19] =?UTF-8?q?[fix]=20#34=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20response=20header=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gachon/checkmate/domain/post/controller/PostController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java index f5848d1..2900d04 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java +++ b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java @@ -53,6 +53,6 @@ public ResponseEntity> getMyPosts(@UserId final Long userId, public ResponseEntity> createPost(@UserId final Long userId, @RequestBody @Valid final PostCreateRequestDto requestDto) { postService.createPost(userId, requestDto); - return SuccessResponse.ok(null); + return SuccessResponse.created(null); } } From 6dbb27d06828f4854a07f9c3181d2fcfa2541e71 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Fri, 12 Jan 2024 00:23:42 +0900 Subject: [PATCH 15/19] =?UTF-8?q?[fix]=20#34=20scrap=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20api=20userId=20=EC=A1=B0=EA=B1=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checkmate/domain/scrap/controller/ScrapController.java | 5 +++-- .../checkmate/domain/scrap/repository/ScrapRepository.java | 1 + .../gachon/checkmate/domain/scrap/service/ScrapService.java | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/controller/ScrapController.java b/src/main/java/org/gachon/checkmate/domain/scrap/controller/ScrapController.java index c2ca579..b317418 100644 --- a/src/main/java/org/gachon/checkmate/domain/scrap/controller/ScrapController.java +++ b/src/main/java/org/gachon/checkmate/domain/scrap/controller/ScrapController.java @@ -31,8 +31,9 @@ public ResponseEntity> createScrapPost(@UserId final Long use } @DeleteMapping("/{id}") - public ResponseEntity> deleteScrapPost(@PathVariable("id") final Long scrapId) { - scrapService.deleteScrapPost(scrapId); + public ResponseEntity> deleteScrapPost(@UserId final Long userId, + @PathVariable("id") final Long scrapId) { + scrapService.deleteScrapPost(userId, scrapId); return SuccessResponse.ok(null); } } diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java index b1e8a90..5b4cab4 100644 --- a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java +++ b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java @@ -4,4 +4,5 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface ScrapRepository extends JpaRepository, ScrapCustomRepository { + void deleteByIdAndUserId(Long scrapId, Long UserId); } diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/service/ScrapService.java b/src/main/java/org/gachon/checkmate/domain/scrap/service/ScrapService.java index 84e0460..e352f31 100644 --- a/src/main/java/org/gachon/checkmate/domain/scrap/service/ScrapService.java +++ b/src/main/java/org/gachon/checkmate/domain/scrap/service/ScrapService.java @@ -51,8 +51,8 @@ public void creatScrapPost(Long userId, ScrapRequestDto scrapRequestDto) { createScrapAndSave(user, post); } - public void deleteScrapPost(Long scrapId) { - scrapRepository.deleteById(scrapId); + public void deleteScrapPost(Long userId, Long scrapId) { + scrapRepository.deleteByIdAndUserId(scrapId, userId); } private List createPostSearchResponseDto(Page postSearchDtoList, CheckList checkList) { From da34e9c17a4a2b86005efb050b657839e7be2c72 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Fri, 12 Jan 2024 00:58:45 +0900 Subject: [PATCH 16/19] =?UTF-8?q?[fix]=20#34=20=EA=B0=9C=EC=9D=B8=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EB=AC=BC=20=EC=9E=91=EC=84=B1=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=97=90=EC=84=9C=20=EC=A7=80=EB=82=9C=20=EA=B2=8C?= =?UTF-8?q?=EC=8B=9C=EA=B8=80=20=EC=A1=B0=ED=9A=8C=20=EA=B0=80=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/repository/PostCustomRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java index e908b5f..5ce3002 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java +++ b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java @@ -96,7 +96,7 @@ public Page searchPostsWithPaging(PostPagingSearchCondition condi containTextCondition(condition.text()), eqUserId(condition.selectedUser()), validateUserState(), - validatePostDate() + condition.selectedUser() != null ? validatePostDate() : null ) .offset(condition.pageable().getOffset()) .limit(condition.pageable().getPageSize()) From ad56643f6c8a1364b34d989ebac097629c328ed8 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Fri, 12 Jan 2024 01:20:01 +0900 Subject: [PATCH 17/19] =?UTF-8?q?[fix]=20#34=20=EC=A7=80=EB=82=9C=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EC=A1=B0=ED=9A=8C=20=EA=B0=80?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PostCustomRepositoryImpl.java | 30 ++++++++++++------- .../repository/ScrapCustomRepositoryImpl.java | 21 +++++++------ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java index 5ce3002..942e065 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java +++ b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java @@ -12,7 +12,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.support.PageableExecutionUtils; -import java.time.LocalDate; import java.util.List; import java.util.Optional; @@ -65,13 +64,19 @@ public Page searchPosts(PostSearchCondition condition) { .where( eqImportantKey(condition.importantKeyType()), eqGenderType(condition.genderType()), - validateUserState(), - validatePostDate() + validateUserState() ) .fetch(); JPAQuery countQuery = queryFactory - .selectFrom(post); + .selectFrom(post) + .leftJoin(post.postCheckList, postCheckList) + .leftJoin(post.user, user) + .where( + eqImportantKey(condition.importantKeyType()), + eqGenderType(condition.genderType()), + validateUserState() + ); return PageableExecutionUtils.getPage(content, condition.pageable(), countQuery::fetchCount); } @@ -95,15 +100,22 @@ public Page searchPostsWithPaging(PostPagingSearchCondition condi .where( containTextCondition(condition.text()), eqUserId(condition.selectedUser()), - validateUserState(), - condition.selectedUser() != null ? validatePostDate() : null + validateUserState() ) .offset(condition.pageable().getOffset()) .limit(condition.pageable().getPageSize()) .fetch(); JPAQuery countQuery = queryFactory - .selectFrom(post); + .selectFrom(post) + .from(post) + .leftJoin(post.postCheckList, postCheckList) + .leftJoin(post.user, user) + .where( + containTextCondition(condition.text()), + eqUserId(condition.selectedUser()), + validateUserState() + ); return PageableExecutionUtils.getPage(content, condition.pageable(), countQuery::fetchCount); } @@ -130,8 +142,4 @@ private BooleanExpression containTextCondition(String text) { private BooleanExpression validateUserState() { return user.userState.eq(UserState.JOIN); } - - private BooleanExpression validatePostDate() { - return post.endDate.after(LocalDate.now()); - } } diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java index df925c3..513ca10 100644 --- a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java +++ b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java @@ -7,12 +7,11 @@ import org.gachon.checkmate.domain.member.entity.UserState; import org.gachon.checkmate.domain.post.dto.support.PostSearchDto; import org.gachon.checkmate.domain.post.dto.support.QPostSearchDto; -import org.gachon.checkmate.domain.post.entity.Post; import org.gachon.checkmate.domain.scrap.dto.support.ScrapSearchCondition; +import org.gachon.checkmate.domain.scrap.entity.Scrap; import org.springframework.data.domain.Page; import org.springframework.data.support.PageableExecutionUtils; -import java.time.LocalDate; import java.util.List; import static org.gachon.checkmate.domain.checkList.entity.QPostCheckList.postCheckList; @@ -44,15 +43,22 @@ public Page searchMyScrapPosts(ScrapSearchCondition condition) { .leftJoin(scrap.user, user) .where( eqUserId(condition.userId()), - validateUserState(), - validatePostDate() + validateUserState() ) .offset(condition.pageable().getOffset()) .limit(condition.pageable().getPageSize()) .fetch(); - JPAQuery countQuery = queryFactory - .selectFrom(post); + JPAQuery countQuery = queryFactory + .selectFrom(scrap) + .leftJoin(scrap.post, post) + .leftJoin(scrap.post.postCheckList, postCheckList) + .leftJoin(scrap.user, user) + .where( + eqUserId(condition.userId()), + validateUserState() + ); + return PageableExecutionUtils.getPage(content, condition.pageable(), countQuery::fetchCount); } @@ -64,7 +70,4 @@ private BooleanExpression validateUserState() { return user.userState.eq(UserState.JOIN); } - private BooleanExpression validatePostDate() { - return post.endDate.after(LocalDate.now()); - } } From a146fa146ac2a71a4be32f43eb9a61f9a5811199 Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Fri, 12 Jan 2024 01:31:51 +0900 Subject: [PATCH 18/19] =?UTF-8?q?[fix]=20#34=20post=20=EB=AA=A8=EC=A7=91?= =?UTF-8?q?=EC=A4=91,=20=EB=AA=A8=EC=A7=91=20=EC=99=84=EB=A3=8C=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=EA=B4=80=EB=A6=AC=20=EB=B0=8F=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/converter/PostStateConverter.java | 10 ++++++++++ .../response/PostSearchElementResponseDto.java | 4 +++- .../domain/post/dto/support/PostSearchDto.java | 7 +++++-- .../checkmate/domain/post/entity/Post.java | 3 +++ .../checkmate/domain/post/entity/PostState.java | 16 ++++++++++++++++ .../repository/PostCustomRepositoryImpl.java | 6 ++++-- .../repository/ScrapCustomRepositoryImpl.java | 3 ++- 7 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/gachon/checkmate/domain/post/converter/PostStateConverter.java create mode 100644 src/main/java/org/gachon/checkmate/domain/post/entity/PostState.java diff --git a/src/main/java/org/gachon/checkmate/domain/post/converter/PostStateConverter.java b/src/main/java/org/gachon/checkmate/domain/post/converter/PostStateConverter.java new file mode 100644 index 0000000..b95d093 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/post/converter/PostStateConverter.java @@ -0,0 +1,10 @@ +package org.gachon.checkmate.domain.post.converter; + +import org.gachon.checkmate.domain.post.entity.PostState; +import org.gachon.checkmate.global.utils.AbstractEnumCodeAttributeConverter; + +public class PostStateConverter extends AbstractEnumCodeAttributeConverter { + public PostStateConverter() { + super(PostState.class); + } +} diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostSearchElementResponseDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostSearchElementResponseDto.java index 20314e6..6bec711 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostSearchElementResponseDto.java +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostSearchElementResponseDto.java @@ -13,7 +13,8 @@ public record PostSearchElementResponseDto( int scrapCount, int remainDate, int accuracy, - String gender + String gender, + String postState ) { public static PostSearchElementResponseDto of(PostSearchDto postSearchDto, int remainDate, @@ -28,6 +29,7 @@ public static PostSearchElementResponseDto of(PostSearchDto postSearchDto, .remainDate(remainDate) .accuracy(accuracy) .gender(postSearchDto.genderType().getDesc()) + .postState(postSearchDto.postState().getDesc()) .build(); } } diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostSearchDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostSearchDto.java index 9c003e0..daebfa4 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostSearchDto.java +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostSearchDto.java @@ -4,6 +4,7 @@ import org.gachon.checkmate.domain.checkList.entity.PostCheckList; import org.gachon.checkmate.domain.member.entity.GenderType; import org.gachon.checkmate.domain.post.entity.ImportantKeyType; +import org.gachon.checkmate.domain.post.entity.PostState; import org.gachon.checkmate.domain.post.entity.SimilarityKeyType; import java.time.LocalDate; @@ -17,10 +18,11 @@ public record PostSearchDto( LocalDate endDate, int scrapCount, PostCheckList postCheckList, - GenderType genderType + GenderType genderType, + PostState postState ) { @QueryProjection - public PostSearchDto(Long postId, String title, String content, ImportantKeyType importantKey, SimilarityKeyType similarityKey, LocalDate endDate, int scrapCount, PostCheckList postCheckList, GenderType genderType) { + public PostSearchDto(Long postId, String title, String content, ImportantKeyType importantKey, SimilarityKeyType similarityKey, LocalDate endDate, int scrapCount, PostCheckList postCheckList, GenderType genderType, PostState postState) { this.postId = postId; this.title = title; this.content = content; @@ -30,5 +32,6 @@ public PostSearchDto(Long postId, String title, String content, ImportantKeyType this.scrapCount = scrapCount; this.postCheckList = postCheckList; this.genderType = genderType; + this.postState = postState; } } diff --git a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java index fb8f552..07518df 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java +++ b/src/main/java/org/gachon/checkmate/domain/post/entity/Post.java @@ -5,6 +5,7 @@ import org.gachon.checkmate.domain.checkList.entity.PostCheckList; import org.gachon.checkmate.domain.member.entity.User; import org.gachon.checkmate.domain.post.converter.ImportantKeyTypeConverter; +import org.gachon.checkmate.domain.post.converter.PostStateConverter; import org.gachon.checkmate.domain.post.converter.RoomTypeConverter; import org.gachon.checkmate.domain.post.converter.SimilarityKeyTypeConverter; import org.gachon.checkmate.domain.post.dto.request.PostCreateRequestDto; @@ -28,6 +29,8 @@ public class Post extends BaseTimeEntity { private String title; private String content; private LocalDate endDate; + @Convert(converter = PostStateConverter.class) + private PostState postState; @Convert(converter = RoomTypeConverter.class) private RoomType roomType; @Convert(converter = ImportantKeyTypeConverter.class) diff --git a/src/main/java/org/gachon/checkmate/domain/post/entity/PostState.java b/src/main/java/org/gachon/checkmate/domain/post/entity/PostState.java new file mode 100644 index 0000000..56adf09 --- /dev/null +++ b/src/main/java/org/gachon/checkmate/domain/post/entity/PostState.java @@ -0,0 +1,16 @@ +package org.gachon.checkmate.domain.post.entity; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.gachon.checkmate.global.utils.EnumField; + +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +public enum PostState implements EnumField { + RECRUITING("1", "모집중"), + COMPLETE("2", "모집완료"); + + private String code; + private String desc; +} diff --git a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java index 942e065..a219a0a 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java +++ b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java @@ -56,7 +56,8 @@ public Page searchPosts(PostSearchCondition condition) { post.endDate, post.scrapList.size(), postCheckList, - user.gender + user.gender, + post.postState )) .from(post) .leftJoin(post.postCheckList, postCheckList) @@ -92,7 +93,8 @@ public Page searchPostsWithPaging(PostPagingSearchCondition condi post.endDate, post.scrapList.size(), postCheckList, - user.gender + user.gender, + post.postState )) .from(post) .leftJoin(post.postCheckList, postCheckList) diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java index 513ca10..47799b8 100644 --- a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java +++ b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapCustomRepositoryImpl.java @@ -35,7 +35,8 @@ public Page searchMyScrapPosts(ScrapSearchCondition condition) { post.endDate, post.scrapList.size(), postCheckList, - user.gender + user.gender, + post.postState )) .from(scrap) .leftJoin(scrap.post, post) From 7a4d11e2b74ea3f55e23ce4e96bb5acfa03d093b Mon Sep 17 00:00:00 2001 From: RyuKwanKon Date: Fri, 12 Jan 2024 01:46:37 +0900 Subject: [PATCH 19/19] =?UTF-8?q?[fix]=20#34=20post=20=EC=83=81=EC=84=B8?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20scrap=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/post/controller/PostController.java | 5 +++-- .../post/dto/response/PostDetailResponseDto.java | 4 +++- .../checkmate/domain/post/service/PostService.java | 11 +++++++++-- .../domain/scrap/repository/ScrapRepository.java | 3 ++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java index 2900d04..eeb88fd 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java +++ b/src/main/java/org/gachon/checkmate/domain/post/controller/PostController.java @@ -29,8 +29,9 @@ public ResponseEntity> getAllPosts(@UserId final Long userId, } @GetMapping("/{id}") - public ResponseEntity> getPostDetails(@PathVariable("id") final Long postId) { - final PostDetailResponseDto responseDto = postService.getPostDetails(postId); + public ResponseEntity> getPostDetails(@UserId final Long userId, + @PathVariable("id") final Long postId) { + final PostDetailResponseDto responseDto = postService.getPostDetails(userId, postId); return SuccessResponse.ok(responseDto); } diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostDetailResponseDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostDetailResponseDto.java index be6166d..d6148f7 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostDetailResponseDto.java +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostDetailResponseDto.java @@ -11,15 +11,17 @@ public record PostDetailResponseDto( String profile, String gender, String mbti, + boolean isScrap, CheckListResponseDto checkList ) { - public static PostDetailResponseDto of(PostDetailDto postDetailDto, CheckListResponseDto checkList) { + public static PostDetailResponseDto of(PostDetailDto postDetailDto, CheckListResponseDto checkList, boolean isScrap) { return PostDetailResponseDto.builder() .name(postDetailDto.name()) .major(postDetailDto.major()) .profile(postDetailDto.profile()) .gender(postDetailDto.gender().getDesc()) .mbti(postDetailDto.mbti().getDesc()) + .isScrap(isScrap) .checkList(checkList) .build(); } diff --git a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java index 70bf4df..831bcef 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java +++ b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java @@ -20,6 +20,7 @@ import org.gachon.checkmate.domain.post.entity.Post; import org.gachon.checkmate.domain.post.entity.SortType; import org.gachon.checkmate.domain.post.repository.PostRepository; +import org.gachon.checkmate.domain.scrap.repository.ScrapRepository; import org.gachon.checkmate.global.error.exception.EntityNotFoundException; import org.gachon.checkmate.global.error.exception.InvalidValueException; import org.springframework.data.domain.Page; @@ -45,6 +46,7 @@ public class PostService { private final CheckListRepository checkListRepository; private final PostRepository postRepository; private final PostCheckListRepository postCheckListRepository; + private final ScrapRepository scrapRepository; public void createPost(Long userId, PostCreateRequestDto requestDto) { validateDuplicateTitle(requestDto.title()); @@ -73,10 +75,11 @@ public PostSearchResponseDto getAllPosts(Long userId, String key, String type, S return PostSearchResponseDto.of(pagingSearchResults, postSearchList.getTotalPages(), postSearchList.getTotalElements()); } - public PostDetailResponseDto getPostDetails(Long postId) { + public PostDetailResponseDto getPostDetails(Long userId, Long postId) { PostDetailDto postDetailDto = getPostDetailDto(postId); CheckListResponseDto checkListResponseDto = createCheckListResponseDto(postDetailDto.postCheckList()); - return PostDetailResponseDto.of(postDetailDto, checkListResponseDto); + boolean isScrapPost = existPostInScrap(postId, userId); + return PostDetailResponseDto.of(postDetailDto, checkListResponseDto, isScrapPost); } public PostSearchResponseDto searchTextPost(Long userId, String text, Pageable pageable) { @@ -186,4 +189,8 @@ private User getUserOrThrow(Long userId) { return userRepository.findById(userId) .orElseThrow(() -> new EntityNotFoundException(USER_NOT_FOUND)); } + + private boolean existPostInScrap(Long postId, Long userId) { + return scrapRepository.existsByPostIdAndUserId(postId, userId); + } } diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java index 5b4cab4..f413ab9 100644 --- a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java +++ b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java @@ -4,5 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface ScrapRepository extends JpaRepository, ScrapCustomRepository { - void deleteByIdAndUserId(Long scrapId, Long UserId); + void deleteByIdAndUserId(Long scrapId, Long userId); + boolean existsByPostIdAndUserId(Long postId, Long userId); }