From 9d065423f12dcc7e56d0301e39abbe7b03daeff6 Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Tue, 14 Nov 2023 23:52:51 +0900 Subject: [PATCH 1/8] =?UTF-8?q?fix=20:=20=EC=A2=8B=EC=95=84=EC=9A=94=20?= =?UTF-8?q?=EB=A6=AC=ED=84=B4=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../heart/presentation/HeartController.java | 4 +++- .../constant/HeartCommunityResponse.java | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/main/java/gwangjang/server/domain/heart/presentation/constant/HeartCommunityResponse.java diff --git a/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java b/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java index 7ddc7d5..45a8776 100644 --- a/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java +++ b/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java @@ -12,6 +12,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import static gwangjang.server.domain.heart.presentation.constant.HeartCommunityResponse.PUSH_HEART_SUCCESS; + @RestController @AllArgsConstructor @RequestMapping("/contents/{contentsId}/community/{communityId}/heart") @@ -23,7 +25,7 @@ public class HeartController { public ResponseEntity> pushHeart(@RequestHeader(value = "user-id") String socialId, @PathVariable("contentsId") Long contentsId, @PathVariable("communityId") Long communityId, @PathVariable("heartStatus") String heartStatus) { - return ResponseEntity.ok(SuccessResponse.create(CommentResponseMessage.CREATE_COMMENT_SUCCESS.getMessage(), this.heartUpdateUseCase.pushHeart(socialId, communityId,heartStatus))); + return ResponseEntity.ok(SuccessResponse.create(PUSH_HEART_SUCCESS.getMessage(), this.heartUpdateUseCase.pushHeart(socialId, communityId,heartStatus))); } } diff --git a/src/main/java/gwangjang/server/domain/heart/presentation/constant/HeartCommunityResponse.java b/src/main/java/gwangjang/server/domain/heart/presentation/constant/HeartCommunityResponse.java new file mode 100644 index 0000000..a8fac69 --- /dev/null +++ b/src/main/java/gwangjang/server/domain/heart/presentation/constant/HeartCommunityResponse.java @@ -0,0 +1,16 @@ +package gwangjang.server.domain.heart.presentation.constant; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum HeartCommunityResponse { + + + PUSH_HEART_SUCCESS("게시글 좋아요/취소 를 완료 했습니다."), + GET_COMMUNITY_SUCCESS("커뮤니티 글 조회를 완료 했습니다"); + + private final String message; + +} From 40b18965109611cc62e85235d4c75933cbfd7a34 Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Wed, 15 Nov 2023 00:23:05 +0900 Subject: [PATCH 2/8] =?UTF-8?q?fix=20:=20=EB=8C=93=EA=B8=80=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=ED=9B=84=20=EB=AA=A8=EB=93=A0=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EB=A6=AC=ED=84=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/service/CommentCreateUseCase.java | 9 +++++++-- .../domain/comment/presentation/CommentController.java | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/gwangjang/server/domain/comment/application/service/CommentCreateUseCase.java b/src/main/java/gwangjang/server/domain/comment/application/service/CommentCreateUseCase.java index c4e8c6a..70f4881 100644 --- a/src/main/java/gwangjang/server/domain/comment/application/service/CommentCreateUseCase.java +++ b/src/main/java/gwangjang/server/domain/comment/application/service/CommentCreateUseCase.java @@ -4,6 +4,7 @@ import gwangjang.server.domain.comment.application.dto.res.CommentRes; import gwangjang.server.domain.comment.application.mapper.CommentMapper; import gwangjang.server.domain.comment.domain.entity.Comment; +import gwangjang.server.domain.comment.domain.service.CommentQueryService; import gwangjang.server.domain.comment.domain.service.CommentSaveService; import gwangjang.server.domain.community.application.dto.res.MemberDto; import gwangjang.server.domain.community.domain.entity.Community; @@ -13,12 +14,15 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; + @Service @Transactional @RequiredArgsConstructor public class CommentCreateUseCase { private final CommentSaveService commentSaveService; + private final CommentQueryService commentQueryService; private final CommunityQueryService communityQueryService; @@ -27,14 +31,15 @@ public class CommentCreateUseCase { private final CommentMapper commentMapper = new CommentMapper(); - public CommentRes create(String socialId, Long communityId, CommentReq commentReq) { + public List create(String socialId, Long communityId, CommentReq commentReq) { MemberDto memberDto = findMemberFeignClient.getMemberBySocialId(socialId); Community community = communityQueryService.getCommunityById(communityId); Comment comment = commentSaveService.save(commentMapper.mapToComment(socialId, community, commentReq)); - return commentMapper.mapToCommentRes(memberDto, comment); + return commentQueryService.getCommentsByCommunityId(communityId); +// return commentMapper.mapToCommentRes(memberDto, comment); } } diff --git a/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java b/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java index 99c5622..f4f4118 100644 --- a/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java +++ b/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java @@ -27,7 +27,7 @@ public class CommentController { private final CommentReadUseCase commentReadUseCase; @PostMapping - public ResponseEntity> createComment(@RequestHeader(value = "user-id") String socialId, + public ResponseEntity>> createComment(@RequestHeader(value = "user-id") String socialId, @PathVariable("contentsId") Long contentsId,@PathVariable("communityId") Long communityId, @RequestBody CommentReq commentReq) { return ResponseEntity.ok(SuccessResponse.create(CommentResponseMessage.CREATE_COMMENT_SUCCESS.getMessage(), this.commentCreateUseCase.create(socialId, communityId, commentReq))); } From 095692eb26dcfddb1ffd74987859df264e2dabdf Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Wed, 15 Nov 2023 00:30:32 +0900 Subject: [PATCH 3/8] chore : update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d7b49d3..ab9b73f 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,4 @@ out/ .vscode/ application.yml -src/main/generated/ +generated \ No newline at end of file From 2e9cb15257bb82a94b6c27a765c8f9a8d42c1d49 Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Wed, 15 Nov 2023 00:44:40 +0900 Subject: [PATCH 4/8] =?UTF-8?q?fix=20:=20=EB=8C=93=EA=B8=80=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=ED=9B=84=20=EC=A0=84=EC=B2=B4=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EB=A6=AC=ED=84=B4=20#4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + build.gradle | 2 +- .../comment/application/service/CommentCreateUseCase.java | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ab9b73f..21f6c01 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ out/ .vscode/ application.yml +src/main/generated/ generated \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6673975..12aa435 100644 --- a/build.gradle +++ b/build.gradle @@ -90,7 +90,7 @@ bootJar{ archiveVersion = "0.0.1" } -def generated = 'src/main/generated' +def generated = 'src/main/generated/querydsl' tasks.withType(JavaCompile) { options.getGeneratedSourceOutputDirectory().set(file(generated)) diff --git a/src/main/java/gwangjang/server/domain/comment/application/service/CommentCreateUseCase.java b/src/main/java/gwangjang/server/domain/comment/application/service/CommentCreateUseCase.java index e6fa3fd..9c13c54 100644 --- a/src/main/java/gwangjang/server/domain/comment/application/service/CommentCreateUseCase.java +++ b/src/main/java/gwangjang/server/domain/comment/application/service/CommentCreateUseCase.java @@ -24,6 +24,7 @@ public class CommentCreateUseCase { private final CommentSaveService commentSaveService; private final CommentQueryService commentQueryService; private final CommunityQueryService communityQueryService; + private final CommentReadUseCase commentReadUseCase; private final FindMemberFeignClient findMemberFeignClient; @@ -39,7 +40,7 @@ public List create(String socialId, Long communityId, CommentReq com Comment comment = commentSaveService.save(commentMapper.mapToComment(socialId, community, commentReq)); community.updateComments(comment); - return commentQueryService.getCommentsByCommunityId(communityId); + return commentReadUseCase.getCommentsByCommunity(communityId); // return commentMapper.mapToCommentRes(memberDto, comment); } From 7290a8963b0b0e319609260a6afed7c7773b5899 Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Wed, 15 Nov 2023 02:01:39 +0900 Subject: [PATCH 5/8] =?UTF-8?q?fix=20:=20=EC=BB=A4=EB=AE=A4=EB=8B=88?= =?UTF-8?q?=ED=8B=B0=20=EC=A1=B0=ED=9A=8C,=20=EB=8C=93=EA=B8=80,=20?= =?UTF-8?q?=EC=A2=8B=EC=95=84=EC=9A=94=20=20url=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/presentation/CommentController.java | 6 +++--- .../server/domain/heart/presentation/HeartController.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java b/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java index f4f4118..03a6956 100644 --- a/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java +++ b/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java @@ -20,7 +20,7 @@ @RestController @AllArgsConstructor -@RequestMapping("/contents/{contentsId}/community/{communityId}/comments") +@RequestMapping("/domain/{domain}/community/{communityId}/comments") public class CommentController { private final CommentCreateUseCase commentCreateUseCase; @@ -28,13 +28,13 @@ public class CommentController { @PostMapping public ResponseEntity>> createComment(@RequestHeader(value = "user-id") String socialId, - @PathVariable("contentsId") Long contentsId,@PathVariable("communityId") Long communityId, @RequestBody CommentReq commentReq) { + @PathVariable("domain") String domain,@PathVariable("communityId") Long communityId, @RequestBody CommentReq commentReq) { return ResponseEntity.ok(SuccessResponse.create(CommentResponseMessage.CREATE_COMMENT_SUCCESS.getMessage(), this.commentCreateUseCase.create(socialId, communityId, commentReq))); } @GetMapping public ResponseEntity>> getComments(@RequestHeader(value = "user-id") String socialId, - @PathVariable("contentsId") Long contentsId,@PathVariable("communityId") Long communityId) { + @PathVariable("domain") String domain,@PathVariable("communityId") Long communityId) { return ResponseEntity.ok(SuccessResponse.create(CommentResponseMessage.GET_COMMENT_SUCCESS.getMessage(), this.commentReadUseCase.getCommentsByCommunity(communityId))); } } diff --git a/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java b/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java index 45a8776..ad783f4 100644 --- a/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java +++ b/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java @@ -16,14 +16,14 @@ @RestController @AllArgsConstructor -@RequestMapping("/contents/{contentsId}/community/{communityId}/heart") +@RequestMapping("/domain/{domain}/community/{communityId}/heart") public class HeartController { private final HeartUpdateUseCase heartUpdateUseCase; @PutMapping("/{heartStatus}") public ResponseEntity> pushHeart(@RequestHeader(value = "user-id") String socialId, - @PathVariable("contentsId") Long contentsId, @PathVariable("communityId") Long communityId, + @PathVariable("domain") String domain, @PathVariable("communityId") Long communityId, @PathVariable("heartStatus") String heartStatus) { return ResponseEntity.ok(SuccessResponse.create(PUSH_HEART_SUCCESS.getMessage(), this.heartUpdateUseCase.pushHeart(socialId, communityId,heartStatus))); } From 205ffd47343d6d790ff4a1080fac2daa14fac3a9 Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Wed, 15 Nov 2023 03:08:03 +0900 Subject: [PATCH 6/8] =?UTF-8?q?fix=20:=20=EC=98=81=EC=97=AD=20[domain=20->?= =?UTF-8?q?=20topic]=20=ED=82=A4=EC=9B=8C=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/presentation/CommentController.java | 6 +++--- .../application/dto/res/ContentsDto.java | 2 +- .../application/mapper/CommunityMapper.java | 4 ++-- .../community/domain/entity/Community.java | 2 +- .../presentation/CommunityController.java | 16 ++++++++-------- .../heart/presentation/HeartController.java | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java b/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java index 03a6956..3d277af 100644 --- a/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java +++ b/src/main/java/gwangjang/server/domain/comment/presentation/CommentController.java @@ -20,7 +20,7 @@ @RestController @AllArgsConstructor -@RequestMapping("/domain/{domain}/community/{communityId}/comments") +@RequestMapping("/topic/{topic}/community/{communityId}/comments") public class CommentController { private final CommentCreateUseCase commentCreateUseCase; @@ -28,13 +28,13 @@ public class CommentController { @PostMapping public ResponseEntity>> createComment(@RequestHeader(value = "user-id") String socialId, - @PathVariable("domain") String domain,@PathVariable("communityId") Long communityId, @RequestBody CommentReq commentReq) { + @PathVariable("topic") String topic,@PathVariable("communityId") Long communityId, @RequestBody CommentReq commentReq) { return ResponseEntity.ok(SuccessResponse.create(CommentResponseMessage.CREATE_COMMENT_SUCCESS.getMessage(), this.commentCreateUseCase.create(socialId, communityId, commentReq))); } @GetMapping public ResponseEntity>> getComments(@RequestHeader(value = "user-id") String socialId, - @PathVariable("domain") String domain,@PathVariable("communityId") Long communityId) { + @PathVariable("topic") String topic,@PathVariable("communityId") Long communityId) { return ResponseEntity.ok(SuccessResponse.create(CommentResponseMessage.GET_COMMENT_SUCCESS.getMessage(), this.commentReadUseCase.getCommentsByCommunity(communityId))); } } diff --git a/src/main/java/gwangjang/server/domain/community/application/dto/res/ContentsDto.java b/src/main/java/gwangjang/server/domain/community/application/dto/res/ContentsDto.java index 62cd039..a46314c 100644 --- a/src/main/java/gwangjang/server/domain/community/application/dto/res/ContentsDto.java +++ b/src/main/java/gwangjang/server/domain/community/application/dto/res/ContentsDto.java @@ -14,6 +14,6 @@ public class ContentsDto { private String keyword; private String issue; - private String domain; + private String topic; } diff --git a/src/main/java/gwangjang/server/domain/community/application/mapper/CommunityMapper.java b/src/main/java/gwangjang/server/domain/community/application/mapper/CommunityMapper.java index 86f9d72..7166bba 100644 --- a/src/main/java/gwangjang/server/domain/community/application/mapper/CommunityMapper.java +++ b/src/main/java/gwangjang/server/domain/community/application/mapper/CommunityMapper.java @@ -19,7 +19,7 @@ public Community mapToCommunity(String memberId, ContentsDto contentsDto, Commun .writerId(memberId) .keyword(contentsDto.getKeyword()) .issue(contentsDto.getIssue()) - .domain(contentsDto.getDomain()) + .topic(contentsDto.getTopic()) .build(); } @@ -35,7 +35,7 @@ public CommunityRes mapToCommunityRes(Community community, MemberDto memberDto, .keyword(contentsDto.getKeyword()) .issue(contentsDto.getIssue()) - .domain(contentsDto.getDomain()) + .domain(contentsDto.getTopic()) .build(); } diff --git a/src/main/java/gwangjang/server/domain/community/domain/entity/Community.java b/src/main/java/gwangjang/server/domain/community/domain/entity/Community.java index 6c698a9..706a901 100644 --- a/src/main/java/gwangjang/server/domain/community/domain/entity/Community.java +++ b/src/main/java/gwangjang/server/domain/community/domain/entity/Community.java @@ -33,7 +33,7 @@ public class Community extends BaseEntity { private String keyword; //변하지 않음, contentsId로 가져오기 private String issue; //변하지 않음 , contentsId로 가져오기 - private String domain; //변하지 않음, contentsId로 가져오기 + private String topic; //변하지 않음, contentsId로 가져오기 @OneToMany(fetch = FetchType.LAZY) List comments = new ArrayList<>(); diff --git a/src/main/java/gwangjang/server/domain/community/presentation/CommunityController.java b/src/main/java/gwangjang/server/domain/community/presentation/CommunityController.java index bdd2623..cbf2fd0 100644 --- a/src/main/java/gwangjang/server/domain/community/presentation/CommunityController.java +++ b/src/main/java/gwangjang/server/domain/community/presentation/CommunityController.java @@ -46,22 +46,22 @@ public ResponseEntity>> getCommunityList() { /** * 커뮤니티 글 리스트업(영역별) - * @param domain 영역 정보 + * @param topic 영역 정보 * @return */ - @GetMapping("/domain/{domain}") - public ResponseEntity>> getCommunityListByDomain(@PathVariable String domain) { - return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityList(domain))); + @GetMapping("/topic/{topic}") + public ResponseEntity>> getCommunityListByDomain(@PathVariable String topic) { + return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityList(topic))); } /** * 커뮤니티 글 리스트텁(상세) - * @param domain 영역 정보 + * @param topic 영역 정보 * @return */ - @GetMapping("/domain/{domain}/community/{communityId}") - public ResponseEntity> getCommunityDetail(@PathVariable("domain") String domain, @PathVariable("communityId") Long communityId) { - return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityDetail(domain,communityId))); + @GetMapping("/topic/{topic}/community/{communityId}") + public ResponseEntity> getCommunityDetail(@PathVariable("topic") String topic, @PathVariable("communityId") Long communityId) { + return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityDetail(topic,communityId))); } diff --git a/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java b/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java index ad783f4..a9ccf3a 100644 --- a/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java +++ b/src/main/java/gwangjang/server/domain/heart/presentation/HeartController.java @@ -16,14 +16,14 @@ @RestController @AllArgsConstructor -@RequestMapping("/domain/{domain}/community/{communityId}/heart") +@RequestMapping("/topic/{topic}/community/{communityId}/heart") public class HeartController { private final HeartUpdateUseCase heartUpdateUseCase; @PutMapping("/{heartStatus}") public ResponseEntity> pushHeart(@RequestHeader(value = "user-id") String socialId, - @PathVariable("domain") String domain, @PathVariable("communityId") Long communityId, + @PathVariable("topic") String topic, @PathVariable("communityId") Long communityId, @PathVariable("heartStatus") String heartStatus) { return ResponseEntity.ok(SuccessResponse.create(PUSH_HEART_SUCCESS.getMessage(), this.heartUpdateUseCase.pushHeart(socialId, communityId,heartStatus))); } From 839b135366d817b0dfe8406689b8f8cb2bb7b65a Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Wed, 15 Nov 2023 04:22:47 +0900 Subject: [PATCH 7/8] =?UTF-8?q?feat=20:=20=EC=98=81=EC=97=AD/=EC=A3=BC?= =?UTF-8?q?=EC=A0=9C/=ED=82=A4=EC=9B=8C=EB=93=9C=20=EB=B3=84=20top=205=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dto/res/CommunityRes.java | 12 ++-- .../application/mapper/CommunityMapper.java | 4 +- .../service/CommunityReadUseCase.java | 9 +-- .../constant/CommunityOrderCondition.java | 11 ++++ .../repository/CommunityCustomRepository.java | 7 ++- .../repository/CommunityRepositoryImpl.java | 56 +++++++++++++++++-- .../domain/service/CommunityQueryService.java | 13 +++-- .../presentation/CommunityController.java | 13 ++++- 8 files changed, 100 insertions(+), 25 deletions(-) create mode 100644 src/main/java/gwangjang/server/domain/community/domain/entity/constant/CommunityOrderCondition.java diff --git a/src/main/java/gwangjang/server/domain/community/application/dto/res/CommunityRes.java b/src/main/java/gwangjang/server/domain/community/application/dto/res/CommunityRes.java index e8b89a6..b99ba3e 100644 --- a/src/main/java/gwangjang/server/domain/community/application/dto/res/CommunityRes.java +++ b/src/main/java/gwangjang/server/domain/community/application/dto/res/CommunityRes.java @@ -14,27 +14,27 @@ public class CommunityRes { private Long id; private String title; private String talk; - private String createdAt; + private String date; private String writerId; private String nickname; private String profileImg; - private String domain; + private String topic; private String issue; private String keyword; private Long heartsNum; private Long commentsNum; - public CommunityRes(Long id, String title,String talk, LocalDateTime createdAt, String writerId, - String domain, String issue, String keyword, Long heartsNum, Long commentsNum) { + public CommunityRes(Long id, String title, String talk, LocalDateTime date, String writerId, + String topic, String issue, String keyword, Long heartsNum, Long commentsNum) { this.id = id; this.title = title; this.talk = talk; - this.createdAt = createdAt.toString(); + this.date = date.toString(); this.writerId = writerId; - this.domain = domain; + this.topic = topic; this.issue = issue; this.keyword = keyword; this.heartsNum = heartsNum; diff --git a/src/main/java/gwangjang/server/domain/community/application/mapper/CommunityMapper.java b/src/main/java/gwangjang/server/domain/community/application/mapper/CommunityMapper.java index 7166bba..b6ebf31 100644 --- a/src/main/java/gwangjang/server/domain/community/application/mapper/CommunityMapper.java +++ b/src/main/java/gwangjang/server/domain/community/application/mapper/CommunityMapper.java @@ -28,14 +28,14 @@ public CommunityRes mapToCommunityRes(Community community, MemberDto memberDto, .id(community.getId()) .title(community.getTitle()) .talk(community.getTalk()) - .createdAt(community.getCreatedAt().toString()) + .date(community.getCreatedAt().toString()) .writerId(memberDto.getMemberId()) .nickname(memberDto.getNickname()) .profileImg(memberDto.getProfileImage()) .keyword(contentsDto.getKeyword()) .issue(contentsDto.getIssue()) - .domain(contentsDto.getTopic()) + .topic(contentsDto.getTopic()) .build(); } diff --git a/src/main/java/gwangjang/server/domain/community/application/service/CommunityReadUseCase.java b/src/main/java/gwangjang/server/domain/community/application/service/CommunityReadUseCase.java index 0dc9f4a..4828be5 100644 --- a/src/main/java/gwangjang/server/domain/community/application/service/CommunityReadUseCase.java +++ b/src/main/java/gwangjang/server/domain/community/application/service/CommunityReadUseCase.java @@ -2,6 +2,7 @@ import gwangjang.server.domain.community.application.dto.res.CommunityRes; +import gwangjang.server.domain.community.domain.entity.constant.CommunityOrderCondition; import gwangjang.server.domain.community.domain.service.CommunityQueryService; import gwangjang.server.global.annotation.DomainService; import lombok.RequiredArgsConstructor; @@ -17,10 +18,10 @@ public class CommunityReadUseCase { // private final DomainGetService domainGetService; - public List getCommunityList(String domain) { + public List getCommunityList(String topic) { // domainGetService.getDomainByName(domain) - return communityQueryService.getAllCommunityByDomain(domain); + return communityQueryService.getAllCommunityByTopic(topic); } public List getAllCommunityList() { // domainGetService.getDomainByName(domain) @@ -32,8 +33,8 @@ public CommunityRes getCommunityDetail(String domain,Long communityId) { return communityQueryService.getCommunity(communityId); } - public List getCommunityTop5ByHeartsAndDomain(String domain) { + public List getCommunityTop5ByHearts(String orderBy, String word) { - return communityQueryService.getCommunityTop5ByHeartsAndDomain(domain); + return communityQueryService.getCommunityTop5(CommunityOrderCondition.valueOf(orderBy), word); } } diff --git a/src/main/java/gwangjang/server/domain/community/domain/entity/constant/CommunityOrderCondition.java b/src/main/java/gwangjang/server/domain/community/domain/entity/constant/CommunityOrderCondition.java new file mode 100644 index 0000000..932afda --- /dev/null +++ b/src/main/java/gwangjang/server/domain/community/domain/entity/constant/CommunityOrderCondition.java @@ -0,0 +1,11 @@ +package gwangjang.server.domain.community.domain.entity.constant; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum CommunityOrderCondition { + TOPIC("topic"),ISSUE("issue"), KEYWORD("keyword"); + private final String name; +} diff --git a/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityCustomRepository.java b/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityCustomRepository.java index 32d5992..ffacbf5 100644 --- a/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityCustomRepository.java +++ b/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityCustomRepository.java @@ -1,6 +1,7 @@ package gwangjang.server.domain.community.domain.repository; import gwangjang.server.domain.community.application.dto.res.CommunityRes; +import gwangjang.server.domain.community.domain.entity.constant.CommunityOrderCondition; import java.util.List; import java.util.Optional; @@ -8,9 +9,11 @@ public interface CommunityCustomRepository { - Optional> findAllCommunityByDomain(String domain); + Optional> findAllCommunityByTopic(String topic); Optional> findAllCommunity(); Optional findCommunity(Long communityId); - Optional> findCommunityTop5ByHeartsAndDomain(String domain); + Optional> findCommunityTop5ByHeartsAndTopic(String topic); + + Optional> findCommunityTop5(CommunityOrderCondition orderCondition, String word); } diff --git a/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityRepositoryImpl.java b/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityRepositoryImpl.java index 535fba3..83fbf16 100644 --- a/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityRepositoryImpl.java +++ b/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityRepositoryImpl.java @@ -1,11 +1,16 @@ package gwangjang.server.domain.community.domain.repository; +import com.querydsl.core.types.Order; +import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.impl.JPAQueryFactory; import gwangjang.server.domain.community.application.dto.res.CommunityRes; +import gwangjang.server.domain.community.domain.entity.constant.CommunityOrderCondition; import jakarta.persistence.EntityManager; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -21,7 +26,7 @@ public CommunityRepositoryImpl(EntityManager em) { @Override - public Optional> findAllCommunityByDomain(String domain) { + public Optional> findAllCommunityByTopic(String topic) { return Optional.ofNullable( queryFactory .select(Projections.constructor(CommunityRes.class, @@ -30,14 +35,14 @@ public Optional> findAllCommunityByDomain(String domain) { community.talk, community.createdAt, community.writerId, - community.domain, + community.topic, community.issue, community.keyword, community.hearts.size().longValue(), community.comments.size().longValue() )) .from(community) - .where(community.domain.eq(domain)) + .where(community.topic.eq(topic)) .orderBy(community.createdAt.desc()) .fetch() ); @@ -52,7 +57,7 @@ public Optional> findAllCommunity() { community.talk, community.createdAt, community.writerId, - community.domain, + community.topic, community.issue, community.keyword, community.hearts.size().longValue(), @@ -74,7 +79,7 @@ public Optional findCommunity(Long communityId) { community.talk, community.createdAt, community.writerId, - community.domain, + community.topic, community.issue, community.keyword, community.hearts.size().longValue(), @@ -87,9 +92,48 @@ public Optional findCommunity(Long communityId) { } @Override - public Optional> findCommunityTop5ByHeartsAndDomain(String domain) { + public Optional> findCommunityTop5ByHeartsAndTopic(String topic) { return Optional.empty(); } + @Override + public Optional> findCommunityTop5(CommunityOrderCondition orderCondition, String word) { + + return Optional.ofNullable(queryFactory + .select(Projections.constructor(CommunityRes.class, + community.id, + community.title, + community.talk, + community.createdAt, + community.writerId, + community.topic, + community.issue, + community.keyword, + community.hearts.size().longValue(), + community.comments.size().longValue() + )) + .from(community) + .where( + orderByColumn(orderCondition,word) + + ).orderBy(community.hearts.size().desc()) // hearts의 크기에 따라 내림차순 정렬 + .limit(5) // 상위 5개 결과만 선택 + .fetch()); + + + } + + + private BooleanExpression orderByColumn(CommunityOrderCondition orderCondition, String word) { + if (orderCondition.equals(CommunityOrderCondition.KEYWORD)) { + return community.keyword.eq(word); + } else if (orderCondition.equals(CommunityOrderCondition.ISSUE)) { + return community.issue.eq(word); + } else{ + return community.topic.eq(word); + } + } + + } diff --git a/src/main/java/gwangjang/server/domain/community/domain/service/CommunityQueryService.java b/src/main/java/gwangjang/server/domain/community/domain/service/CommunityQueryService.java index 2cae0fe..e674929 100644 --- a/src/main/java/gwangjang/server/domain/community/domain/service/CommunityQueryService.java +++ b/src/main/java/gwangjang/server/domain/community/domain/service/CommunityQueryService.java @@ -4,6 +4,7 @@ import gwangjang.server.domain.community.application.dto.res.MemberDto; import gwangjang.server.domain.community.application.mapper.CommunityMapper; import gwangjang.server.domain.community.domain.entity.Community; +import gwangjang.server.domain.community.domain.entity.constant.CommunityOrderCondition; import gwangjang.server.domain.community.domain.repository.CommunityRepository; import gwangjang.server.domain.community.exception.NotFoundCommunityException; import gwangjang.server.global.feign.client.FindMemberFeignClient; @@ -25,8 +26,8 @@ public Community getCommunityById(Long communityId) { return communityRepository.findById(communityId).orElseThrow(NotFoundCommunityException::new ); } - public List getAllCommunityByDomain(String domain) { - List communityRes = communityRepository.findAllCommunityByDomain(domain).orElseThrow(NotFoundCommunityException::new); + public List getAllCommunityByTopic(String topic) { + List communityRes = communityRepository.findAllCommunityByTopic(topic).orElseThrow(NotFoundCommunityException::new); communityRes.stream().forEach( communityRes1 -> { @@ -57,7 +58,11 @@ public CommunityRes getCommunity(Long communityId) { return communityRepository.findCommunity(communityId).orElseThrow(NotFoundCommunityException::new); } - public List getCommunityTop5ByHeartsAndDomain(String domain) { - return communityRepository.findCommunityTop5ByHeartsAndDomain(domain).orElseThrow(NotFoundCommunityException::new); + public List getCommunityTop5ByHeartsAndTopic(String topic) { + return communityRepository.findCommunityTop5ByHeartsAndTopic(topic).orElseThrow(NotFoundCommunityException::new); + } + + public List getCommunityTop5(CommunityOrderCondition communityOrderCondition, String with) { + return communityRepository.findCommunityTop5(communityOrderCondition, with).orElseThrow(NotFoundCommunityException::new); } } diff --git a/src/main/java/gwangjang/server/domain/community/presentation/CommunityController.java b/src/main/java/gwangjang/server/domain/community/presentation/CommunityController.java index cbf2fd0..07fa797 100644 --- a/src/main/java/gwangjang/server/domain/community/presentation/CommunityController.java +++ b/src/main/java/gwangjang/server/domain/community/presentation/CommunityController.java @@ -50,7 +50,7 @@ public ResponseEntity>> getCommunityList() { * @return */ @GetMapping("/topic/{topic}") - public ResponseEntity>> getCommunityListByDomain(@PathVariable String topic) { + public ResponseEntity>> getCommunityListByDomain(@PathVariable("topic") String topic) { return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityList(topic))); } @@ -64,6 +64,17 @@ public ResponseEntity> getCommunityDetail(@PathVar return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityDetail(topic,communityId))); } + /** + * 커뮤니티 글 top5(영역/주제/키워드) + * @param sortBy 정렬 조건 + * @param word 정렬 단어 + * @return + */ + @GetMapping("/sortBy/{sortBy}/word/{word}") + public ResponseEntity>> getCommunityTop5(@PathVariable("sortBy") String sortBy,@PathVariable("word") String word ) { + return ResponseEntity.ok(SuccessResponse.create(CommunityResponseMessage.GET_COMMUNITY_SUCCESS.getMessage(), this.communityReadUseCase.getCommunityTop5ByHearts(sortBy,word))); + } + } From 88bde29d0bf0367cb2ced98f4a959903eb656bac Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Wed, 15 Nov 2023 04:34:44 +0900 Subject: [PATCH 8/8] =?UTF-8?q?feat=20:=20=EC=BB=A4=EB=AE=A4=EB=8B=88?= =?UTF-8?q?=ED=8B=B0=20=EC=A0=84=EC=B2=B4=20top=205=20&=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EB=8B=89=EB=84=A4=EC=9E=84/=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EB=A6=AC=ED=84=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/constant/CommunityOrderCondition.java | 2 +- .../domain/repository/CommunityRepositoryImpl.java | 2 ++ .../domain/service/CommunityQueryService.java | 13 ++++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/gwangjang/server/domain/community/domain/entity/constant/CommunityOrderCondition.java b/src/main/java/gwangjang/server/domain/community/domain/entity/constant/CommunityOrderCondition.java index 932afda..8dfae1a 100644 --- a/src/main/java/gwangjang/server/domain/community/domain/entity/constant/CommunityOrderCondition.java +++ b/src/main/java/gwangjang/server/domain/community/domain/entity/constant/CommunityOrderCondition.java @@ -6,6 +6,6 @@ @Getter @RequiredArgsConstructor public enum CommunityOrderCondition { - TOPIC("topic"),ISSUE("issue"), KEYWORD("keyword"); + TOPIC("topic"),ISSUE("issue"), KEYWORD("keyword"),ALL("all"); private final String name; } diff --git a/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityRepositoryImpl.java b/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityRepositoryImpl.java index 83fbf16..ea6a112 100644 --- a/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityRepositoryImpl.java +++ b/src/main/java/gwangjang/server/domain/community/domain/repository/CommunityRepositoryImpl.java @@ -130,6 +130,8 @@ private BooleanExpression orderByColumn(CommunityOrderCondition orderCondition, return community.keyword.eq(word); } else if (orderCondition.equals(CommunityOrderCondition.ISSUE)) { return community.issue.eq(word); + } else if (orderCondition.equals(CommunityOrderCondition.ALL)) { + return null; } else{ return community.topic.eq(word); } diff --git a/src/main/java/gwangjang/server/domain/community/domain/service/CommunityQueryService.java b/src/main/java/gwangjang/server/domain/community/domain/service/CommunityQueryService.java index e674929..5a092a0 100644 --- a/src/main/java/gwangjang/server/domain/community/domain/service/CommunityQueryService.java +++ b/src/main/java/gwangjang/server/domain/community/domain/service/CommunityQueryService.java @@ -63,6 +63,17 @@ public List getCommunityTop5ByHeartsAndTopic(String topic) { } public List getCommunityTop5(CommunityOrderCondition communityOrderCondition, String with) { - return communityRepository.findCommunityTop5(communityOrderCondition, with).orElseThrow(NotFoundCommunityException::new); + List communityRes = communityRepository.findCommunityTop5(communityOrderCondition, with).orElseThrow(NotFoundCommunityException::new); + + communityRes.stream().forEach( + communityRes1 -> + { + String writerId = communityRes1.getWriterId(); + MemberDto memberDto = findMemberFeignClient.getMemberBySocialId(writerId); + communityRes1.updateMemberDto(memberDto); + } + ); + + return communityRes; } }