From 5f54321b5b5c210035907485a5f79ff365ff5cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Wed, 22 Nov 2023 10:48:59 +0900 Subject: [PATCH 01/45] =?UTF-8?q?fix:=20=EC=83=81=EC=84=B8=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20&=20=EC=BB=A4=EB=A6=AC=ED=81=98=EB=9F=BC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/application/service/NoticeSaveUseCase.java | 7 ++++--- .../domain/repository/NoticeDynamicRepositoryImpl.java | 2 +- .../notice/domain/repository/NoticeRepository.java | 7 +++++-- .../notice/domain/service/NoticeQueryService.java | 8 ++++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeSaveUseCase.java b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeSaveUseCase.java index 8dc8b2e3..a9a03a5d 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeSaveUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeSaveUseCase.java @@ -101,10 +101,11 @@ public NoticeListResponse selectNoticeDetail(Long memberId, Long noticeId) { NoticeListResponse response = noticeMapper.toNoticeDetailDTO(projection); // 조회 여부 기록 업데이트 - NoticeViewResponse viewResponse = noticeQueryService.findSingleViewYn(noticeId, memberId); + ViewType viewResponse = noticeQueryService.findSingleViewType(noticeId, memberId); + Long viewId = noticeQueryService.findSingleViewId(noticeId, memberId); - if (viewResponse.viewType().equals(ViewType.NONE)) { - noticeQueryService.updateSingleViewYn(viewResponse.id(), memberId, ViewType.VIEWED); + if (viewResponse.equals(ViewType.NONE)) { + noticeQueryService.updateSingleViewYn(viewId, memberId, ViewType.VIEWED); } return response; diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java index 58a9feb4..0683f3dd 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java @@ -71,7 +71,7 @@ public List findByCurriculum() { @Override public List selectNoticeByCurriculum(Long curriculumId) { return jpaQueryFactory.selectFrom(notice) - .join(curriculum).on(notice.id.eq(curriculumId)) + .join(curriculum).on(notice.curriculum.id.eq(curriculumId)) .orderBy(notice.createdAt.desc()) .fetch(); } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeRepository.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeRepository.java index 02d5b428..70dcd7d1 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeRepository.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeRepository.java @@ -33,8 +33,11 @@ public interface NoticeRepository extends JpaRepository, NoticeDyn @Query("update Notice n set n.title = :title, n.content = :content where n.id = :noticeId") void updateNotice(Long noticeId, String title, String content); - @Query("select v.id, v.view from Notice n join NoticeView v on n.noticeView.id = v.id where n.id = :noticeId and v.member.id = :memberId") - NoticeViewResponse findSingleViewYn(Long memberId, Long noticeId); + @Query("select v.id from Notice n join NoticeView v on n.noticeView.id = v.id where n.id = :noticeId and v.member.id = :memberId") + Long findSingleViewId(Long memberId, Long noticeId); + + @Query("select v.view from Notice n join NoticeView v on n.noticeView.id = v.id where n.id = :noticeId and v.member.id = :memberId") + ViewType findSingleViewType(Long memberId, Long noticeId); @Modifying @Query("update NoticeView v set v.view = :viewType where v.member.id = :memberId and v.id = :noticeViewId") diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java index 000093d3..5d4ecc23 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java @@ -92,8 +92,12 @@ public String findImageByNoticeId(Long noticeId) { return noticeRepository.findImageByNoticeId(noticeId); } - public NoticeViewResponse findSingleViewYn(Long noticeId, Long memberId) { - return noticeRepository.findSingleViewYn(memberId, noticeId); + public Long findSingleViewId(Long noticeId, Long memberId) { + return noticeRepository.findSingleViewId(memberId, noticeId); + } + + public ViewType findSingleViewType(Long noticeId, Long memberId) { + return noticeRepository.findSingleViewType(memberId, noticeId); } public void updateSingleViewYn(Long noticeViewId, Long memberId, ViewType viewType) { From 4aa547fbe342ed57010330bdc51ee5e6ffe1e039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Wed, 22 Nov 2023 11:06:45 +0900 Subject: [PATCH 02/45] fix: curriculum date column & entity --- .../notice/application/dto/CurriculumListResponse.java | 4 ++-- .../coremodule/notice/application/mapper/NoticeMapper.java | 6 +++--- .../com/koa/coremodule/notice/domain/entity/Curriculum.java | 4 ---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumListResponse.java b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumListResponse.java index 82723dff..7711c7eb 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumListResponse.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumListResponse.java @@ -1,8 +1,8 @@ package com.koa.coremodule.notice.application.dto; -import java.time.LocalDate; +import java.time.LocalDateTime; public record CurriculumListResponse(String title, String content, - LocalDate date) { + LocalDateTime date) { } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java b/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java index 25462223..e894d5ca 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java @@ -25,7 +25,7 @@ public interface NoticeMapper { @Mapping(source = "teamName", target = "team"), @Mapping(source = "date", target = "date") }) - List toNoticeListDTO(List company); + List toNoticeListDTO(List notice); @Mappings({ @Mapping(source = "curriculumId", target = "curriculumId"), @@ -33,14 +33,14 @@ public interface NoticeMapper { @Mapping(source = "name", target = "name"), @Mapping(source = "title", target = "title") }) - List toCurriculumDTO(List company); + List toCurriculumDTO(List notice); @Mappings({ @Mapping(source = "title", target = "title"), @Mapping(source = "content", target = "content"), @Mapping(source = "createdAt", target = "date") }) - List toCurriculumListDTO(List company); + List toCurriculumListDTO(List notice); @Mappings({ @Mapping(source = "title", target = "title"), diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/entity/Curriculum.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/entity/Curriculum.java index eb808080..a51a1a17 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/entity/Curriculum.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/entity/Curriculum.java @@ -19,8 +19,4 @@ public class Curriculum extends BaseEntity { private String curriculumName; - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "notice_id") - private Notice notice; - } From 2746b29e9d060957b56069b81b2a57abe8501145 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Wed, 22 Nov 2023 13:46:21 +0900 Subject: [PATCH 03/45] =?UTF-8?q?refactor=20:=20=EC=9D=B5=EB=AA=85=20?= =?UTF-8?q?=EC=97=AC=EB=B6=80=20=EC=B9=BC=EB=9F=BC=20=EC=B6=94=EA=B0=80,?= =?UTF-8?q?=20dto=EC=97=90=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dto/request/CommentCreateRequest.java | 1 + .../application/dto/response/CommentInfoResponse.java | 1 + .../application/dto/response/CommentListResponse.java | 1 + .../comment/application/mapper/CommentMapper.java | 7 +++++-- .../comment/application/service/CommentCreateUseCase.java | 4 ++-- .../comment/application/service/CommentGetUseCase.java | 4 ++-- .../com/koa/coremodule/comment/domain/entity/Comment.java | 2 ++ 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/dto/request/CommentCreateRequest.java b/core-module/src/main/java/com/koa/coremodule/comment/application/dto/request/CommentCreateRequest.java index 00766624..af50934e 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/dto/request/CommentCreateRequest.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/dto/request/CommentCreateRequest.java @@ -7,4 +7,5 @@ @NoArgsConstructor public class CommentCreateRequest { private String content; + private Boolean isAnonymous; } diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentInfoResponse.java b/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentInfoResponse.java index 7afa7bb6..c7a7fbb6 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentInfoResponse.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentInfoResponse.java @@ -13,4 +13,5 @@ public class CommentInfoResponse { private final String writer; private final String createdAt; private final Boolean isMine; + private final Boolean isAnonymous; } diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentListResponse.java b/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentListResponse.java index cbcf4da1..96b36c82 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentListResponse.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentListResponse.java @@ -14,4 +14,5 @@ public class CommentListResponse { private final String createdAt; private final Integer commentCount; private final Boolean isMine; + private final Boolean isAnonymous; } diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/mapper/CommentMapper.java b/core-module/src/main/java/com/koa/coremodule/comment/application/mapper/CommentMapper.java index ab445ae0..085cffbd 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/mapper/CommentMapper.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/mapper/CommentMapper.java @@ -11,21 +11,23 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class CommentMapper { - public static Comment mapToCommentWithUserAndAlbum(String content, Notice notice, Member member) { + public static Comment mapToCommentWithUserAndAlbum(String content, Notice notice, Member member, Boolean isAnonymous) { Comment comment = Comment.builder() .content(content) .notice(notice) .writer(member) + .isAnonymous(isAnonymous) .build(); return comment; } - public static Comment mapToCommentWithUserAndNoticeAndParent(String content, Notice notice, Member member, Comment parent) { + public static Comment mapToCommentWithUserAndNoticeAndParent(String content, Notice notice, Member member, Comment parent, Boolean isAnonymous) { Comment comment = Comment.builder() .content(content) .notice(notice) .writer(member) .parent(parent) + .isAnonymous(isAnonymous) .build(); return comment; } @@ -37,6 +39,7 @@ public static CommentInfoResponse mapToCommentInfoResponse(Comment comment, Memb .writer(member.getName()) .createdAt(comment.getCreatedAt().toString()) .isMine(comment.getWriter().equals(member)) + .isAnonymous(comment.getIsAnonymous()) .build(); } diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentCreateUseCase.java b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentCreateUseCase.java index 2222ea98..db2cf149 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentCreateUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentCreateUseCase.java @@ -26,7 +26,7 @@ public class CommentCreateUseCase { public CommentInfoResponse createComment(Long noticeId, CommentCreateRequest commentCreateRequest){ final Member member = memberUtils.getAccessMember(); final Notice notice = noticeQueryService.findByNoticeId(noticeId); - final Comment comment = CommentMapper.mapToCommentWithUserAndAlbum(commentCreateRequest.getContent(), notice, member); + final Comment comment = CommentMapper.mapToCommentWithUserAndAlbum(commentCreateRequest.getContent(), notice, member, commentCreateRequest.getIsAnonymous()); commentSaveService.saveComment(comment); return CommentMapper.mapToCommentInfoResponse(comment, member); @@ -37,7 +37,7 @@ public CommentInfoResponse createReComment(Long noticeId, Long commentId, Commen final Member member = memberUtils.getAccessMember(); final Notice notice = noticeQueryService.findByNoticeId(noticeId); final Comment parent = commentQueryService.getCommentById(commentId); - final Comment comment = CommentMapper.mapToCommentWithUserAndNoticeAndParent(commentCreateRequest.getContent(), notice, member, parent); + final Comment comment = CommentMapper.mapToCommentWithUserAndNoticeAndParent(commentCreateRequest.getContent(), notice, member, parent, commentCreateRequest.getIsAnonymous()); commentSaveService.saveComment(comment); return CommentMapper.mapToCommentInfoResponse(comment, member); diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentGetUseCase.java b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentGetUseCase.java index 063c15e3..6b3b2d9d 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentGetUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentGetUseCase.java @@ -29,7 +29,7 @@ public List getCommentList(Long noticeId){ for (Comment comment : commentList) { final List childCommentList = childCommentMap.get(comment.getId()); commentListResponses.add(new CommentListResponse(comment.getId(), comment.getContent(), comment.getWriter().getName(), comment.getCreatedAt().toString() - ,childCommentList != null ? childCommentList.size() : 0, comment.getWriter().equals(member))); + ,childCommentList != null ? childCommentList.size() : 0, comment.getWriter().equals(member), comment.getIsAnonymous())); } return commentListResponses; } @@ -40,7 +40,7 @@ public List getReCommentList(Long commentId){ final ArrayList childCommentInfoResponses = new ArrayList<>(); for (Comment comment : childCommentList) { childCommentInfoResponses.add(new CommentInfoResponse(comment.getId(), comment.getContent() - , comment.getWriter().getName(), comment.getCreatedAt().toString(), comment.getWriter().equals(member))); + , comment.getWriter().getName(), comment.getCreatedAt().toString(), comment.getWriter().equals(member), comment.getIsAnonymous())); } return childCommentInfoResponses; } diff --git a/core-module/src/main/java/com/koa/coremodule/comment/domain/entity/Comment.java b/core-module/src/main/java/com/koa/coremodule/comment/domain/entity/Comment.java index 91846119..adc74756 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/domain/entity/Comment.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/domain/entity/Comment.java @@ -31,6 +31,8 @@ public class Comment extends BaseEntity { @JoinColumn(name = "parent_id") private Comment parent; + private Boolean isAnonymous; + public Long getParentId() { return this.parent != null ? this.parent.getId() : null; } From 0837b559d0c32da4a6e8260cad3a29822da42c82 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Wed, 22 Nov 2023 13:46:57 +0900 Subject: [PATCH 04/45] =?UTF-8?q?feat=20:=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=B0=BE=EA=B8=B0=20=EC=9D=B4=ED=9B=84=EC=97=90=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=A0=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B3=80=EA=B2=BD=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/koa/apimodule/command/api/MemberController.java | 6 ++++++ .../auth/application/common/consts/IgnoredPathConsts.java | 1 + .../application/service/MemberPasswordChangeUseCase.java | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/MemberController.java b/api-module/src/main/java/com/koa/apimodule/command/api/MemberController.java index 2ba67c95..04a9f5bc 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/MemberController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/MemberController.java @@ -99,4 +99,10 @@ public ApplicationResponse putPassword(@RequestBody MemberPasswordChangeRe memberPasswordChangeUseCase.changePassword(memberPasswordChangeRequest); return ApplicationResponse.ok(null); } + + @PutMapping("/password/unauthenticated") + public ApplicationResponse putPasswordUnauthenticated(@RequestParam String email, @RequestBody MemberPasswordChangeRequest memberPasswordChangeRequest) { + memberPasswordChangeUseCase.changePasswordUnauthenticated(email, memberPasswordChangeRequest); + return ApplicationResponse.ok(null); + } } diff --git a/core-module/src/main/java/com/koa/coremodule/auth/application/common/consts/IgnoredPathConsts.java b/core-module/src/main/java/com/koa/coremodule/auth/application/common/consts/IgnoredPathConsts.java index c7f13c23..41511d19 100644 --- a/core-module/src/main/java/com/koa/coremodule/auth/application/common/consts/IgnoredPathConsts.java +++ b/core-module/src/main/java/com/koa/coremodule/auth/application/common/consts/IgnoredPathConsts.java @@ -25,6 +25,7 @@ private static Map> createIgnoredPathMap() { map.put("/v1/member/email", Set.of(HttpMethod.POST)); map.put("/v1/member/verify", Set.of(HttpMethod.POST)); map.put("/v1/member/verify/code", Set.of(HttpMethod.POST)); + map.put("/v1/member/password/unauthenticated", Set.of(HttpMethod.PUT)); map.put("/api-docs/**", Set.of(HttpMethod.GET, HttpMethod.POST)); map.put("/error", Set.of(HttpMethod.GET, HttpMethod.POST)); map.put("/favicon.ico", Set.of(HttpMethod.GET, HttpMethod.POST)); diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberPasswordChangeUseCase.java b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberPasswordChangeUseCase.java index 79e66578..11108805 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberPasswordChangeUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberPasswordChangeUseCase.java @@ -3,6 +3,7 @@ import com.koa.commonmodule.annotation.ApplicationService; import com.koa.coremodule.member.application.dto.request.MemberPasswordChangeRequest; import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.member.domain.service.MemberQueryService; import com.koa.coremodule.member.domain.utils.MemberUtils; import lombok.RequiredArgsConstructor; import org.springframework.transaction.annotation.Transactional; @@ -13,9 +14,15 @@ public class MemberPasswordChangeUseCase { private final MemberUtils memberUtils; + private final MemberQueryService memberQueryService; public void changePassword(MemberPasswordChangeRequest request) { Member member = memberUtils.getAccessMember(); member.updatePassword(request.getPassword()); } + + public void changePasswordUnauthenticated(String email, MemberPasswordChangeRequest request) { + Member member = memberQueryService.findByEmail(email); + member.updatePassword(request.getPassword()); + } } From 6694bbadf72fd6b925d5e585a2d3d57d0df47721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Wed, 22 Nov 2023 15:34:37 +0900 Subject: [PATCH 05/45] fix: entity relations --- .../com/koa/coremodule/notice/domain/entity/Notice.java | 4 ++-- .../koa/coremodule/notice/domain/entity/NoticeView.java | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/entity/Notice.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/entity/Notice.java index ea1fb6ee..cb3ce042 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/entity/Notice.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/entity/Notice.java @@ -56,11 +56,11 @@ public Notice(String title, String content, Member member, Curriculum curriculum this.curriculum = curriculum; } - public void settingInfo(String imageUrl, Member member, NoticeTeam team, Curriculum curriculum) { + public void settingInfo(String imageUrl, Member member, NoticeTeam team, Curriculum curriculum, Notice notice) { this.noticeTeam = team; this.noticeImage = NoticeImage.create(imageUrl); this.curriculum = curriculum; - this.noticeView = NoticeView.create(ViewType.NONE, member); + this.noticeView = NoticeView.create(ViewType.NONE, member, notice); this.member = member; } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/entity/NoticeView.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/entity/NoticeView.java index 37ebd180..f034ddc1 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/entity/NoticeView.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/entity/NoticeView.java @@ -23,10 +23,15 @@ public class NoticeView { @JoinColumn(name = "member_id") private Member member; - public static NoticeView create(ViewType view, Member member) { + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "notice_id") + private Notice notice; + + public static NoticeView create(ViewType view, Member member, Notice notice) { return NoticeView.builder() .view(view) .member(member) + .notice(notice) .build(); } From 6b41d145df8f46a6831c5f1a7dcdad2dd8234884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Wed, 22 Nov 2023 15:35:26 +0900 Subject: [PATCH 06/45] fix: usecase logics --- .../notice/application/service/NoticeFindUseCase.java | 1 - .../notice/application/service/NoticeSaveUseCase.java | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java index f357b837..76b5fa7c 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java @@ -25,7 +25,6 @@ public class NoticeFindUseCase { public List selectNotice(Long memberId) { List projection = noticeQueryService.selectNotice(); - List response = noticeMapper.toNoticeListDTO(projection); noticeQueryService.findViewYn(response, memberId, projection); diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeSaveUseCase.java b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeSaveUseCase.java index a9a03a5d..f35a3e96 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeSaveUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeSaveUseCase.java @@ -45,13 +45,14 @@ public Long saveNotice(NoticeRequest request, MultipartFile multipartFile) { // 공지 본문 저장 Notice noticeEntity = noticeMapper.toNoticeEntity(request); final Member member = noticeQueryService.findMemberById(request.getMemberId()).orElseThrow(() -> new NoticeNotFoundException(Error.MEMBER_NOT_FOUND)); + Notice savedNotice = noticeQueryService.save(noticeEntity); // 공지 저장 시 연관 테이블 모두 맵핑 final NoticeTeam noticeTeam = noticeQueryService.findNoticeTeamById(request.getTeamId()).orElseThrow(() -> new EntityNotFoundException("팀을 찾을 수 없습니다.")); final Curriculum curriculum = noticeQueryService.findCurriculumById(request.getCurriculumId()).orElseThrow(() -> new EntityNotFoundException("커리큘럼을 찾을 수 없습니다.")); - noticeEntity.settingInfo(imageUrl, member, noticeTeam, curriculum); + noticeEntity.settingInfo(imageUrl, member, noticeTeam, curriculum, savedNotice); - Notice savedNotice = noticeQueryService.save(noticeEntity); + noticeQueryService.save(noticeEntity); return savedNotice.getId(); } From e2e564070f611423adca5bf876addd66e6c1fb24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Wed, 22 Nov 2023 15:36:04 +0900 Subject: [PATCH 07/45] fix: controller & query service logics --- .../command/api/NoticeController.java | 2 -- .../domain/service/NoticeQueryService.java | 27 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java b/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java index 75f927ea..b0895561 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java @@ -67,8 +67,6 @@ public ApplicationResponse saveNotice( @RequestPart(value = "dto") NoticeRequest request, @RequestPart(value = "file") MultipartFile multipartFile) { - Member memberRequest = memberUtils.getAccessMember(); - request.setMemberId(memberRequest.getId()); Long noticeId = noticeSaveUseCase.saveNotice(request, multipartFile); return ApplicationResponse.ok(noticeId, "공지 작성에 성공했습니다."); } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java index 5d4ecc23..459ed888 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java @@ -6,14 +6,12 @@ import com.koa.coremodule.notice.application.dto.NoticeListResponse; import com.koa.coremodule.notice.application.dto.NoticeViewRequest; import com.koa.coremodule.notice.application.dto.NoticeViewResponse; -import com.koa.coremodule.notice.domain.entity.Curriculum; -import com.koa.coremodule.notice.domain.entity.Notice; -import com.koa.coremodule.notice.domain.entity.NoticeTeam; -import com.koa.coremodule.notice.domain.entity.ViewType; +import com.koa.coremodule.notice.domain.entity.*; import com.koa.coremodule.notice.domain.exception.NoticeNotFoundException; import com.koa.coremodule.notice.domain.repository.CurriculumRepository; import com.koa.coremodule.notice.domain.repository.NoticeRepository; import com.koa.coremodule.notice.domain.repository.NoticeTeamRepository; +import com.koa.coremodule.notice.domain.repository.NoticeViewRepository; import com.koa.coremodule.notice.domain.repository.projection.CurriculumProjection; import com.koa.coremodule.notice.domain.repository.projection.NoticeListProjection; import lombok.RequiredArgsConstructor; @@ -30,6 +28,7 @@ public class NoticeQueryService { private final MemberRepository memberRepository; private final NoticeTeamRepository noticeTeamRepository; private final CurriculumRepository curriculumRepository; + private final NoticeViewRepository noticeViewRepository; public List selectNotice() { @@ -44,12 +43,22 @@ public void findViewYn(List response, Long memberId, List new NoticeNotFoundException(Error.MEMBER_NOT_FOUND)); + final Notice noticeEntity = noticeRepository.findById(viewRequest.noticeId()).orElseThrow(() -> new NoticeNotFoundException(Error.NOTICE_NOT_FOUND)); + NoticeView noticeView = NoticeView.create(ViewType.NONE, member, noticeEntity); + noticeViewRepository.save(noticeView); } + i++; } } From adb6e05ad33bf4ff0f7eafd316b9b7c3790bf99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Wed, 22 Nov 2023 15:36:17 +0900 Subject: [PATCH 08/45] fix: related notice repositoiries --- .../domain/repository/NoticeDynamicRepositoryImpl.java | 7 ++----- .../notice/domain/repository/NoticeRepository.java | 7 +++---- .../notice/domain/repository/NoticeViewRepository.java | 7 +++++++ 3 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeViewRepository.java diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java index 0683f3dd..8023e581 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java @@ -21,7 +21,6 @@ public class NoticeDynamicRepositoryImpl implements NoticeDynamicRepository { private final JPAQueryFactory jpaQueryFactory; - @Override public List findAllNotice() { return jpaQueryFactory.select(new QNoticeListProjection( @@ -51,10 +50,8 @@ public NoticeListProjection findAllNoticeDetail(Long noticeId) { @Override public ViewType findViewYn(NoticeViewRequest request) { return jpaQueryFactory.select(noticeView.view) - .from(notice) - .join(noticeView) - .on(notice.noticeView.id.eq(noticeView.id)) - .where(noticeView.member.id.eq(request.memberId()).and(notice.id.eq(request.noticeId()))) + .from(noticeView) + .where(noticeView.member.id.eq(request.memberId()).and(noticeView.notice.id.eq(request.noticeId()))) .fetchOne(); } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeRepository.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeRepository.java index 70dcd7d1..2e6affdb 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeRepository.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeRepository.java @@ -1,6 +1,5 @@ package com.koa.coremodule.notice.domain.repository; -import com.koa.coremodule.notice.application.dto.NoticeViewResponse; import com.koa.coremodule.notice.domain.entity.Notice; import com.koa.coremodule.notice.domain.entity.ViewType; import org.springframework.data.jpa.repository.JpaRepository; @@ -14,7 +13,7 @@ public interface NoticeRepository extends JpaRepository, NoticeDyn @Query("select n.id from Notice n where n.member.id = :memberId") List findIdsByMemberId(Long memberId); - @Query("select v.imageUrl from Notice n join NoticeImage v on n.noticeView.id = v.id where n.id = :noticeId") + @Query("select v.imageUrl from Notice n join NoticeImage v on n.noticeImage.id = v.id where n.id = :noticeId") String findImageByNoticeId(Long noticeId); @Modifying @@ -33,10 +32,10 @@ public interface NoticeRepository extends JpaRepository, NoticeDyn @Query("update Notice n set n.title = :title, n.content = :content where n.id = :noticeId") void updateNotice(Long noticeId, String title, String content); - @Query("select v.id from Notice n join NoticeView v on n.noticeView.id = v.id where n.id = :noticeId and v.member.id = :memberId") + @Query("select v.id from NoticeView v where v.notice.id = :noticeId and v.member.id = :memberId") Long findSingleViewId(Long memberId, Long noticeId); - @Query("select v.view from Notice n join NoticeView v on n.noticeView.id = v.id where n.id = :noticeId and v.member.id = :memberId") + @Query("select v.view from NoticeView v where v.notice.id = :noticeId and v.member.id = :memberId") ViewType findSingleViewType(Long memberId, Long noticeId); @Modifying diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeViewRepository.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeViewRepository.java new file mode 100644 index 00000000..a99152f8 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeViewRepository.java @@ -0,0 +1,7 @@ +package com.koa.coremodule.notice.domain.repository; + +import com.koa.coremodule.notice.domain.entity.NoticeView; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NoticeViewRepository extends JpaRepository { +} From 889ba84b6f4ecac56efa9945cc79f53564105783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Wed, 22 Nov 2023 16:06:56 +0900 Subject: [PATCH 09/45] =?UTF-8?q?fix:=20readonly=20transactional=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/application/service/NoticeFindUseCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java index 76b5fa7c..db591b94 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java @@ -15,7 +15,7 @@ import java.util.List; @Service -@Transactional(readOnly = true) +@Transactional @RequiredArgsConstructor public class NoticeFindUseCase { From 729a686128e55c17bf64c9cd0b12a83a148e6758 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 Nov 2023 15:16:40 +0900 Subject: [PATCH 10/45] =?UTF-8?q?refactor=20:=20Comment=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=EA=B0=92=EC=97=90=20=EC=9E=91=EC=84=B1=EC=9E=90=20id,?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1=EC=9E=90=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20url=20=EC=B6=94=EA=B0=80,=20?= =?UTF-8?q?=EB=8C=93=EA=B8=80=20=EC=9E=91=EC=84=B1=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/CommentInfoResponse.java | 2 + .../dto/response/CommentListResponse.java | 2 + .../application/mapper/CommentMapper.java | 7 ++- .../service/CommentCreateUseCase.java | 9 +++- .../service/CommentGetUseCase.java | 52 ++++++++++++++++--- .../comment/domain/entity/Comment.java | 5 ++ .../repository/MemberDetailRepository.java | 4 ++ .../service/MemberDetailQueryService.java | 7 ++- 8 files changed, 76 insertions(+), 12 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentInfoResponse.java b/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentInfoResponse.java index c7a7fbb6..f750c316 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentInfoResponse.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentInfoResponse.java @@ -14,4 +14,6 @@ public class CommentInfoResponse { private final String createdAt; private final Boolean isMine; private final Boolean isAnonymous; + private final String profileImageUrl; + private final Long writerId; } diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentListResponse.java b/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentListResponse.java index 96b36c82..6ba2b3e2 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentListResponse.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/dto/response/CommentListResponse.java @@ -15,4 +15,6 @@ public class CommentListResponse { private final Integer commentCount; private final Boolean isMine; private final Boolean isAnonymous; + private final String profileImageUrl; + private final Long writerId; } diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/mapper/CommentMapper.java b/core-module/src/main/java/com/koa/coremodule/comment/application/mapper/CommentMapper.java index 085cffbd..718546fb 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/mapper/CommentMapper.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/mapper/CommentMapper.java @@ -3,6 +3,7 @@ import com.koa.coremodule.comment.application.dto.response.CommentInfoResponse; import com.koa.coremodule.comment.domain.entity.Comment; import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.member.domain.entity.MemberDetail; import com.koa.coremodule.notice.domain.entity.Notice; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -32,14 +33,16 @@ public static Comment mapToCommentWithUserAndNoticeAndParent(String content, Not return comment; } - public static CommentInfoResponse mapToCommentInfoResponse(Comment comment, Member member) { + public static CommentInfoResponse mapToCommentInfoResponse(Comment comment, Member member, MemberDetail memberDetail) { return CommentInfoResponse.builder() .commentId(comment.getId()) .content(comment.getContent()) .writer(member.getName()) - .createdAt(comment.getCreatedAt().toString()) + .createdAt(comment.getCreatedAtByFormat()) .isMine(comment.getWriter().equals(member)) .isAnonymous(comment.getIsAnonymous()) + .profileImageUrl(memberDetail.getProfileImage()) + .writerId(member.getId()) .build(); } diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentCreateUseCase.java b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentCreateUseCase.java index db2cf149..04b85b3a 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentCreateUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentCreateUseCase.java @@ -8,6 +8,8 @@ import com.koa.coremodule.comment.domain.service.CommentQueryService; import com.koa.coremodule.comment.domain.service.CommentSaveService; import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.member.domain.entity.MemberDetail; +import com.koa.coremodule.member.domain.service.MemberDetailQueryService; import com.koa.coremodule.member.domain.utils.MemberUtils; import com.koa.coremodule.notice.domain.service.NoticeQueryService; import com.koa.coremodule.notice.domain.entity.Notice; @@ -21,15 +23,17 @@ public class CommentCreateUseCase { private final NoticeQueryService noticeQueryService; private final CommentSaveService commentSaveService; private final CommentQueryService commentQueryService; + private final MemberDetailQueryService memberDetailQueryService; @Transactional public CommentInfoResponse createComment(Long noticeId, CommentCreateRequest commentCreateRequest){ final Member member = memberUtils.getAccessMember(); final Notice notice = noticeQueryService.findByNoticeId(noticeId); final Comment comment = CommentMapper.mapToCommentWithUserAndAlbum(commentCreateRequest.getContent(), notice, member, commentCreateRequest.getIsAnonymous()); + final MemberDetail memberDetail = memberDetailQueryService.findMemberDetailByMemberId(member.getId()); commentSaveService.saveComment(comment); - return CommentMapper.mapToCommentInfoResponse(comment, member); + return CommentMapper.mapToCommentInfoResponse(comment, member, memberDetail); } @Transactional @@ -38,8 +42,9 @@ public CommentInfoResponse createReComment(Long noticeId, Long commentId, Commen final Notice notice = noticeQueryService.findByNoticeId(noticeId); final Comment parent = commentQueryService.getCommentById(commentId); final Comment comment = CommentMapper.mapToCommentWithUserAndNoticeAndParent(commentCreateRequest.getContent(), notice, member, parent, commentCreateRequest.getIsAnonymous()); + final MemberDetail memberDetail = memberDetailQueryService.findMemberDetailByMemberId(member.getId()); commentSaveService.saveComment(comment); - return CommentMapper.mapToCommentInfoResponse(comment, member); + return CommentMapper.mapToCommentInfoResponse(comment, member, memberDetail); } } diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentGetUseCase.java b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentGetUseCase.java index 6b3b2d9d..5ecbfb7b 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentGetUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentGetUseCase.java @@ -6,7 +6,13 @@ import com.koa.coremodule.comment.domain.entity.Comment; import com.koa.coremodule.comment.domain.service.CommentQueryService; import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.member.domain.entity.MemberDetail; +import com.koa.coremodule.member.domain.service.MemberDetailQueryService; import com.koa.coremodule.member.domain.utils.MemberUtils; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.function.Function; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.transaction.annotation.Transactional; @@ -20,28 +26,60 @@ public class CommentGetUseCase { private final CommentQueryService commentQueryService; private final MemberUtils memberUtils; + private final MemberDetailQueryService memberDetailQueryService; public List getCommentList(Long noticeId){ final Member member = memberUtils.getAccessMember(); final Map> childCommentMap = commentQueryService.getChildCommentByNoticeId(noticeId); final ArrayList commentListResponses = new ArrayList<>(); - List commentList = commentQueryService.getCommentByNoticeId(noticeId); - for (Comment comment : commentList) { + final Map commentMemberDetailMap = createCommentMemberDetailMapWithNoticeId(noticeId); + for (Comment comment : commentMemberDetailMap.keySet()) { final List childCommentList = childCommentMap.get(comment.getId()); - commentListResponses.add(new CommentListResponse(comment.getId(), comment.getContent(), comment.getWriter().getName(), comment.getCreatedAt().toString() - ,childCommentList != null ? childCommentList.size() : 0, comment.getWriter().equals(member), comment.getIsAnonymous())); + commentListResponses.add(new CommentListResponse(comment.getId(), comment.getContent(), comment.getWriter().getName(), + comment.getCreatedAtByFormat() ,childCommentList != null ? childCommentList.size() : 0, + comment.getWriter().equals(member), comment.getIsAnonymous(), commentMemberDetailMap.get(comment).getProfileImage(), + comment.getWriter().getId())); } return commentListResponses; } public List getReCommentList(Long commentId){ final Member member = memberUtils.getAccessMember(); - final List childCommentList = commentQueryService.getChildCommentByCommentId(commentId); + final Map childCommentMemberDetailMap = createCommentMemberDetailMapWithCommentId(commentId); final ArrayList childCommentInfoResponses = new ArrayList<>(); - for (Comment comment : childCommentList) { + for (Comment comment : childCommentMemberDetailMap.keySet()) { childCommentInfoResponses.add(new CommentInfoResponse(comment.getId(), comment.getContent() - , comment.getWriter().getName(), comment.getCreatedAt().toString(), comment.getWriter().equals(member), comment.getIsAnonymous())); + , comment.getWriter().getName(), comment.getCreatedAtByFormat(), + comment.getWriter().equals(member), comment.getIsAnonymous(), + childCommentMemberDetailMap.get(comment).getProfileImage(), comment.getWriter().getId())); } return childCommentInfoResponses; } + + private Map createCommentMemberDetailMap(Long id, Function> commentGetter) { + final List commentList = commentGetter.apply(id); + final List memberIdList = commentList.stream() + .map(comment -> comment.getWriter().getId()) + .collect(Collectors.toList()); + final List memberDetailList = memberDetailQueryService.findMemberDetailListByMemberIdList(memberIdList); + final Map memberDetailMap = memberDetailList.stream() + .collect(Collectors.toMap(memberDetail -> memberDetail.getMember().getId(), memberDetail -> memberDetail)); + final Map commentMemberDetailMap = commentList.stream() + .sorted(Comparator.comparing(Comment::getCreatedAt).reversed()) + .collect(Collectors.toMap( + comment -> comment, + comment -> memberDetailMap.get(comment.getWriter().getId()), + (existing, replacement) -> existing, + LinkedHashMap::new + )); + return commentMemberDetailMap; + } + + public Map createCommentMemberDetailMapWithNoticeId(Long noticeId) { + return createCommentMemberDetailMap(noticeId, commentQueryService::getCommentByNoticeId); + } + + public Map createCommentMemberDetailMapWithCommentId(Long commentId) { + return createCommentMemberDetailMap(commentId, commentQueryService::getChildCommentByCommentId); + } } diff --git a/core-module/src/main/java/com/koa/coremodule/comment/domain/entity/Comment.java b/core-module/src/main/java/com/koa/coremodule/comment/domain/entity/Comment.java index adc74756..f9666994 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/domain/entity/Comment.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/domain/entity/Comment.java @@ -4,6 +4,7 @@ import com.koa.coremodule.notice.domain.entity.Notice; import com.koa.coremodule.member.domain.entity.Member; import jakarta.persistence.*; +import java.time.format.DateTimeFormatter; import lombok.*; @Builder @@ -36,4 +37,8 @@ public class Comment extends BaseEntity { public Long getParentId() { return this.parent != null ? this.parent.getId() : null; } + + public String getCreatedAtByFormat() { + return this.createdAt.format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm")); + } } diff --git a/core-module/src/main/java/com/koa/coremodule/member/domain/repository/MemberDetailRepository.java b/core-module/src/main/java/com/koa/coremodule/member/domain/repository/MemberDetailRepository.java index 6e1b8e6a..193ff4a2 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/domain/repository/MemberDetailRepository.java +++ b/core-module/src/main/java/com/koa/coremodule/member/domain/repository/MemberDetailRepository.java @@ -1,6 +1,7 @@ package com.koa.coremodule.member.domain.repository; import com.koa.coremodule.member.domain.entity.MemberDetail; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -9,6 +10,9 @@ public interface MemberDetailRepository extends JpaRepository findByMemberId(Long memberId); + @Query("select m from MemberDetail m join fetch m.member where m.member.id in :memberIdList") + List findAllByMemberIdIn(List memberIdList); + boolean existsByMemberId(Long memberId); void deleteByMemberId(Long memberId); diff --git a/core-module/src/main/java/com/koa/coremodule/member/domain/service/MemberDetailQueryService.java b/core-module/src/main/java/com/koa/coremodule/member/domain/service/MemberDetailQueryService.java index f7c04b57..c35836a4 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/domain/service/MemberDetailQueryService.java +++ b/core-module/src/main/java/com/koa/coremodule/member/domain/service/MemberDetailQueryService.java @@ -5,6 +5,7 @@ import com.koa.coremodule.member.domain.entity.MemberDetail; import com.koa.coremodule.member.domain.exception.UserNotFoundException; import com.koa.coremodule.member.domain.repository.MemberDetailRepository; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.transaction.annotation.Transactional; @@ -14,11 +15,15 @@ public class MemberDetailQueryService { private final MemberDetailRepository memberDetailRepository; - public MemberDetail findMemberDatailByMemberId(Long memberId) { + public MemberDetail findMemberDetailByMemberId(Long memberId) { return memberDetailRepository.findByMemberId(memberId) .orElseThrow(() -> new UserNotFoundException(Error.MEMBER_NOT_FOUND)); } + public List findMemberDetailListByMemberIdList(List memberIdList){ + return memberDetailRepository.findAllByMemberIdIn(memberIdList); + } + public boolean isMemberDetailExist(Long memberId){ return memberDetailRepository.existsByMemberId(memberId); } From 61297cd383aadc6a1e8da0db80384b68e676fa99 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 Nov 2023 15:16:51 +0900 Subject: [PATCH 11/45] =?UTF-8?q?refactor=20:=20n=20+=201=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/domain/repository/CommentRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/comment/domain/repository/CommentRepository.java b/core-module/src/main/java/com/koa/coremodule/comment/domain/repository/CommentRepository.java index d195e54f..aa487f61 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/domain/repository/CommentRepository.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/domain/repository/CommentRepository.java @@ -10,10 +10,10 @@ public interface CommentRepository extends JpaRepository { - @Query("select c from Comment c where c.notice.id = :noticeId and c.parent is null order by c.createdAt asc") + @Query("select c from Comment c join fetch c.writer where c.notice.id = :noticeId and c.parent is null order by c.createdAt asc") List findByNoticeId(@Param("noticeId") Long noticeId); - @Query("select c from Comment c where c.notice.id = :noticeId and c.parent is not null order by c.createdAt asc") + @Query("select c from Comment c join fetch c.writer where c.notice.id = :noticeId and c.parent is not null order by c.createdAt asc") List findChildByNoticeId(@Param("noticeId") Long noticeId); @Query("select c from Comment c where c.parent.id = :commentId order by c.createdAt asc") From add788556db88edbff79234a2078935610f6bc18 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 Nov 2023 15:18:20 +0900 Subject: [PATCH 12/45] =?UTF-8?q?refactor=20:=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=EA=B0=80=EB=8A=A5=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?API=EC=99=80=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20API=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/api/MemberController.java | 12 ++++++++- .../dto/response/CheckRegisterResponse.java | 20 +++++++++++--- .../service/MemberCheckUseCase.java | 7 ++--- .../application/service/MemberGetUseCase.java | 2 +- .../service/MemberRegisterUseCase.java | 26 +++++++++++++++++++ .../member/domain/entity/Member.java | 12 +++++++++ .../domain/service/MemberQueryService.java | 2 +- 7 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 core-module/src/main/java/com/koa/coremodule/member/application/service/MemberRegisterUseCase.java diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/MemberController.java b/api-module/src/main/java/com/koa/apimodule/command/api/MemberController.java index 04a9f5bc..48b71b26 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/MemberController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/MemberController.java @@ -15,6 +15,7 @@ import com.koa.coremodule.member.application.service.MemberGetUseCase; import com.koa.coremodule.member.application.service.MemberCheckUseCase; import com.koa.coremodule.member.application.service.MemberPasswordChangeUseCase; +import com.koa.coremodule.member.application.service.MemberRegisterUseCase; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.DeleteMapping; @@ -40,6 +41,7 @@ public class MemberController { private final MemberDeleteUseCase memberDeleteUseCase; private final EmailVerificationUseCase emailVerificationUseCase; private final MemberPasswordChangeUseCase memberPasswordChangeUseCase; + private final MemberRegisterUseCase memberRegisterUseCase; @GetMapping("/info") public ApplicationResponse getMemberInfo(){ @@ -53,11 +55,19 @@ public ApplicationResponse postMemberDetail(@RequestPart(value = "dto") Me return ApplicationResponse.ok(null); } - @PostMapping("/register") + @PostMapping("/check/register") public ApplicationResponse checkMemberRegistered(@RequestParam String email, @RequestParam String password) { CheckRegisterResponse response = memberCheckUseCase.checkMemberRegistered(email, password); return ApplicationResponse.ok(response); } + + @PostMapping("/register") + public ApplicationResponse postMemberDetail(@RequestParam String email, @RequestParam String password){ + memberRegisterUseCase.registerMember(email, password); + return ApplicationResponse.ok(null); + } + + @GetMapping("/info/detail") public ApplicationResponse getMemberDetailInfo() { MemberDetailInfoResponse response = memberGetUseCase.getMemberDetailInfo(); diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/dto/response/CheckRegisterResponse.java b/core-module/src/main/java/com/koa/coremodule/member/application/dto/response/CheckRegisterResponse.java index f20f66c8..33006e30 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/application/dto/response/CheckRegisterResponse.java +++ b/core-module/src/main/java/com/koa/coremodule/member/application/dto/response/CheckRegisterResponse.java @@ -1,12 +1,26 @@ package com.koa.coremodule.member.application.dto.response; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Getter; @Getter -@Builder @AllArgsConstructor public class CheckRegisterResponse { - private final Boolean isRegistered; + private ReisterResult checkRegistered; + + public enum ReisterResult { + NO_ACCOUNT, + REGISTERED, + CAN_REGISTER + } + + public CheckRegisterResponse(Boolean isMember, Boolean isRegistered) { + if(isMember && isRegistered) { + checkRegistered = ReisterResult.REGISTERED; + } else if(isMember && !isRegistered) { + checkRegistered = ReisterResult.CAN_REGISTER; + } else { + checkRegistered = ReisterResult.NO_ACCOUNT; + } + } } diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberCheckUseCase.java b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberCheckUseCase.java index b5523733..b74420d8 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberCheckUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberCheckUseCase.java @@ -19,13 +19,14 @@ public class MemberCheckUseCase { private final MemberQueryService memberQueryService; public CheckRegisterResponse checkMemberRegistered(String email, String password) { - final boolean isRegistered = memberQueryService.checkMemberRegistered(email, password); - return new CheckRegisterResponse(isRegistered); + boolean isMember = memberQueryService.checkMemberExist(email, password); + Member member = isMember ? memberQueryService.findByEmail(email) : null; + return new CheckRegisterResponse(isMember, member != null && member.isRegistered()); } public CheckPasswordResponse checkPassword(String password) { Member member = memberUtils.getAccessMember(); - return new CheckPasswordResponse(member.getPassword().equals(password)); + return new CheckPasswordResponse(member.checkPassword(password)); } public CheckEmailResponse checkEmail(String email) { diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberGetUseCase.java b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberGetUseCase.java index a3ed87e5..1f003554 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberGetUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberGetUseCase.java @@ -36,7 +36,7 @@ public MemberInfoResponse getMemberInfo(){ public MemberDetailInfoResponse getMemberDetailInfo(){ final Member member = memberUtils.getAccessMember(); - final MemberDetail memberDetail = memberDetailQueryService.findMemberDatailByMemberId(member.getId()); + final MemberDetail memberDetail = memberDetailQueryService.findMemberDetailByMemberId(member.getId()); final List interests = interestQueryService.findInterestsByMemberDetailId(memberDetail.getId()); final List interestInfoResponses = interests.stream() .map(MemberMapper::mapToInterestInfoResponse) diff --git a/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberRegisterUseCase.java b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberRegisterUseCase.java new file mode 100644 index 00000000..f3496ad6 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/member/application/service/MemberRegisterUseCase.java @@ -0,0 +1,26 @@ +package com.koa.coremodule.member.application.service; + +import com.koa.commonmodule.annotation.ApplicationService; +import com.koa.commonmodule.exception.Error; +import com.koa.coremodule.member.application.exception.WrongPasswordException; +import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.member.domain.service.MemberQueryService; +import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; + +@ApplicationService +@RequiredArgsConstructor +@Transactional +public class MemberRegisterUseCase { + + private final MemberQueryService memberQueryService; + + public void registerMember(String email, String password) { + Member member = memberQueryService.findByEmail(email); + final boolean isPasswordMatch = member.checkPassword(password); + if(!isPasswordMatch) { + throw new WrongPasswordException(Error.MEMBER_NOT_FOUND); + } + member.register(); + } +} diff --git a/core-module/src/main/java/com/koa/coremodule/member/domain/entity/Member.java b/core-module/src/main/java/com/koa/coremodule/member/domain/entity/Member.java index 957b6431..aad1791e 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/domain/entity/Member.java +++ b/core-module/src/main/java/com/koa/coremodule/member/domain/entity/Member.java @@ -34,6 +34,7 @@ public class Member extends BaseEntity { private Authority authority; private Boolean isDeleted = Boolean.FALSE; + private Boolean isRegistered = Boolean.FALSE; @Builder public Member(String name, String period, String email, String phoneNumber, String password, Authority authority) { @@ -56,4 +57,15 @@ public void updateFcmToken(String fcmToken) { this.fcmToken = fcmToken; } } + public boolean checkPassword(String password) { + return this.password.equals(password); + } + + public void register() { + this.isRegistered = true; + } + + public boolean isRegistered() { + return this.isRegistered; + } } diff --git a/core-module/src/main/java/com/koa/coremodule/member/domain/service/MemberQueryService.java b/core-module/src/main/java/com/koa/coremodule/member/domain/service/MemberQueryService.java index ede49b71..5d52d354 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/domain/service/MemberQueryService.java +++ b/core-module/src/main/java/com/koa/coremodule/member/domain/service/MemberQueryService.java @@ -21,7 +21,7 @@ public void checkAccountExist(Authority authority, String email, String password } } - public boolean checkMemberRegistered(String email, String password) { + public boolean checkMemberExist(String email, String password) { return memberRepository.existsByEmailAndPassword(email, password); } From 9a54ddf00340c2e9f448f6568748b3cbc9ac6194 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 Nov 2023 15:18:56 +0900 Subject: [PATCH 13/45] =?UTF-8?q?refactor=20:=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=EA=B0=80=EB=8A=A5=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?API=20=ED=86=A0=ED=81=B0=20=EA=B2=80=EC=A6=9D=20=EB=AC=B4?= =?UTF-8?q?=EC=8B=9C=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/application/common/consts/IgnoredPathConsts.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core-module/src/main/java/com/koa/coremodule/auth/application/common/consts/IgnoredPathConsts.java b/core-module/src/main/java/com/koa/coremodule/auth/application/common/consts/IgnoredPathConsts.java index 41511d19..52f1beb3 100644 --- a/core-module/src/main/java/com/koa/coremodule/auth/application/common/consts/IgnoredPathConsts.java +++ b/core-module/src/main/java/com/koa/coremodule/auth/application/common/consts/IgnoredPathConsts.java @@ -20,6 +20,7 @@ private static Map> createIgnoredPathMap() { map.put("/v1/auth/reissue", Set.of(HttpMethod.GET)); map.put("/v1/member/register", Set.of(HttpMethod.POST)); + map.put("/v1/member/check/register", Set.of(HttpMethod.POST)); map.put("/h2-console/**", Set.of(HttpMethod.GET, HttpMethod.POST)); map.put("/v1/auth/login/**", Set.of(HttpMethod.GET, HttpMethod.POST)); map.put("/v1/member/email", Set.of(HttpMethod.POST)); From 908459078a556ff1ffb97386907112eaf3e0ff38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Thu, 23 Nov 2023 17:33:36 +0900 Subject: [PATCH 14/45] feat: curriculum response dto --- .../application/dto/CurriculumListResponse.java | 17 ++++++++++++++--- .../application/dto/CurriculumResponse.java | 16 ++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumListResponse.java b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumListResponse.java index 7711c7eb..345aa785 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumListResponse.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumListResponse.java @@ -1,8 +1,19 @@ package com.koa.coremodule.notice.application.dto; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + import java.time.LocalDateTime; -public record CurriculumListResponse(String title, - String content, - LocalDateTime date) { +@Data +@Builder +@Jacksonized +public class CurriculumListResponse { + + private Long noticeId; + private String title; + private String content; + private LocalDateTime date; + } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumResponse.java b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumResponse.java index 67092a09..b8ce84b2 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumResponse.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumResponse.java @@ -1,7 +1,15 @@ package com.koa.coremodule.notice.application.dto; -public record CurriculumResponse(Long curriculumId, - String curriculumName, - String name, - String title) { +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +@Builder +@Jacksonized +public class CurriculumResponse { + + private Long curriculumId; + private String curriculumName; + private String title; } From 280f14a6079882aedf770bf2d3e3e2a2ff8bef1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Thu, 23 Nov 2023 17:33:57 +0900 Subject: [PATCH 15/45] fix: curriculum mapper --- .../application/mapper/CurriculumMapper.java | 18 ++++++++++++++++++ .../application/mapper/NoticeMapper.java | 4 +--- 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 core-module/src/main/java/com/koa/coremodule/notice/application/mapper/CurriculumMapper.java diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/CurriculumMapper.java b/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/CurriculumMapper.java new file mode 100644 index 00000000..cbdbec0d --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/CurriculumMapper.java @@ -0,0 +1,18 @@ +package com.koa.coremodule.notice.application.mapper; + +import com.koa.coremodule.notice.application.dto.CurriculumResponse; +import com.koa.coremodule.notice.domain.repository.projection.CurriculumProjection; + +public final class CurriculumMapper { + private CurriculumMapper() { + } + + public static CurriculumResponse toResponse(CurriculumProjection curriculum) { + if (curriculum == null) return CurriculumResponse.builder().build(); + return CurriculumResponse.builder() + .curriculumId(curriculum.getCurriculumId()) + .curriculumName(curriculum.getCurriculumName()) + .title(curriculum.getTitle()) + .build(); + } +} diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java b/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java index e894d5ca..da657cac 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java @@ -30,15 +30,13 @@ public interface NoticeMapper { @Mappings({ @Mapping(source = "curriculumId", target = "curriculumId"), @Mapping(source = "curriculumName", target = "curriculumName"), - @Mapping(source = "name", target = "name"), @Mapping(source = "title", target = "title") }) List toCurriculumDTO(List notice); @Mappings({ @Mapping(source = "title", target = "title"), - @Mapping(source = "content", target = "content"), - @Mapping(source = "createdAt", target = "date") + @Mapping(source = "content", target = "content") }) List toCurriculumListDTO(List notice); From 61f66595578423338a3204c55275cda63f4aed95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Thu, 23 Nov 2023 17:34:15 +0900 Subject: [PATCH 16/45] fix: query repository --- .../NoticeDynamicRepositoryImpl.java | 22 ++++++++++---- .../projection/CurriculumProjection.java | 29 ++++++------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java index 8023e581..8ae8c739 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java @@ -2,16 +2,18 @@ import com.koa.coremodule.notice.application.dto.NoticeViewRequest; import com.koa.coremodule.notice.domain.entity.Notice; +import com.koa.coremodule.notice.domain.entity.QNotice; import com.koa.coremodule.notice.domain.entity.ViewType; import com.koa.coremodule.notice.domain.repository.projection.CurriculumProjection; import com.koa.coremodule.notice.domain.repository.projection.NoticeListProjection; +import com.koa.coremodule.notice.domain.repository.projection.QCurriculumProjection; import com.koa.coremodule.notice.domain.repository.projection.QNoticeListProjection; +import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; import java.util.List; -import static com.koa.coremodule.member.domain.entity.QMember.member; import static com.koa.coremodule.notice.domain.entity.QCurriculum.curriculum; import static com.koa.coremodule.notice.domain.entity.QNotice.notice; import static com.koa.coremodule.notice.domain.entity.QNoticeView.noticeView; @@ -58,11 +60,21 @@ public ViewType findViewYn(NoticeViewRequest request) { @Override public List findByCurriculum() { - return jpaQueryFactory.select(CurriculumProjection.CONSTRUCTOR_EXPRESSION) + final QNotice subNotice = new QNotice("sub"); + + return jpaQueryFactory + .selectDistinct(new QCurriculumProjection( + curriculum.id, + curriculum.curriculumName, + notice.title + )) .from(curriculum) - .join(notice).on(notice.curriculum.id.eq(curriculum.id)) - .join(member).on(member.id.eq(notice.member.id)) - .fetch(); + .leftJoin(notice).on(curriculum.id.eq(notice.curriculum.id) + .and(notice.createdAt.eq(JPAExpressions + .select(subNotice.createdAt.max()) + .from(subNotice) + .where(subNotice.curriculum.id.eq(notice.curriculum.id))) + )).fetch(); } @Override diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/projection/CurriculumProjection.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/projection/CurriculumProjection.java index 0a79b886..33f0c687 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/projection/CurriculumProjection.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/projection/CurriculumProjection.java @@ -1,29 +1,18 @@ package com.koa.coremodule.notice.domain.repository.projection; -import com.querydsl.core.types.ConstructorExpression; -import com.querydsl.core.types.Projections; -import lombok.AllArgsConstructor; -import lombok.Getter; +import com.querydsl.core.annotations.QueryProjection; +import lombok.Data; -import static com.koa.coremodule.member.domain.entity.QMember.member; -import static com.koa.coremodule.notice.domain.entity.QCurriculum.curriculum; -import static com.koa.coremodule.notice.domain.entity.QNotice.notice; - -@AllArgsConstructor -@Getter +@Data public class CurriculumProjection { - - public static final ConstructorExpression CONSTRUCTOR_EXPRESSION = - Projections.constructor(CurriculumProjection.class, - curriculum.id, - curriculum.curriculumName, - notice.title, - member.name - ); - private Long curriculumId; private String curriculumName; private String title; - private String name; + @QueryProjection + public CurriculumProjection(Long curriculumId, String curriculumName, String title) { + this.curriculumId = curriculumId; + this.curriculumName = curriculumName; + this.title = title; + } } From 916f61c1491230e560fc93963e0b35da6b024bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Thu, 23 Nov 2023 17:34:34 +0900 Subject: [PATCH 17/45] fix: controller & service layer --- .../command/api/NoticeController.java | 48 +++++++++++++++++++ .../service/NoticeFindUseCase.java | 12 +++-- .../domain/service/NoticeQueryService.java | 1 - 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java b/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java index b0895561..c2fbef00 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java @@ -1,16 +1,24 @@ package com.koa.apimodule.command.api; import com.koa.commonmodule.common.ApplicationResponse; +import com.koa.coremodule.member.domain.entity.Authority; import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.member.domain.repository.MemberRepository; import com.koa.coremodule.member.domain.utils.MemberUtils; import com.koa.coremodule.notice.application.dto.*; import com.koa.coremodule.notice.application.service.NoticeFindUseCase; import com.koa.coremodule.notice.application.service.NoticeSaveUseCase; +import com.koa.coremodule.notice.domain.entity.Curriculum; +import com.koa.coremodule.notice.domain.entity.NoticeTeam; +import com.koa.coremodule.notice.domain.repository.CurriculumRepository; +import com.koa.coremodule.notice.domain.repository.NoticeRepository; +import com.koa.coremodule.notice.domain.repository.NoticeTeamRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.annotation.PostConstruct; import java.util.List; @Slf4j @@ -22,6 +30,46 @@ public class NoticeController { private final NoticeFindUseCase noticeFindUseCase; private final NoticeSaveUseCase noticeSaveUseCase; private final MemberUtils memberUtils; + private final MemberRepository memberRepository; + private final NoticeTeamRepository noticeTeamRepository; + private final CurriculumRepository curriculumRepository; + private final NoticeRepository noticeRepository; + + @PostConstruct + public void test() { + final Member member = Member.builder() + .authority(Authority.MEMBER) + .email("austinan123@gmail.com") + .password("001215") + .name("안정후") + .build(); + memberRepository.save(member); + final Member member2 = Member.builder() + .authority(Authority.MEMBER) + .email("test@gmail.com") + .password("001215") + .name("test") + .build(); + memberRepository.save(member2); + + final Curriculum curriculum = Curriculum.builder() + .curriculumName("기업프로젝트1") + .build(); + curriculumRepository.save(curriculum); + final Curriculum curriculum2 = Curriculum.builder() + .curriculumName("기업프로젝트2") + .build(); + curriculumRepository.save(curriculum2); + final Curriculum curriculum3 = Curriculum.builder() + .curriculumName("기업프로젝트3") + .build(); + curriculumRepository.save(curriculum3); + + final NoticeTeam noticeTeam = NoticeTeam.builder() + .teamName("경영총괄팀") + .build(); + noticeTeamRepository.save(noticeTeam); + } /** * 공지 전체 조회 diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java index db591b94..362c021e 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java @@ -3,6 +3,7 @@ import com.koa.coremodule.notice.application.dto.CurriculumListResponse; import com.koa.coremodule.notice.application.dto.CurriculumResponse; import com.koa.coremodule.notice.application.dto.NoticeListResponse; +import com.koa.coremodule.notice.application.mapper.CurriculumMapper; import com.koa.coremodule.notice.application.mapper.NoticeMapper; import com.koa.coremodule.notice.domain.entity.Notice; import com.koa.coremodule.notice.domain.repository.projection.CurriculumProjection; @@ -35,16 +36,21 @@ public List selectNotice(Long memberId) { public List selectCurriculum() { List projection = noticeQueryService.selectCurriculum(); - List response = noticeMapper.toCurriculumDTO(projection); - - return response; + return projection.stream().map(CurriculumMapper::toResponse).toList(); } public List selectCurriculumList(Long curriculumId) { List entityResponse = noticeQueryService.selectCurriculumList(curriculumId); + int size = entityResponse.size(); + List response = noticeMapper.toCurriculumListDTO(entityResponse); + for (int i = 0; i < size; i++) { + response.get(i).setNoticeId(entityResponse.get(i).getMember().getId()); + response.get(i).setDate(entityResponse.get(i).getCreatedAt()); + } + return response; } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java index 459ed888..19362ed8 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java @@ -5,7 +5,6 @@ import com.koa.coremodule.member.domain.repository.MemberRepository; import com.koa.coremodule.notice.application.dto.NoticeListResponse; import com.koa.coremodule.notice.application.dto.NoticeViewRequest; -import com.koa.coremodule.notice.application.dto.NoticeViewResponse; import com.koa.coremodule.notice.domain.entity.*; import com.koa.coremodule.notice.domain.exception.NoticeNotFoundException; import com.koa.coremodule.notice.domain.repository.CurriculumRepository; From 9ef909b40ed33d58164c990ab26793bc950bdfc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Thu, 23 Nov 2023 17:37:34 +0900 Subject: [PATCH 18/45] fix: test data delete --- .../command/api/NoticeController.java | 48 ------------------- 1 file changed, 48 deletions(-) diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java b/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java index c2fbef00..b0895561 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java @@ -1,24 +1,16 @@ package com.koa.apimodule.command.api; import com.koa.commonmodule.common.ApplicationResponse; -import com.koa.coremodule.member.domain.entity.Authority; import com.koa.coremodule.member.domain.entity.Member; -import com.koa.coremodule.member.domain.repository.MemberRepository; import com.koa.coremodule.member.domain.utils.MemberUtils; import com.koa.coremodule.notice.application.dto.*; import com.koa.coremodule.notice.application.service.NoticeFindUseCase; import com.koa.coremodule.notice.application.service.NoticeSaveUseCase; -import com.koa.coremodule.notice.domain.entity.Curriculum; -import com.koa.coremodule.notice.domain.entity.NoticeTeam; -import com.koa.coremodule.notice.domain.repository.CurriculumRepository; -import com.koa.coremodule.notice.domain.repository.NoticeRepository; -import com.koa.coremodule.notice.domain.repository.NoticeTeamRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import javax.annotation.PostConstruct; import java.util.List; @Slf4j @@ -30,46 +22,6 @@ public class NoticeController { private final NoticeFindUseCase noticeFindUseCase; private final NoticeSaveUseCase noticeSaveUseCase; private final MemberUtils memberUtils; - private final MemberRepository memberRepository; - private final NoticeTeamRepository noticeTeamRepository; - private final CurriculumRepository curriculumRepository; - private final NoticeRepository noticeRepository; - - @PostConstruct - public void test() { - final Member member = Member.builder() - .authority(Authority.MEMBER) - .email("austinan123@gmail.com") - .password("001215") - .name("안정후") - .build(); - memberRepository.save(member); - final Member member2 = Member.builder() - .authority(Authority.MEMBER) - .email("test@gmail.com") - .password("001215") - .name("test") - .build(); - memberRepository.save(member2); - - final Curriculum curriculum = Curriculum.builder() - .curriculumName("기업프로젝트1") - .build(); - curriculumRepository.save(curriculum); - final Curriculum curriculum2 = Curriculum.builder() - .curriculumName("기업프로젝트2") - .build(); - curriculumRepository.save(curriculum2); - final Curriculum curriculum3 = Curriculum.builder() - .curriculumName("기업프로젝트3") - .build(); - curriculumRepository.save(curriculum3); - - final NoticeTeam noticeTeam = NoticeTeam.builder() - .teamName("경영총괄팀") - .build(); - noticeTeamRepository.save(noticeTeam); - } /** * 공지 전체 조회 From 75e051be3b2e0e0b17d2597099abcf5925a3d890 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Thu, 23 Nov 2023 22:47:54 +0900 Subject: [PATCH 19/45] =?UTF-8?q?refactor=20:=20=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/application/service/CommentGetUseCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentGetUseCase.java b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentGetUseCase.java index 5ecbfb7b..57f66b52 100644 --- a/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentGetUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/comment/application/service/CommentGetUseCase.java @@ -65,7 +65,7 @@ private Map createCommentMemberDetailMap(Long id, Fun final Map memberDetailMap = memberDetailList.stream() .collect(Collectors.toMap(memberDetail -> memberDetail.getMember().getId(), memberDetail -> memberDetail)); final Map commentMemberDetailMap = commentList.stream() - .sorted(Comparator.comparing(Comment::getCreatedAt).reversed()) + .sorted(Comparator.comparing(Comment::getCreatedAt)) .collect(Collectors.toMap( comment -> comment, comment -> memberDetailMap.get(comment.getWriter().getId()), From 31a090c7a7e8b8367d864ce7adf6f76c2573ded0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Fri, 24 Nov 2023 10:09:56 +0900 Subject: [PATCH 20/45] =?UTF-8?q?fix:=20=EA=B3=B5=EC=A7=80=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/NoticeDetailListResponse.java | 24 +++++++++++++++++++ .../application/mapper/NoticeMapper.java | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 core-module/src/main/java/com/koa/coremodule/notice/application/dto/NoticeDetailListResponse.java diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/NoticeDetailListResponse.java b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/NoticeDetailListResponse.java new file mode 100644 index 00000000..50511845 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/NoticeDetailListResponse.java @@ -0,0 +1,24 @@ +package com.koa.coremodule.notice.application.dto; + +import java.time.LocalDate; + +public record NoticeDetailListResponse(Long noticeId, + String writer, + String profileImage, + String curriculum, + String team, + String title, + String content, + String imageUrl, + LocalDate date, + Boolean viewYn) { + + public NoticeDetailListResponse { + if (viewYn == null) viewYn = false; + } + + public NoticeDetailListResponse withViewYn(Boolean newViewYn) { + return new NoticeDetailListResponse(noticeId, writer, profileImage, curriculum, team, title, content, imageUrl, date, newViewYn); + } + +} diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java b/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java index da657cac..cf033a50 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java @@ -3,6 +3,7 @@ import com.koa.coremodule.notice.application.dto.*; import com.koa.coremodule.notice.domain.entity.Notice; import com.koa.coremodule.notice.domain.repository.projection.CurriculumProjection; +import com.koa.coremodule.notice.domain.repository.projection.NoticeDetailListProjection; import com.koa.coremodule.notice.domain.repository.projection.NoticeListProjection; import org.mapstruct.*; @@ -62,6 +63,6 @@ public interface NoticeMapper { @Mapping(source = "teamName", target = "team"), @Mapping(source = "date", target = "date") }) - NoticeListResponse toNoticeDetailDTO(NoticeListProjection projection); + NoticeDetailListResponse toNoticeDetailDTO(NoticeDetailListProjection projection); } From 94f83ea817c10ce0fbbfdb7564497f75dc7ed94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Fri, 24 Nov 2023 10:10:14 +0900 Subject: [PATCH 21/45] =?UTF-8?q?fix:=20notice=20deail=20repository=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/NoticeDynamicRepository.java | 3 +- .../NoticeDynamicRepositoryImpl.java | 13 +++-- .../NoticeDetailListProjection.java | 56 +++++++++++++++++++ .../projection/NoticeListProjection.java | 2 + 4 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 core-module/src/main/java/com/koa/coremodule/notice/domain/repository/projection/NoticeDetailListProjection.java diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepository.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepository.java index 337b9374..0c72192b 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepository.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepository.java @@ -4,6 +4,7 @@ import com.koa.coremodule.notice.domain.entity.Notice; import com.koa.coremodule.notice.domain.entity.ViewType; import com.koa.coremodule.notice.domain.repository.projection.CurriculumProjection; +import com.koa.coremodule.notice.domain.repository.projection.NoticeDetailListProjection; import com.koa.coremodule.notice.domain.repository.projection.NoticeListProjection; import java.util.List; @@ -12,7 +13,7 @@ public interface NoticeDynamicRepository { List findAllNotice(); - NoticeListProjection findAllNoticeDetail(Long noticeId); + NoticeDetailListProjection findAllNoticeDetail(Long noticeId); ViewType findViewYn(NoticeViewRequest request); diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java index 8ae8c739..99d78e00 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/NoticeDynamicRepositoryImpl.java @@ -4,16 +4,15 @@ import com.koa.coremodule.notice.domain.entity.Notice; import com.koa.coremodule.notice.domain.entity.QNotice; import com.koa.coremodule.notice.domain.entity.ViewType; -import com.koa.coremodule.notice.domain.repository.projection.CurriculumProjection; -import com.koa.coremodule.notice.domain.repository.projection.NoticeListProjection; -import com.koa.coremodule.notice.domain.repository.projection.QCurriculumProjection; -import com.koa.coremodule.notice.domain.repository.projection.QNoticeListProjection; +import com.koa.coremodule.notice.domain.repository.projection.*; import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; import java.util.List; +import static com.koa.coremodule.member.domain.entity.QMember.member; +import static com.koa.coremodule.member.domain.entity.QMemberDetail.memberDetail; import static com.koa.coremodule.notice.domain.entity.QCurriculum.curriculum; import static com.koa.coremodule.notice.domain.entity.QNotice.notice; import static com.koa.coremodule.notice.domain.entity.QNoticeView.noticeView; @@ -41,9 +40,11 @@ public List findAllNotice() { } @Override - public NoticeListProjection findAllNoticeDetail(Long noticeId) { - return jpaQueryFactory.select(NoticeListProjection.CONSTRUCTOR_EXPRESSION) + public NoticeDetailListProjection findAllNoticeDetail(Long noticeId) { + return jpaQueryFactory.select(NoticeDetailListProjection.CONSTRUCTOR_EXPRESSION) .from(notice) + .join(member).on(notice.member.id.eq(member.id)) + .join(memberDetail).on(memberDetail.member.id.eq(member.id)) .where(notice.id.eq(noticeId)) .orderBy(notice.createdAt.desc()) .fetchOne(); diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/projection/NoticeDetailListProjection.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/projection/NoticeDetailListProjection.java new file mode 100644 index 00000000..abb5df92 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/projection/NoticeDetailListProjection.java @@ -0,0 +1,56 @@ +package com.koa.coremodule.notice.domain.repository.projection; + +import com.querydsl.core.annotations.QueryProjection; +import com.querydsl.core.types.ConstructorExpression; +import com.querydsl.core.types.Projections; +import lombok.Getter; + +import java.time.LocalDateTime; + +import static com.koa.coremodule.member.domain.entity.QMember.member; +import static com.koa.coremodule.member.domain.entity.QMemberDetail.memberDetail; +import static com.koa.coremodule.notice.domain.entity.QCurriculum.curriculum; +import static com.koa.coremodule.notice.domain.entity.QNotice.notice; +import static com.koa.coremodule.notice.domain.entity.QNoticeImage.noticeImage; +import static com.koa.coremodule.notice.domain.entity.QNoticeTeam.noticeTeam; + + +@Getter +public class NoticeDetailListProjection { + + public static final ConstructorExpression CONSTRUCTOR_EXPRESSION = + Projections.constructor(NoticeDetailListProjection.class, + notice.id, + member.name, + memberDetail.profileImage, + notice.title, + notice.content, + notice.createdAt, + noticeImage.imageUrl, + curriculum.curriculumName, + noticeTeam.teamName + ); + + private final Long noticeId; + private final String name; + private final String profileImage; + private final String title; + private final String content; + private final LocalDateTime date; + private final String imageUrl; + private final String curriculumName; + private final String teamName; + + @QueryProjection + public NoticeDetailListProjection(Long noticeId, String name, String profileImage, String title, String content, LocalDateTime date, String imageUrl, String curriculumName, String teamName) { + this.noticeId = noticeId; + this.name = name; + this.profileImage = profileImage; + this.title = title; + this.content = content; + this.date = date; + this.imageUrl = imageUrl; + this.curriculumName = curriculumName; + this.teamName = teamName; + } +} diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/projection/NoticeListProjection.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/projection/NoticeListProjection.java index ab5a2cba..7e78f376 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/projection/NoticeListProjection.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/repository/projection/NoticeListProjection.java @@ -7,6 +7,8 @@ import java.time.LocalDateTime; +import static com.koa.coremodule.member.domain.entity.QMember.member; +import static com.koa.coremodule.member.domain.entity.QMemberDetail.memberDetail; import static com.koa.coremodule.notice.domain.entity.QCurriculum.curriculum; import static com.koa.coremodule.notice.domain.entity.QNotice.notice; import static com.koa.coremodule.notice.domain.entity.QNoticeImage.noticeImage; From 67171f18690dc1c30fc24e54575d056fca0836e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Fri, 24 Nov 2023 10:10:38 +0900 Subject: [PATCH 22/45] =?UTF-8?q?fix:=20noticeId=20=EB=84=A3=EA=B8=B0=20&?= =?UTF-8?q?=20logics=20changed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../koa/apimodule/command/api/NoticeController.java | 4 ++-- .../application/service/NoticeFindUseCase.java | 2 +- .../application/service/NoticeSaveUseCase.java | 12 +++++------- .../notice/domain/service/NoticeQueryService.java | 5 +++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java b/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java index b0895561..9eef7081 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/NoticeController.java @@ -101,12 +101,12 @@ public ApplicationResponse deleteNotice( * 공지 상세 조회 (내용) */ @GetMapping(value = "/{noticeId}/detail") - public ApplicationResponse noticeDetail( + public ApplicationResponse noticeDetail( @PathVariable Long noticeId) { Member memberRequest = memberUtils.getAccessMember(); - NoticeListResponse response = noticeSaveUseCase.selectNoticeDetail(memberRequest.getId(), noticeId); + NoticeDetailListResponse response = noticeSaveUseCase.selectNoticeDetail(memberRequest.getId(), noticeId); return ApplicationResponse.ok(response, "공지 상세 조회에 성공했습니다."); } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java index 362c021e..ce9c999c 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java @@ -47,7 +47,7 @@ public List selectCurriculumList(Long curriculumId) { List response = noticeMapper.toCurriculumListDTO(entityResponse); for (int i = 0; i < size; i++) { - response.get(i).setNoticeId(entityResponse.get(i).getMember().getId()); + response.get(i).setNoticeId(entityResponse.get(i).getId()); response.get(i).setDate(entityResponse.get(i).getCreatedAt()); } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeSaveUseCase.java b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeSaveUseCase.java index f35a3e96..50c6745e 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeSaveUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeSaveUseCase.java @@ -3,16 +3,14 @@ import com.koa.commonmodule.exception.Error; import com.koa.coremodule.image.service.AwsS3Service; import com.koa.coremodule.member.domain.entity.Member; -import com.koa.coremodule.notice.application.dto.NoticeListResponse; -import com.koa.coremodule.notice.application.dto.NoticeRequest; -import com.koa.coremodule.notice.application.dto.NoticeUpdateRequest; -import com.koa.coremodule.notice.application.dto.NoticeViewResponse; +import com.koa.coremodule.notice.application.dto.*; import com.koa.coremodule.notice.application.mapper.NoticeMapper; import com.koa.coremodule.notice.domain.entity.Curriculum; import com.koa.coremodule.notice.domain.entity.Notice; import com.koa.coremodule.notice.domain.entity.NoticeTeam; import com.koa.coremodule.notice.domain.entity.ViewType; import com.koa.coremodule.notice.domain.exception.NoticeNotFoundException; +import com.koa.coremodule.notice.domain.repository.projection.NoticeDetailListProjection; import com.koa.coremodule.notice.domain.repository.projection.NoticeListProjection; import com.koa.coremodule.notice.domain.service.NoticeDeleteService; import com.koa.coremodule.notice.domain.service.NoticeQueryService; @@ -96,10 +94,10 @@ public void deleteNotice(Long noticeId) { noticeDeleteService.deleteNoticeBySingleNoticeId(noticeId); } - public NoticeListResponse selectNoticeDetail(Long memberId, Long noticeId) { + public NoticeDetailListResponse selectNoticeDetail(Long memberId, Long noticeId) { - NoticeListProjection projection = noticeQueryService.selectNoticeDetail(noticeId); - NoticeListResponse response = noticeMapper.toNoticeDetailDTO(projection); + NoticeDetailListProjection projection = noticeQueryService.selectNoticeDetail(noticeId); + NoticeDetailListResponse response = noticeMapper.toNoticeDetailDTO(projection); // 조회 여부 기록 업데이트 ViewType viewResponse = noticeQueryService.findSingleViewType(noticeId, memberId); diff --git a/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java b/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java index 19362ed8..8b2a8b4e 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/domain/service/NoticeQueryService.java @@ -12,6 +12,7 @@ import com.koa.coremodule.notice.domain.repository.NoticeTeamRepository; import com.koa.coremodule.notice.domain.repository.NoticeViewRepository; import com.koa.coremodule.notice.domain.repository.projection.CurriculumProjection; +import com.koa.coremodule.notice.domain.repository.projection.NoticeDetailListProjection; import com.koa.coremodule.notice.domain.repository.projection.NoticeListProjection; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -81,9 +82,9 @@ public Notice save(Notice notice) { return noticeRepository.save(notice); } - public NoticeListProjection selectNoticeDetail(Long noticeId) { + public NoticeDetailListProjection selectNoticeDetail(Long noticeId) { - NoticeListProjection projection = noticeRepository.findAllNoticeDetail(noticeId); + NoticeDetailListProjection projection = noticeRepository.findAllNoticeDetail(noticeId); return projection; } From 99ee818f41a586dbd7c758bb6bcd51557999f509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Fri, 24 Nov 2023 10:23:02 +0900 Subject: [PATCH 23/45] =?UTF-8?q?fix:=20=EB=82=A0=EC=A7=9C=20=ED=98=95?= =?UTF-8?q?=EC=8B=9D=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dto/CurriculumListResponse.java | 4 ++-- .../application/service/NoticeFindUseCase.java | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumListResponse.java b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumListResponse.java index 345aa785..5c843556 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumListResponse.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/CurriculumListResponse.java @@ -4,7 +4,7 @@ import lombok.Data; import lombok.extern.jackson.Jacksonized; -import java.time.LocalDateTime; +import java.time.LocalDate; @Data @Builder @@ -14,6 +14,6 @@ public class CurriculumListResponse { private Long noticeId; private String title; private String content; - private LocalDateTime date; + private LocalDate date; } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java index ce9c999c..776e17b1 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFindUseCase.java @@ -13,6 +13,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.List; @Service @@ -48,10 +50,18 @@ public List selectCurriculumList(Long curriculumId) { for (int i = 0; i < size; i++) { response.get(i).setNoticeId(entityResponse.get(i).getId()); - response.get(i).setDate(entityResponse.get(i).getCreatedAt()); + response.get(i).setDate(convertDateString(entityResponse.get(i).getCreatedAt().toString())); } return response; } + private LocalDate convertDateString(String dateString) { + + String datePart = dateString.substring(0, 10); + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + return LocalDate.parse(datePart, formatter); + } + } From 0e913cda0930b5df6e44170eca2485d17e18dcff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Fri, 24 Nov 2023 10:48:56 +0900 Subject: [PATCH 24/45] fix: report logics save --- .../application/service/ReportSaveUseCase.java | 12 ++++++++++-- .../report/domain/entity/Report.java | 1 + .../domain/service/ReportQueryService.java | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/report/application/service/ReportSaveUseCase.java b/core-module/src/main/java/com/koa/coremodule/report/application/service/ReportSaveUseCase.java index 752ed878..76006841 100644 --- a/core-module/src/main/java/com/koa/coremodule/report/application/service/ReportSaveUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/report/application/service/ReportSaveUseCase.java @@ -1,11 +1,13 @@ package com.koa.coremodule.report.application.service; import com.koa.commonmodule.exception.Error; -import com.koa.coremodule.report.domain.entity.Report; +import com.koa.coremodule.comment.domain.entity.Comment; +import com.koa.coremodule.member.domain.entity.Member; import com.koa.coremodule.report.application.dto.ReportRequest; +import com.koa.coremodule.report.application.mapper.ReportMapper; +import com.koa.coremodule.report.domain.entity.Report; import com.koa.coremodule.report.domain.exception.ReportException; import com.koa.coremodule.report.domain.service.ReportQueryService; -import com.koa.coremodule.report.application.mapper.ReportMapper; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -28,6 +30,12 @@ public Long createReport(ReportRequest request) { throw new ReportException(Error.DUPLICATE_REPORT); } else { Report reportEntity = reportMapper.toReportEntity(request); + + Member member = reportQueryService.findMember(request.getMemberId()); + Comment comment = reportQueryService.findComment(request.getCommentId()); + reportEntity.setMember(member); + reportEntity.setComment(comment); + Report savedReport = reportQueryService.save(reportEntity); return savedReport.getId(); } diff --git a/core-module/src/main/java/com/koa/coremodule/report/domain/entity/Report.java b/core-module/src/main/java/com/koa/coremodule/report/domain/entity/Report.java index ed9d1d31..d2f8489d 100644 --- a/core-module/src/main/java/com/koa/coremodule/report/domain/entity/Report.java +++ b/core-module/src/main/java/com/koa/coremodule/report/domain/entity/Report.java @@ -7,6 +7,7 @@ @Builder @Getter +@Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @Entity diff --git a/core-module/src/main/java/com/koa/coremodule/report/domain/service/ReportQueryService.java b/core-module/src/main/java/com/koa/coremodule/report/domain/service/ReportQueryService.java index ed3cce71..615a55ad 100644 --- a/core-module/src/main/java/com/koa/coremodule/report/domain/service/ReportQueryService.java +++ b/core-module/src/main/java/com/koa/coremodule/report/domain/service/ReportQueryService.java @@ -1,5 +1,11 @@ package com.koa.coremodule.report.domain.service; +import com.koa.commonmodule.exception.BusinessException; +import com.koa.commonmodule.exception.Error; +import com.koa.coremodule.comment.domain.entity.Comment; +import com.koa.coremodule.comment.domain.repository.CommentRepository; +import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.member.domain.repository.MemberRepository; import com.koa.coremodule.report.domain.entity.Report; import com.koa.coremodule.report.domain.repository.ReportRepository; import lombok.RequiredArgsConstructor; @@ -12,6 +18,8 @@ public class ReportQueryService { private final ReportRepository reportRepository; + private final MemberRepository memberRepository; + private final CommentRepository commentRepository; public Optional findByIds(Long memberId, Long commentId) { @@ -22,4 +30,14 @@ public Report save(Report report) { return reportRepository.save(report); } + + public Member findMember(Long memberId) { + + return memberRepository.findById(memberId).orElseThrow(() -> new BusinessException(Error.MEMBER_NOT_FOUND)); + } + + public Comment findComment(Long commentId) { + + return commentRepository.findById(commentId).orElseThrow(() -> new BusinessException(Error.COMMENT_NOT_FOUND)); + } } From b1ad6bb3636ad5ac6db02f3a94e22bdd29a2b643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Fri, 24 Nov 2023 11:37:50 +0900 Subject: [PATCH 25/45] =?UTF-8?q?fix:=20mapping=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/application/dto/NoticeDetailListResponse.java | 4 ++-- .../notice/application/dto/NoticeListResponse.java | 6 +++--- .../coremodule/notice/application/mapper/NoticeMapper.java | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/NoticeDetailListResponse.java b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/NoticeDetailListResponse.java index 50511845..312f3781 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/NoticeDetailListResponse.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/NoticeDetailListResponse.java @@ -3,7 +3,7 @@ import java.time.LocalDate; public record NoticeDetailListResponse(Long noticeId, - String writer, + String name, String profileImage, String curriculum, String team, @@ -18,7 +18,7 @@ public record NoticeDetailListResponse(Long noticeId, } public NoticeDetailListResponse withViewYn(Boolean newViewYn) { - return new NoticeDetailListResponse(noticeId, writer, profileImage, curriculum, team, title, content, imageUrl, date, newViewYn); + return new NoticeDetailListResponse(noticeId, name, profileImage, curriculum, team, title, content, imageUrl, date, newViewYn); } } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/NoticeListResponse.java b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/NoticeListResponse.java index 27e6fe15..e9f5a52a 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/dto/NoticeListResponse.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/dto/NoticeListResponse.java @@ -3,8 +3,8 @@ import java.time.LocalDate; public record NoticeListResponse(Long noticeId, - String curriculum, - String team, + String curriculumName, + String teamName, String title, String content, String imageUrl, @@ -16,7 +16,7 @@ public record NoticeListResponse(Long noticeId, } public NoticeListResponse withViewYn(Boolean newViewYn) { - return new NoticeListResponse(noticeId, curriculum, team, title, content, imageUrl, date, newViewYn); + return new NoticeListResponse(noticeId, curriculumName, teamName, title, content, imageUrl, date, newViewYn); } } diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java b/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java index cf033a50..d8453381 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/mapper/NoticeMapper.java @@ -22,8 +22,8 @@ public interface NoticeMapper { @Mapping(source = "title", target = "title"), @Mapping(source = "content", target = "content"), @Mapping(source = "imageUrl", target = "imageUrl"), - @Mapping(source = "curriculumName", target = "curriculum"), - @Mapping(source = "teamName", target = "team"), + @Mapping(source = "curriculumName", target = "curriculumName"), + @Mapping(source = "teamName", target = "teamName"), @Mapping(source = "date", target = "date") }) List toNoticeListDTO(List notice); @@ -56,6 +56,8 @@ public interface NoticeMapper { @Mappings({ @Mapping(source = "noticeId", target = "noticeId"), + @Mapping(source = "name", target = "name"), + @Mapping(source = "profileImage", target = "profileImage"), @Mapping(source = "title", target = "title"), @Mapping(source = "content", target = "content"), @Mapping(source = "imageUrl", target = "imageUrl"), From a6b7b1a89513e618aa1fafc95a45ee4e76899203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Mon, 20 Nov 2023 14:57:21 +0900 Subject: [PATCH 26/45] feat: vote request dto --- .../vote/application/dto/VoteItemRequest.java | 13 +++++++++++++ .../vote/application/dto/VoteRequest.java | 6 ++++++ 2 files changed, 19 insertions(+) create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteItemRequest.java create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteRequest.java diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteItemRequest.java b/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteItemRequest.java new file mode 100644 index 00000000..62993406 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteItemRequest.java @@ -0,0 +1,13 @@ +package com.koa.coremodule.vote.application.dto; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class VoteItemRequest { + + private Long voteItemId; + private Long memberId; + +} diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteRequest.java b/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteRequest.java new file mode 100644 index 00000000..fd776bd3 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteRequest.java @@ -0,0 +1,6 @@ +package com.koa.coremodule.vote.application.dto; + +import java.util.ArrayList; + +public record VoteRequest(String title, ArrayList item) { +} From 00f51ac4f4dae2b58d64c3b65275302693195fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Mon, 20 Nov 2023 14:57:45 +0900 Subject: [PATCH 27/45] feat: controller & usecase service layer --- .../apimodule/command/api/VoteController.java | 39 ++++++++++++++ .../application/service/VoteSaveUseCase.java | 52 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java b/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java new file mode 100644 index 00000000..81c347c6 --- /dev/null +++ b/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java @@ -0,0 +1,39 @@ +package com.koa.apimodule.command.api; + +import com.koa.commonmodule.common.ApplicationResponse; +import com.koa.coremodule.vote.application.dto.VoteRequest; +import com.koa.coremodule.vote.application.service.VoteSaveUseCase; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Slf4j +@RestController +@RequiredArgsConstructor +@RequestMapping("/v1/vote") +public class VoteController { + + public final VoteSaveUseCase voteSaveUseCase; + + /** + * 투표 생성 + */ + @PostMapping(value = "") + public ApplicationResponse makeVote(@RequestBody VoteRequest voteRequest) { + + Long voteId = voteSaveUseCase.saveVote(voteRequest); + return ApplicationResponse.ok(voteId, "투표 생성을 완료했습니다."); + } + + /** + * 투표 현황 조회 - 명단까지 리스트로 전달 필요 + */ + + /** + * 투표 참여 + */ + +} diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java new file mode 100644 index 00000000..35c28b45 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java @@ -0,0 +1,52 @@ +package com.koa.coremodule.vote.application.service; + +import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.member.domain.utils.MemberUtils; +import com.koa.coremodule.vote.application.dto.VoteItemRequest; +import com.koa.coremodule.vote.application.dto.VoteRequest; +import com.koa.coremodule.vote.application.mapper.VoteMapper; +import com.koa.coremodule.vote.domain.entity.Vote; +import com.koa.coremodule.vote.domain.entity.VoteItem; +import com.koa.coremodule.vote.domain.entity.VoteItemRecord; +import com.koa.coremodule.vote.domain.service.VoteSaveService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class VoteSaveUseCase { + + private final MemberUtils memberUtils; + private final VoteSaveService voteSaveService; + private final VoteMapper voteMapper; + + public Long saveVote(VoteRequest voteRequest) { + + Member memberRequest = memberUtils.getAccessMember(); + + // 투표 제목 저장 + Vote voteEntity = voteMapper.toVoteEntity(voteRequest.title()); + Vote vote = voteSaveService.saveVote(voteEntity); + + // 투표 항목 개수 체크 후 각자 저장 + List titles = voteRequest.item(); + for(String i : titles) { + + VoteItem voteItemEntity = voteMapper.toVoteItemEntity(i); + VoteItem voteItem = voteSaveService.saveVoteItem(voteItemEntity); + + VoteItemRequest voteItemRequest = VoteItemRequest.builder() + .memberId(memberRequest.getId()) + .voteItemId(voteItem.getId()) + .build(); + + VoteItemRecord voteItemRecordRequest = voteMapper.toVoteRecordEntity(voteItemRequest); + VoteItemRecord voteItemRecord = voteSaveService.saveVoteRecord(voteItemRecordRequest); + } + + return vote.getId(); + } + +} From d068b0070ede3c6471025a67ea8157aca4694ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Mon, 20 Nov 2023 14:57:56 +0900 Subject: [PATCH 28/45] feat: entity relations --- .../coremodule/vote/domain/entity/Vote.java | 2 +- .../vote/domain/entity/VoteItem.java | 2 +- .../vote/domain/entity/VoteItemRecord.java | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItemRecord.java diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java index 5b02b1fa..ef2256bb 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java @@ -19,7 +19,7 @@ public class Vote extends BaseEntity { private String voteTitle; - @ManyToOne(fetch = FetchType.LAZY) + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "notice_id") private Notice notice; } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java index 092733bd..3b03445a 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java @@ -1,6 +1,7 @@ package com.koa.coremodule.vote.domain.entity; import com.koa.commonmodule.domain.BaseEntity; +import com.koa.coremodule.member.domain.entity.Member; import jakarta.persistence.*; import lombok.*; @@ -17,7 +18,6 @@ public class VoteItem extends BaseEntity { private Long id; private String voteItemName; - private Integer count; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "vote_id") diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItemRecord.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItemRecord.java new file mode 100644 index 00000000..4101244e --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItemRecord.java @@ -0,0 +1,28 @@ +package com.koa.coremodule.vote.domain.entity; + +import com.koa.commonmodule.domain.BaseEntity; +import com.koa.coremodule.member.domain.entity.Member; +import jakarta.persistence.*; +import lombok.*; + +@Builder +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@Entity +public class VoteItemRecord extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "vote_item_record_id") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "vote_item_id") + private VoteItem voteItem; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + +} From ec9d6d6eed5d857d7c54edba9ab7ae324c2e5f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Mon, 20 Nov 2023 14:58:19 +0900 Subject: [PATCH 29/45] feat: mapper & service layer --- .../vote/application/mapper/VoteMapper.java | 38 +++++++++++++++++++ .../vote/domain/service/VoteSaveService.java | 32 ++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/application/mapper/VoteMapper.java create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteSaveService.java diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/mapper/VoteMapper.java b/core-module/src/main/java/com/koa/coremodule/vote/application/mapper/VoteMapper.java new file mode 100644 index 00000000..d9a55656 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/mapper/VoteMapper.java @@ -0,0 +1,38 @@ +package com.koa.coremodule.vote.application.mapper; + +import com.koa.coremodule.notice.application.dto.CurriculumListResponse; +import com.koa.coremodule.notice.domain.entity.Notice; +import com.koa.coremodule.vote.application.dto.VoteItemRequest; +import com.koa.coremodule.vote.domain.entity.Vote; +import com.koa.coremodule.vote.domain.entity.VoteItem; +import com.koa.coremodule.vote.domain.entity.VoteItemRecord; +import org.mapstruct.*; + +import java.util.List; + +@Mapper( + componentModel = MappingConstants.ComponentModel.SPRING, + unmappedTargetPolicy = ReportingPolicy.IGNORE, + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, + uses = Vote.class +) +public interface VoteMapper { + + @Mappings({ + @Mapping(source = "title", target = "title") + }) + Vote toVoteEntity(String title); + + @Mappings({ + @Mapping(source = "voteItemName", target = "name") + }) + VoteItem toVoteItemEntity(String name); + + @Mappings({ + @Mapping(source = "memberId", target = "memberId"), + @Mapping(source = "voteItemId", target = "voteItemId"), + }) + VoteItemRecord toVoteRecordEntity(VoteItemRequest voteItemRequest); + + +} diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteSaveService.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteSaveService.java new file mode 100644 index 00000000..c256b31c --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteSaveService.java @@ -0,0 +1,32 @@ +package com.koa.coremodule.vote.domain.service; + +import com.koa.coremodule.vote.domain.entity.Vote; +import com.koa.coremodule.vote.domain.entity.VoteItem; +import com.koa.coremodule.vote.domain.entity.VoteItemRecord; +import com.koa.coremodule.vote.domain.repository.VoteItemRepository; +import com.koa.coremodule.vote.domain.repository.VoteRecordRepository; +import com.koa.coremodule.vote.domain.repository.VoteRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class VoteSaveService { + + private final VoteRepository voteRepository; + private final VoteRecordRepository voteRecordRepository; + private final VoteItemRepository voteItemRepository; + + public Vote saveVote(Vote vote) { + return voteRepository.save(vote); + } + + public VoteItem saveVoteItem(VoteItem voteItem) { + return voteItemRepository.save(voteItem); + } + + public VoteItemRecord saveVoteRecord(VoteItemRecord voteItemRecord) { + return voteRecordRepository.save(voteItemRecord); + } + +} From 27ce0b44125963b8d1af82fed18e272fa06b57c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Mon, 20 Nov 2023 14:58:32 +0900 Subject: [PATCH 30/45] feat: related vote repositories --- .../vote/domain/repository/VoteItemRepository.java | 7 +++++++ .../vote/domain/repository/VoteRecordRepository.java | 7 +++++++ .../coremodule/vote/domain/repository/VoteRepository.java | 7 +++++++ 3 files changed, 21 insertions(+) create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteItemRepository.java create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRecordRepository.java create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRepository.java diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteItemRepository.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteItemRepository.java new file mode 100644 index 00000000..5fc8a839 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteItemRepository.java @@ -0,0 +1,7 @@ +package com.koa.coremodule.vote.domain.repository; + +import com.koa.coremodule.vote.domain.entity.VoteItem; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface VoteItemRepository extends JpaRepository { +} diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRecordRepository.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRecordRepository.java new file mode 100644 index 00000000..4f2d78d9 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRecordRepository.java @@ -0,0 +1,7 @@ +package com.koa.coremodule.vote.domain.repository; + +import com.koa.coremodule.vote.domain.entity.VoteItemRecord; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface VoteRecordRepository extends JpaRepository { +} diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRepository.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRepository.java new file mode 100644 index 00000000..14ba1abb --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRepository.java @@ -0,0 +1,7 @@ +package com.koa.coremodule.vote.domain.repository; + +import com.koa.coremodule.vote.domain.entity.Vote; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface VoteRepository extends JpaRepository { +} From bcf4edeedce5dccabe4dbfb63430513653c11158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Mon, 27 Nov 2023 17:08:09 +0900 Subject: [PATCH 31/45] feat: related vote mapper --- .../mapper/VoteItemRecordMapper.java | 17 +++++++++++++++++ .../vote/application/mapper/VoteMapper.java | 11 ++--------- 2 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/application/mapper/VoteItemRecordMapper.java diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/mapper/VoteItemRecordMapper.java b/core-module/src/main/java/com/koa/coremodule/vote/application/mapper/VoteItemRecordMapper.java new file mode 100644 index 00000000..970ba0bf --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/mapper/VoteItemRecordMapper.java @@ -0,0 +1,17 @@ +package com.koa.coremodule.vote.application.mapper; + +import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.vote.domain.entity.VoteItem; +import com.koa.coremodule.vote.domain.entity.VoteItemRecord; + +public final class VoteItemRecordMapper { + private VoteItemRecordMapper() { + } + + public static VoteItemRecord toVoteItemRecord(VoteItem item, Member member) { + return VoteItemRecord.builder() + .voteItem(item) + .member(member) + .build(); + } +} diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/mapper/VoteMapper.java b/core-module/src/main/java/com/koa/coremodule/vote/application/mapper/VoteMapper.java index d9a55656..86e8c727 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/application/mapper/VoteMapper.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/mapper/VoteMapper.java @@ -19,20 +19,13 @@ public interface VoteMapper { @Mappings({ - @Mapping(source = "title", target = "title") + @Mapping(source = "title", target = "voteTitle") }) Vote toVoteEntity(String title); @Mappings({ - @Mapping(source = "voteItemName", target = "name") + @Mapping(source = "name", target = "voteItemName") }) VoteItem toVoteItemEntity(String name); - @Mappings({ - @Mapping(source = "memberId", target = "memberId"), - @Mapping(source = "voteItemId", target = "voteItemId"), - }) - VoteItemRecord toVoteRecordEntity(VoteItemRequest voteItemRequest); - - } From a291aea438ae5549fc8886950818132dfed5481e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Mon, 27 Nov 2023 17:08:39 +0900 Subject: [PATCH 32/45] fix: vote entity --- .../koa/coremodule/vote/domain/entity/Vote.java | 14 ++++++++++++++ .../coremodule/vote/domain/entity/VoteItem.java | 10 ++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java index ef2256bb..f1ca4db7 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java @@ -5,6 +5,9 @@ import jakarta.persistence.*; import lombok.*; +import java.util.ArrayList; +import java.util.List; + @Builder @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -19,7 +22,18 @@ public class Vote extends BaseEntity { private String voteTitle; + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "vote") + private List voteItems = new ArrayList<>(); + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "notice_id") private Notice notice; + + public void setVoteItems(List voteItems) { + this.voteItems = voteItems; + } + + public void setNotice(Notice notice) { + this.notice = notice; + } } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java index 3b03445a..1e550bee 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java @@ -1,7 +1,6 @@ package com.koa.coremodule.vote.domain.entity; import com.koa.commonmodule.domain.BaseEntity; -import com.koa.coremodule.member.domain.entity.Member; import jakarta.persistence.*; import lombok.*; @@ -17,9 +16,12 @@ public class VoteItem extends BaseEntity { @Column(name = "vote_item_id") private Long id; - private String voteItemName; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "vote_id") private Vote vote; + + private String voteItemName; + + public void setVote(Vote vote) { + this.vote = vote; + } } From e77a8b4b8a78fe9543ae395dfdcf080510aefb84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Mon, 27 Nov 2023 17:08:59 +0900 Subject: [PATCH 33/45] feat: vote controller & service layer --- .../apimodule/command/api/VoteController.java | 45 ++++++++++++++++++- .../vote/application/dto/VoteRequest.java | 2 +- .../application/service/VoteSaveUseCase.java | 33 +++++++++----- 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java b/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java index 81c347c6..6be52612 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java @@ -1,6 +1,15 @@ package com.koa.apimodule.command.api; import com.koa.commonmodule.common.ApplicationResponse; +import com.koa.coremodule.member.domain.entity.Authority; +import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.member.domain.repository.MemberRepository; +import com.koa.coremodule.notice.domain.entity.Curriculum; +import com.koa.coremodule.notice.domain.entity.Notice; +import com.koa.coremodule.notice.domain.entity.NoticeTeam; +import com.koa.coremodule.notice.domain.repository.CurriculumRepository; +import com.koa.coremodule.notice.domain.repository.NoticeRepository; +import com.koa.coremodule.notice.domain.repository.NoticeTeamRepository; import com.koa.coremodule.vote.application.dto.VoteRequest; import com.koa.coremodule.vote.application.service.VoteSaveUseCase; import lombok.RequiredArgsConstructor; @@ -10,18 +19,50 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.PostConstruct; + @Slf4j @RestController @RequiredArgsConstructor @RequestMapping("/v1/vote") public class VoteController { - public final VoteSaveUseCase voteSaveUseCase; + private final VoteSaveUseCase voteSaveUseCase; + private final MemberRepository memberRepository; + private final NoticeTeamRepository noticeTeamRepository; + private final CurriculumRepository curriculumRepository; + private final NoticeRepository noticeRepository; + + @PostConstruct + public void test() { + final Member member = Member.builder() + .authority(Authority.MEMBER) + .email("austinan123@gmail.com") + .password("001215") + .name("안정후") + .build(); + memberRepository.save(member); + final Curriculum curriculum = Curriculum.builder() + .curriculumName("기업프로젝트") + .build(); + curriculumRepository.save(curriculum); + final NoticeTeam noticeTeam = NoticeTeam.builder() + .teamName("경영총괄팀") + .build(); + noticeTeamRepository.save(noticeTeam); + final Notice notice = Notice.builder() + .member(member) + .title("sampletitle") + .content("samplecontent") + .curriculum(curriculum) + .build(); + noticeRepository.save(notice); + } /** * 투표 생성 */ - @PostMapping(value = "") + @PostMapping public ApplicationResponse makeVote(@RequestBody VoteRequest voteRequest) { Long voteId = voteSaveUseCase.saveVote(voteRequest); diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteRequest.java b/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteRequest.java index fd776bd3..ec63fc85 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteRequest.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteRequest.java @@ -2,5 +2,5 @@ import java.util.ArrayList; -public record VoteRequest(String title, ArrayList item) { +public record VoteRequest(Long noticeId, String title, ArrayList item) { } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java index 35c28b45..a266c8c5 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java @@ -2,8 +2,10 @@ import com.koa.coremodule.member.domain.entity.Member; import com.koa.coremodule.member.domain.utils.MemberUtils; -import com.koa.coremodule.vote.application.dto.VoteItemRequest; +import com.koa.coremodule.notice.domain.entity.Notice; +import com.koa.coremodule.notice.domain.service.NoticeQueryService; import com.koa.coremodule.vote.application.dto.VoteRequest; +import com.koa.coremodule.vote.application.mapper.VoteItemRecordMapper; import com.koa.coremodule.vote.application.mapper.VoteMapper; import com.koa.coremodule.vote.domain.entity.Vote; import com.koa.coremodule.vote.domain.entity.VoteItem; @@ -12,6 +14,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; @Service @@ -20,31 +23,39 @@ public class VoteSaveUseCase { private final MemberUtils memberUtils; private final VoteSaveService voteSaveService; + private final NoticeQueryService noticeQueryService; private final VoteMapper voteMapper; public Long saveVote(VoteRequest voteRequest) { Member memberRequest = memberUtils.getAccessMember(); + final ArrayList voteItems = new ArrayList<>(); // 투표 제목 저장 Vote voteEntity = voteMapper.toVoteEntity(voteRequest.title()); + //1차 저장 -> ID 생성을 위해서 Vote vote = voteSaveService.saveVote(voteEntity); // 투표 항목 개수 체크 후 각자 저장 List titles = voteRequest.item(); - for(String i : titles) { - + for (String i : titles) { + //vote Item enttiy 생성 VoteItem voteItemEntity = voteMapper.toVoteItemEntity(i); - VoteItem voteItem = voteSaveService.saveVoteItem(voteItemEntity); - - VoteItemRequest voteItemRequest = VoteItemRequest.builder() - .memberId(memberRequest.getId()) - .voteItemId(voteItem.getId()) - .build(); + voteItemEntity.setVote(vote); + voteItems.add(voteItemEntity); + voteSaveService.saveVoteItem(voteItemEntity); - VoteItemRecord voteItemRecordRequest = voteMapper.toVoteRecordEntity(voteItemRequest); - VoteItemRecord voteItemRecord = voteSaveService.saveVoteRecord(voteItemRecordRequest); + VoteItemRecord voteItemRecordRequest = VoteItemRecordMapper.toVoteItemRecord(voteItemEntity, memberRequest); + voteSaveService.saveVoteRecord(voteItemRecordRequest); } + //vote Item을 vote를 통해서 저장 + vote.setVoteItems(voteItems); + + //notice 조회 후 저장 + Notice notice = noticeQueryService.findByNoticeId(voteRequest.noticeId()); + vote.setNotice(notice); + + voteSaveService.saveVote(vote); return vote.getId(); } From eef53c5ccccff7869278e60c0be5e66c0856f887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Thu, 30 Nov 2023 17:33:04 +0900 Subject: [PATCH 34/45] feat: error code --- .../src/main/java/com/koa/commonmodule/exception/Error.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common-module/src/main/java/com/koa/commonmodule/exception/Error.java b/common-module/src/main/java/com/koa/commonmodule/exception/Error.java index 6c9b6f98..14c2496a 100644 --- a/common-module/src/main/java/com/koa/commonmodule/exception/Error.java +++ b/common-module/src/main/java/com/koa/commonmodule/exception/Error.java @@ -15,7 +15,10 @@ public enum Error { //REPORT DUPLICATE_REPORT("이미 등록된 신고내용입니다.", 400), - //NOTICE + // VOTE + VOTE_NOT_FOUND("투표가 존재하지 않습니다.", 400), + VOTE_ITEM_NOT_FOUND("투표 항목이 존재하지 않습니다.", 400), + VOTE_ITEM_RECORD_NOT_FOUND("투표 항목 참여자가 존재하지 않습니다.", 400), // MEMBER MEMBER_NOT_FOUND("사용자를 찾을 수 없습니다.", 2000), From 173b50f535067ef7462a751b8345b940a8657b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Thu, 30 Nov 2023 17:33:21 +0900 Subject: [PATCH 35/45] feat: exception files & dto --- .../vote/application/dto/VoteStatus.java | 40 +++++++++++++++++++ .../vote/domain/exception/VoteException.java | 10 +++++ 2 files changed, 50 insertions(+) create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteStatus.java create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/domain/exception/VoteException.java diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteStatus.java b/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteStatus.java new file mode 100644 index 00000000..216ca963 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/dto/VoteStatus.java @@ -0,0 +1,40 @@ +package com.koa.coremodule.vote.application.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.extern.jackson.Jacksonized; + +import java.util.List; + +@Data +@Builder +@Jacksonized +@AllArgsConstructor +@NoArgsConstructor +public class VoteStatus { + + private Long voteId; + private String title; + private List items; + + @Data + @Builder + @Jacksonized + public static class VoteItemStatus { + private Long voteItemId; + private String item; + private Integer count; + private List members; + } + + @Data + @Builder + @Jacksonized + public static class MemberList { + private Long memberId; + private String name; + } + +} diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/exception/VoteException.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/exception/VoteException.java new file mode 100644 index 00000000..e5e00caa --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/exception/VoteException.java @@ -0,0 +1,10 @@ +package com.koa.coremodule.vote.domain.exception; + +import com.koa.commonmodule.exception.BusinessException; +import com.koa.commonmodule.exception.Error; + +public class VoteException extends BusinessException { + public VoteException(Error error) { + super(error); + } +} From f4ca1eb580a423f7f49b50efc07fe796aca08876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Thu, 30 Nov 2023 17:33:41 +0900 Subject: [PATCH 36/45] feat: repository & query --- .../repository/VoteDynamicRepository.java | 14 +++++++ .../repository/VoteDynamicRepositoryImpl.java | 39 +++++++++++++++++++ .../domain/repository/VoteItemRepository.java | 5 +++ .../repository/VoteRecordRepository.java | 3 ++ .../domain/repository/VoteRepository.java | 5 ++- .../projection/VoteItemProjection.java | 26 +++++++++++++ 6 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteDynamicRepository.java create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteDynamicRepositoryImpl.java create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/domain/repository/projection/VoteItemProjection.java diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteDynamicRepository.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteDynamicRepository.java new file mode 100644 index 00000000..773839fe --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteDynamicRepository.java @@ -0,0 +1,14 @@ +package com.koa.coremodule.vote.domain.repository; + +import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.vote.domain.repository.projection.VoteItemProjection; + +import java.util.List; + +public interface VoteDynamicRepository { + + List findVoteItems(); + + Member findVoteMemberByMemberId(Long memberId, Long recordId); + +} diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteDynamicRepositoryImpl.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteDynamicRepositoryImpl.java new file mode 100644 index 00000000..00bd1679 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteDynamicRepositoryImpl.java @@ -0,0 +1,39 @@ +package com.koa.coremodule.vote.domain.repository; + +import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.vote.domain.repository.projection.VoteItemProjection; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +import static com.koa.coremodule.member.domain.entity.QMember.member; +import static com.koa.coremodule.vote.domain.entity.QVoteItem.voteItem; +import static com.koa.coremodule.vote.domain.entity.QVoteItemRecord.voteItemRecord; + +@RequiredArgsConstructor +public class VoteDynamicRepositoryImpl implements VoteDynamicRepository { + + private final JPAQueryFactory jpaQueryFactory; + + @Override + public List findVoteItems() { + return jpaQueryFactory.select(VoteItemProjection.CONSTRUCTOR_EXPRESSION) + .from(voteItem) + .leftJoin(voteItemRecord) + .on(voteItem.id.eq(voteItemRecord.voteItem.id)) + .groupBy(voteItem.voteItemName) + .fetch(); + } + + @Override + public Member findVoteMemberByMemberId(Long memberId, Long recordId) { + return jpaQueryFactory.select(member) + .from(voteItemRecord) + .join(member) + .on(voteItemRecord.member.id.eq(member.id)) + .where(voteItemRecord.member.id.eq(memberId).and(voteItemRecord.id.eq(recordId))) + .fetchOne(); + } + +} diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteItemRepository.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteItemRepository.java index 5fc8a839..5e330131 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteItemRepository.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteItemRepository.java @@ -3,5 +3,10 @@ import com.koa.coremodule.vote.domain.entity.VoteItem; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface VoteItemRepository extends JpaRepository { + + Optional findVoteItemByVoteItemName(String item); + } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRecordRepository.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRecordRepository.java index 4f2d78d9..2afe3024 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRecordRepository.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRecordRepository.java @@ -4,4 +4,7 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface VoteRecordRepository extends JpaRepository { + + VoteItemRecord findVoteItemRecordByVoteItemId(Long voteItemId); + } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRepository.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRepository.java index 14ba1abb..557cdd90 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRepository.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRepository.java @@ -3,5 +3,8 @@ import com.koa.coremodule.vote.domain.entity.Vote; import org.springframework.data.jpa.repository.JpaRepository; -public interface VoteRepository extends JpaRepository { +public interface VoteRepository extends JpaRepository, VoteDynamicRepository { + + Vote findVoteByNoticeId(Long noticeId); + } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/projection/VoteItemProjection.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/projection/VoteItemProjection.java new file mode 100644 index 00000000..d2667543 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/projection/VoteItemProjection.java @@ -0,0 +1,26 @@ +package com.koa.coremodule.vote.domain.repository.projection; + +import com.querydsl.core.types.ConstructorExpression; +import com.querydsl.core.types.Projections; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import static com.koa.coremodule.vote.domain.entity.QVoteItem.voteItem; +import static com.koa.coremodule.vote.domain.entity.QVoteItemRecord.voteItemRecord; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class VoteItemProjection { + + public static final ConstructorExpression CONSTRUCTOR_EXPRESSION = + Projections.constructor(VoteItemProjection.class, + voteItem.voteItemName, + voteItemRecord.id.count() + ); + + private String item; + private Long count; + +} From 9d66154cc7ad149ce4ff4831000bf0c2db25445a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Thu, 30 Nov 2023 17:33:54 +0900 Subject: [PATCH 37/45] feat: vote usecase --- .../application/service/VoteFindUseCase.java | 24 +++++++++++++++++++ .../application/service/VoteSaveUseCase.java | 19 ++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteFindUseCase.java diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteFindUseCase.java b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteFindUseCase.java new file mode 100644 index 00000000..8d230ec8 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteFindUseCase.java @@ -0,0 +1,24 @@ +package com.koa.coremodule.vote.application.service; + +import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.member.domain.utils.MemberUtils; +import com.koa.coremodule.vote.application.dto.VoteStatus; +import com.koa.coremodule.vote.application.mapper.VoteMapper; +import com.koa.coremodule.vote.domain.service.VoteFindService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class VoteFindUseCase { + + private final MemberUtils memberUtils; + private final VoteFindService voteFindService; + private final VoteMapper voteMapper; + + public VoteStatus findVoteStatus(Long noticeId) { + + return voteFindService.findVoteStatus(noticeId); + } + +} diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java index a266c8c5..50fd1adb 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java @@ -1,6 +1,7 @@ package com.koa.coremodule.vote.application.service; import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.member.domain.service.MemberQueryService; import com.koa.coremodule.member.domain.utils.MemberUtils; import com.koa.coremodule.notice.domain.entity.Notice; import com.koa.coremodule.notice.domain.service.NoticeQueryService; @@ -10,6 +11,7 @@ import com.koa.coremodule.vote.domain.entity.Vote; import com.koa.coremodule.vote.domain.entity.VoteItem; import com.koa.coremodule.vote.domain.entity.VoteItemRecord; +import com.koa.coremodule.vote.domain.service.VoteFindService; import com.koa.coremodule.vote.domain.service.VoteSaveService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -23,7 +25,9 @@ public class VoteSaveUseCase { private final MemberUtils memberUtils; private final VoteSaveService voteSaveService; + private final VoteFindService voteFindService; private final NoticeQueryService noticeQueryService; + private final MemberQueryService memberQueryService; private final VoteMapper voteMapper; public Long saveVote(VoteRequest voteRequest) { @@ -44,9 +48,6 @@ public Long saveVote(VoteRequest voteRequest) { voteItemEntity.setVote(vote); voteItems.add(voteItemEntity); voteSaveService.saveVoteItem(voteItemEntity); - - VoteItemRecord voteItemRecordRequest = VoteItemRecordMapper.toVoteItemRecord(voteItemEntity, memberRequest); - voteSaveService.saveVoteRecord(voteItemRecordRequest); } //vote Item을 vote를 통해서 저장 vote.setVoteItems(voteItems); @@ -60,4 +61,16 @@ public Long saveVote(VoteRequest voteRequest) { return vote.getId(); } + public Long attendVote(Long voteItemId) { + + Member memberRequest = memberUtils.getAccessMember(); + VoteItem voteItem = voteFindService.findVoteItemById(voteItemId); + Member member = memberQueryService.findMemberById(memberRequest.getId()); + + VoteItemRecord voteItemRecordRequest = VoteItemRecordMapper.toVoteItemRecord(voteItem, member); + VoteItemRecord voteItemRecord = voteSaveService.saveVoteRecord(voteItemRecordRequest); + + return voteItemRecord.getId(); + } + } From 0691489c28e8529e47f8c73193c460aa7cfc260e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Thu, 30 Nov 2023 17:34:10 +0900 Subject: [PATCH 38/45] feat: controller & query service --- .../apimodule/command/api/VoteController.java | 31 ++++- .../domain/service/MemberQueryService.java | 5 + .../vote/domain/service/VoteFindService.java | 107 ++++++++++++++++++ 3 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java b/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java index 6be52612..2bd0fda2 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java @@ -11,13 +11,12 @@ import com.koa.coremodule.notice.domain.repository.NoticeRepository; import com.koa.coremodule.notice.domain.repository.NoticeTeamRepository; import com.koa.coremodule.vote.application.dto.VoteRequest; +import com.koa.coremodule.vote.application.dto.VoteStatus; +import com.koa.coremodule.vote.application.service.VoteFindUseCase; import com.koa.coremodule.vote.application.service.VoteSaveUseCase; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.PostConstruct; @@ -28,6 +27,7 @@ public class VoteController { private final VoteSaveUseCase voteSaveUseCase; + private final VoteFindUseCase voteFindUseCase; private final MemberRepository memberRepository; private final NoticeTeamRepository noticeTeamRepository; private final CurriculumRepository curriculumRepository; @@ -42,6 +42,13 @@ public void test() { .name("안정후") .build(); memberRepository.save(member); + final Member member2 = Member.builder() + .authority(Authority.MEMBER) + .email("austinan12300@gmail.com") + .password("00121500") + .name("안정후22") + .build(); + memberRepository.save(member2); final Curriculum curriculum = Curriculum.builder() .curriculumName("기업프로젝트") .build(); @@ -72,9 +79,25 @@ public ApplicationResponse makeVote(@RequestBody VoteRequest voteRequest) /** * 투표 현황 조회 - 명단까지 리스트로 전달 필요 */ + @GetMapping + public ApplicationResponse getVoteStatus(Long noticeId) { + + VoteStatus voteStatus = voteFindUseCase.findVoteStatus(noticeId); + return ApplicationResponse.ok(voteStatus, "투표 현황 조회 완료했습니다."); + } /** * 투표 참여 */ + @PostMapping(value = "/attend") + public ApplicationResponse attendVote(Long voteItemId) { + + Long voteItemRecordId = voteSaveUseCase.attendVote(voteItemId); + return ApplicationResponse.ok(voteItemRecordId, "투표 참여를 완료했습니다."); + } + + /** + * 투표 마감 처리 + */ } diff --git a/core-module/src/main/java/com/koa/coremodule/member/domain/service/MemberQueryService.java b/core-module/src/main/java/com/koa/coremodule/member/domain/service/MemberQueryService.java index 5d52d354..60ac7409 100644 --- a/core-module/src/main/java/com/koa/coremodule/member/domain/service/MemberQueryService.java +++ b/core-module/src/main/java/com/koa/coremodule/member/domain/service/MemberQueryService.java @@ -1,6 +1,7 @@ package com.koa.coremodule.member.domain.service; import com.koa.commonmodule.annotation.DomainService; +import com.koa.commonmodule.exception.BusinessException; import com.koa.commonmodule.exception.Error; import com.koa.coremodule.member.domain.entity.Authority; import com.koa.coremodule.member.domain.entity.Member; @@ -30,6 +31,10 @@ public Member findByEmail(String email) { .orElseThrow(() -> new UserNotFoundException(Error.MEMBER_NOT_FOUND)); } + public Member findMemberById(Long memberId) { + return memberRepository.findById(memberId).orElseThrow(() -> new BusinessException(Error.MEMBER_NOT_FOUND)); + } + public boolean checkEmailExist(String email) { return memberRepository.existsByEmail(email); } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java new file mode 100644 index 00000000..c8641416 --- /dev/null +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java @@ -0,0 +1,107 @@ +package com.koa.coremodule.vote.domain.service; + +import com.koa.commonmodule.exception.BusinessException; +import com.koa.commonmodule.exception.Error; +import com.koa.coremodule.member.domain.entity.Member; +import com.koa.coremodule.member.domain.repository.MemberRepository; +import com.koa.coremodule.vote.application.dto.VoteStatus; +import com.koa.coremodule.vote.domain.entity.Vote; +import com.koa.coremodule.vote.domain.entity.VoteItem; +import com.koa.coremodule.vote.domain.entity.VoteItemRecord; +import com.koa.coremodule.vote.domain.repository.VoteItemRepository; +import com.koa.coremodule.vote.domain.repository.VoteRecordRepository; +import com.koa.coremodule.vote.domain.repository.VoteRepository; +import com.koa.coremodule.vote.domain.repository.projection.VoteItemProjection; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class VoteFindService { + + private final VoteRepository voteRepository; + private final VoteItemRepository voteItemRepository; + private final VoteRecordRepository voteRecordRepository; + + public VoteStatus findVoteStatus(Long noticeId) { + + VoteStatus voteStatus = new VoteStatus(); + List voteItemStatusList = new ArrayList<>(); + List memberLists = new ArrayList<>(); + + // 제목, id 기본정보 넣기 + Vote voteList = findVoteByNoticeId(noticeId); + voteStatus.setVoteId(voteList.getId()); + voteStatus.setTitle(voteList.getVoteTitle()); + + List voteItemList = voteRepository.findVoteItems(); + + // 각 항목들 개수 현황 정보 넣기 + for (VoteItemProjection v : voteItemList) { + + VoteStatus.VoteItemStatus voteItemStatus = VoteStatus.VoteItemStatus.builder() + .item(v.getItem()) + .count(Math.toIntExact(v.getCount())) + .build(); + + if (v.getCount() >= 1) { + + // 항목별 멤버 명단 나열 + Optional voteItem = findVoteItemByItem(v.getItem()); + VoteItemRecord voteItemRecord = findVoteItemRecordById(voteItem.get().getId()); + VoteStatus.MemberList memberListBuilder = VoteStatus.MemberList.builder() + .memberId(voteItemRecord.getMember().getId()) + .build(); + + // 이름 넣어주기 + Member member = voteRepository.findVoteMemberByMemberId(memberListBuilder.getMemberId(), voteItemRecord.getId()); + memberListBuilder.setName(member.getName()); + + memberLists.add(memberListBuilder); + + voteItemStatus.setVoteItemId(voteItem.get().getId()); + voteItemStatus.setMembers(memberLists); + + voteItemStatusList.add(voteItemStatus); + } else { + + Optional voteItem = findVoteItemByItem(v.getItem()); + voteItemStatus.setVoteItemId(voteItem.get().getId()); + + voteItemStatusList.add(voteItemStatus); + } + + voteStatus.setItems(voteItemStatusList); + } + + return voteStatus; + } + + public Vote findVoteByNoticeId(Long noticeId) { + + Vote vote = voteRepository.findVoteByNoticeId(noticeId); + + if (vote != null) { + return vote; + } else { + throw new BusinessException(Error.VOTE_NOT_FOUND); + } + } + + public VoteItem findVoteItemById(Long voteItemId) { + return voteItemRepository.findById(voteItemId).orElseThrow(() -> new BusinessException(Error.VOTE_ITEM_NOT_FOUND)); + } + + public Optional findVoteItemByItem(String item) { + return voteItemRepository.findVoteItemByVoteItemName(item); + } + + public VoteItemRecord findVoteItemRecordById(Long voteItemId) { + return voteRecordRepository.findVoteItemRecordByVoteItemId(voteItemId); + } + +} From 4d65d7de312c50f323ca1c6a55baee495ba9f382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Thu, 30 Nov 2023 17:47:52 +0900 Subject: [PATCH 39/45] refactor: unused code --- .../apimodule/command/api/VoteController.java | 48 ------------------- .../application/service/VoteFindUseCase.java | 5 -- .../vote/domain/service/VoteFindService.java | 1 - 3 files changed, 54 deletions(-) diff --git a/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java b/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java index 2bd0fda2..cd30e7cf 100644 --- a/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java +++ b/api-module/src/main/java/com/koa/apimodule/command/api/VoteController.java @@ -1,15 +1,6 @@ package com.koa.apimodule.command.api; import com.koa.commonmodule.common.ApplicationResponse; -import com.koa.coremodule.member.domain.entity.Authority; -import com.koa.coremodule.member.domain.entity.Member; -import com.koa.coremodule.member.domain.repository.MemberRepository; -import com.koa.coremodule.notice.domain.entity.Curriculum; -import com.koa.coremodule.notice.domain.entity.Notice; -import com.koa.coremodule.notice.domain.entity.NoticeTeam; -import com.koa.coremodule.notice.domain.repository.CurriculumRepository; -import com.koa.coremodule.notice.domain.repository.NoticeRepository; -import com.koa.coremodule.notice.domain.repository.NoticeTeamRepository; import com.koa.coremodule.vote.application.dto.VoteRequest; import com.koa.coremodule.vote.application.dto.VoteStatus; import com.koa.coremodule.vote.application.service.VoteFindUseCase; @@ -18,8 +9,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; -import javax.annotation.PostConstruct; - @Slf4j @RestController @RequiredArgsConstructor @@ -28,43 +17,6 @@ public class VoteController { private final VoteSaveUseCase voteSaveUseCase; private final VoteFindUseCase voteFindUseCase; - private final MemberRepository memberRepository; - private final NoticeTeamRepository noticeTeamRepository; - private final CurriculumRepository curriculumRepository; - private final NoticeRepository noticeRepository; - - @PostConstruct - public void test() { - final Member member = Member.builder() - .authority(Authority.MEMBER) - .email("austinan123@gmail.com") - .password("001215") - .name("안정후") - .build(); - memberRepository.save(member); - final Member member2 = Member.builder() - .authority(Authority.MEMBER) - .email("austinan12300@gmail.com") - .password("00121500") - .name("안정후22") - .build(); - memberRepository.save(member2); - final Curriculum curriculum = Curriculum.builder() - .curriculumName("기업프로젝트") - .build(); - curriculumRepository.save(curriculum); - final NoticeTeam noticeTeam = NoticeTeam.builder() - .teamName("경영총괄팀") - .build(); - noticeTeamRepository.save(noticeTeam); - final Notice notice = Notice.builder() - .member(member) - .title("sampletitle") - .content("samplecontent") - .curriculum(curriculum) - .build(); - noticeRepository.save(notice); - } /** * 투표 생성 diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteFindUseCase.java b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteFindUseCase.java index 8d230ec8..7edba08e 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteFindUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteFindUseCase.java @@ -1,9 +1,6 @@ package com.koa.coremodule.vote.application.service; -import com.koa.coremodule.member.domain.entity.Member; -import com.koa.coremodule.member.domain.utils.MemberUtils; import com.koa.coremodule.vote.application.dto.VoteStatus; -import com.koa.coremodule.vote.application.mapper.VoteMapper; import com.koa.coremodule.vote.domain.service.VoteFindService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -12,9 +9,7 @@ @RequiredArgsConstructor public class VoteFindUseCase { - private final MemberUtils memberUtils; private final VoteFindService voteFindService; - private final VoteMapper voteMapper; public VoteStatus findVoteStatus(Long noticeId) { diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java index c8641416..bcd454ad 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java @@ -3,7 +3,6 @@ import com.koa.commonmodule.exception.BusinessException; import com.koa.commonmodule.exception.Error; import com.koa.coremodule.member.domain.entity.Member; -import com.koa.coremodule.member.domain.repository.MemberRepository; import com.koa.coremodule.vote.application.dto.VoteStatus; import com.koa.coremodule.vote.domain.entity.Vote; import com.koa.coremodule.vote.domain.entity.VoteItem; From 114006cf4db383f13fd0f6c148f247898589dc38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Fri, 1 Dec 2023 09:48:28 +0900 Subject: [PATCH 40/45] =?UTF-8?q?fix:=20=ED=86=A0=ED=81=B0=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=EB=A9=A4=EB=B2=84=EB=93=A4=EC=97=90=EA=B2=8C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EB=B3=B4=EB=82=B4=EC=A7=80=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/service/NoticeFcmUseCase.java | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFcmUseCase.java b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFcmUseCase.java index 00927b19..cce26744 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFcmUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFcmUseCase.java @@ -15,6 +15,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Slf4j @Service @RequiredArgsConstructor @@ -35,25 +37,31 @@ public void registerFcmToken(String token) { log.info("회원의 fcm 토큰이 등록되었습니다."); } - @Transactional(readOnly = true) + @Transactional public void sendNotification(String title, String content) { - Member memberRequest = memberUtils.getAccessMember(); + List members = findAllMember(); - Member member = findMember(memberRequest.getId()); Notification notification = Notification.builder() .setTitle(title) .setBody(content) .build(); - Message message = Message.builder() - .setToken(member.getFcmToken()) - .setNotification(notification) - .build(); - try { - firebaseMessaging.send(message); - } catch (FirebaseMessagingException ex) { - log.info("알림 전송에 실패했습니다."); + for (Member m : members) { + + if (!m.getFcmToken().isEmpty()) { + + Message message = Message.builder() + .setToken(m.getFcmToken()) + .setNotification(notification) + .build(); + + try { + firebaseMessaging.send(message); + } catch (FirebaseMessagingException ex) { + log.info("알림 전송에 실패했습니다."); + } + } } } @@ -69,4 +77,8 @@ private Member findMember(Long memberId) { return memberRepository.findById(memberId) .orElseThrow(() -> new BusinessException(Error.MEMBER_NOT_FOUND)); } + + private List findAllMember() { + return memberRepository.findAll(); + } } From f14c8b0810b640fdfd56d43e70a6da7b9fb1ff98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Fri, 1 Dec 2023 10:49:08 +0900 Subject: [PATCH 41/45] =?UTF-8?q?fix:=20=ED=95=AD=EB=AA=A9=EB=B3=84?= =?UTF-8?q?=EB=A1=9C=20=EB=A9=A4=EB=B2=84=20=EB=8B=B4=EA=B8=B0=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coremodule/vote/domain/service/VoteFindService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java index bcd454ad..294334da 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java @@ -30,7 +30,6 @@ public VoteStatus findVoteStatus(Long noticeId) { VoteStatus voteStatus = new VoteStatus(); List voteItemStatusList = new ArrayList<>(); - List memberLists = new ArrayList<>(); // 제목, id 기본정보 넣기 Vote voteList = findVoteByNoticeId(noticeId); @@ -47,6 +46,8 @@ public VoteStatus findVoteStatus(Long noticeId) { .count(Math.toIntExact(v.getCount())) .build(); + List memberLists = new ArrayList<>(); // 항목별로 멤버 초기화 + if (v.getCount() >= 1) { // 항목별 멤버 명단 나열 @@ -73,10 +74,10 @@ public VoteStatus findVoteStatus(Long noticeId) { voteItemStatusList.add(voteItemStatus); } - - voteStatus.setItems(voteItemStatusList); } + voteStatus.setItems(voteItemStatusList); + return voteStatus; } From 55464e8e525389d8b4dd8bd584f311242383015f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Fri, 1 Dec 2023 13:54:01 +0900 Subject: [PATCH 42/45] =?UTF-8?q?fix:=20list=20=EB=A1=9C=20=ED=88=AC?= =?UTF-8?q?=ED=91=9C=ED=95=AD=EB=AA=A9=20=EA=B0=80=EC=A0=B8=EC=98=A4?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/VoteRecordRepository.java | 4 +++- .../vote/domain/service/VoteFindService.java | 21 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRecordRepository.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRecordRepository.java index 2afe3024..8aa245d8 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRecordRepository.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/repository/VoteRecordRepository.java @@ -3,8 +3,10 @@ import com.koa.coremodule.vote.domain.entity.VoteItemRecord; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface VoteRecordRepository extends JpaRepository { - VoteItemRecord findVoteItemRecordByVoteItemId(Long voteItemId); + List findVoteItemRecordByVoteItemId(Long voteItemId); } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java index 294334da..22a3f5ed 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java @@ -52,16 +52,19 @@ public VoteStatus findVoteStatus(Long noticeId) { // 항목별 멤버 명단 나열 Optional voteItem = findVoteItemByItem(v.getItem()); - VoteItemRecord voteItemRecord = findVoteItemRecordById(voteItem.get().getId()); - VoteStatus.MemberList memberListBuilder = VoteStatus.MemberList.builder() - .memberId(voteItemRecord.getMember().getId()) - .build(); + List voteItemRecord = findVoteItemRecordById(voteItem.get().getId()); - // 이름 넣어주기 - Member member = voteRepository.findVoteMemberByMemberId(memberListBuilder.getMemberId(), voteItemRecord.getId()); - memberListBuilder.setName(member.getName()); + for(VoteItemRecord vr : voteItemRecord) { + VoteStatus.MemberList memberListBuilder = VoteStatus.MemberList.builder() + .memberId(vr.getMember().getId()) + .build(); - memberLists.add(memberListBuilder); + // 이름 넣어주기 + Member member = voteRepository.findVoteMemberByMemberId(memberListBuilder.getMemberId(), vr.getId()); + memberListBuilder.setName(member.getName()); + + memberLists.add(memberListBuilder); + } voteItemStatus.setVoteItemId(voteItem.get().getId()); voteItemStatus.setMembers(memberLists); @@ -100,7 +103,7 @@ public Optional findVoteItemByItem(String item) { return voteItemRepository.findVoteItemByVoteItemName(item); } - public VoteItemRecord findVoteItemRecordById(Long voteItemId) { + public List findVoteItemRecordById(Long voteItemId) { return voteRecordRepository.findVoteItemRecordByVoteItemId(voteItemId); } From 6b8ef79b411401fb9d0205fcaaabcb4c674916d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Fri, 1 Dec 2023 14:04:41 +0900 Subject: [PATCH 43/45] =?UTF-8?q?fix:=20null=20=EA=B9=8C=EC=A7=80=20?= =?UTF-8?q?=EC=B2=B4=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/application/service/NoticeFcmUseCase.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFcmUseCase.java b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFcmUseCase.java index cce26744..9b3ebff8 100644 --- a/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFcmUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/notice/application/service/NoticeFcmUseCase.java @@ -48,9 +48,7 @@ public void sendNotification(String title, String content) { .build(); for (Member m : members) { - - if (!m.getFcmToken().isEmpty()) { - + if (m.getFcmToken() != null && !m.getFcmToken().isEmpty()) { Message message = Message.builder() .setToken(m.getFcmToken()) .setNotification(notification) From aaf5846cda0021e7e5f91d9c130a98f4e29b5ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Mon, 4 Dec 2023 13:26:41 +0900 Subject: [PATCH 44/45] =?UTF-8?q?fix:=20=EC=97=B0=EA=B4=80=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20=EC=A0=95=EB=A6=AC=20&=20setter=20=EB=AA=A8?= =?UTF-8?q?=EB=91=90=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/service/VoteSaveUseCase.java | 31 ++++++++++--------- .../coremodule/vote/domain/entity/Vote.java | 9 +----- .../vote/domain/entity/VoteItem.java | 6 ---- .../vote/domain/service/VoteFindService.java | 4 +++ 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java index 50fd1adb..9e9dea0c 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java @@ -15,6 +15,7 @@ import com.koa.coremodule.vote.domain.service.VoteSaveService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; @@ -30,37 +31,39 @@ public class VoteSaveUseCase { private final MemberQueryService memberQueryService; private final VoteMapper voteMapper; + @Transactional public Long saveVote(VoteRequest voteRequest) { - - Member memberRequest = memberUtils.getAccessMember(); - - final ArrayList voteItems = new ArrayList<>(); // 투표 제목 저장 Vote voteEntity = voteMapper.toVoteEntity(voteRequest.title()); - //1차 저장 -> ID 생성을 위해서 - Vote vote = voteSaveService.saveVote(voteEntity); // 투표 항목 개수 체크 후 각자 저장 List titles = voteRequest.item(); - for (String i : titles) { - //vote Item enttiy 생성 - VoteItem voteItemEntity = voteMapper.toVoteItemEntity(i); - voteItemEntity.setVote(vote); + List voteItems = new ArrayList<>(); + + for (String title : titles) { + //vote Item entity 생성 + VoteItem voteItemEntity = voteMapper.toVoteItemEntity(title); voteItems.add(voteItemEntity); voteSaveService.saveVoteItem(voteItemEntity); } - //vote Item을 vote를 통해서 저장 - vote.setVoteItems(voteItems); - //notice 조회 후 저장 + //notice 조회 Notice notice = noticeQueryService.findByNoticeId(voteRequest.noticeId()); - vote.setNotice(notice); + // Vote 엔티티 생성 + Vote vote = Vote.builder() + .voteTitle(voteEntity.getVoteTitle()) + .voteItems(voteItems) + .notice(notice) + .build(); + + // Vote 엔티티 저장 voteSaveService.saveVote(vote); return vote.getId(); } + @Transactional public Long attendVote(Long voteItemId) { Member memberRequest = memberUtils.getAccessMember(); diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java index f1ca4db7..537c7e42 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java @@ -22,18 +22,11 @@ public class Vote extends BaseEntity { private String voteTitle; - @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "vote") + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) private List voteItems = new ArrayList<>(); @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "notice_id") private Notice notice; - public void setVoteItems(List voteItems) { - this.voteItems = voteItems; - } - - public void setNotice(Notice notice) { - this.notice = notice; - } } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java index 1e550bee..2ac54711 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java @@ -16,12 +16,6 @@ public class VoteItem extends BaseEntity { @Column(name = "vote_item_id") private Long id; - @ManyToOne(fetch = FetchType.LAZY) - private Vote vote; - private String voteItemName; - public void setVote(Vote vote) { - this.vote = vote; - } } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java index 22a3f5ed..fc5bd33b 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/service/VoteFindService.java @@ -99,6 +99,10 @@ public VoteItem findVoteItemById(Long voteItemId) { return voteItemRepository.findById(voteItemId).orElseThrow(() -> new BusinessException(Error.VOTE_ITEM_NOT_FOUND)); } + public List findAllVoteItems() { + return voteItemRepository.findAll(); + } + public Optional findVoteItemByItem(String item) { return voteItemRepository.findVoteItemByVoteItemName(item); } From 9a0f96837f02d80f53520678d7a04df5e41ce679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Mon, 4 Dec 2023 15:01:43 +0900 Subject: [PATCH 45/45] =?UTF-8?q?fix:=20=EC=97=B0=EA=B4=80=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20change=20&=20=EB=A1=9C=EC=A7=81=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 --- .../application/service/VoteSaveUseCase.java | 26 +++++++++---------- .../coremodule/vote/domain/entity/Vote.java | 6 ----- .../vote/domain/entity/VoteItem.java | 4 +++ 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java index 9e9dea0c..60000e3e 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/application/service/VoteSaveUseCase.java @@ -17,7 +17,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; import java.util.List; @Service @@ -36,29 +35,28 @@ public Long saveVote(VoteRequest voteRequest) { // 투표 제목 저장 Vote voteEntity = voteMapper.toVoteEntity(voteRequest.title()); - // 투표 항목 개수 체크 후 각자 저장 - List titles = voteRequest.item(); - List voteItems = new ArrayList<>(); - - for (String title : titles) { - //vote Item entity 생성 - VoteItem voteItemEntity = voteMapper.toVoteItemEntity(title); - voteItems.add(voteItemEntity); - voteSaveService.saveVoteItem(voteItemEntity); - } - //notice 조회 Notice notice = noticeQueryService.findByNoticeId(voteRequest.noticeId()); // Vote 엔티티 생성 Vote vote = Vote.builder() .voteTitle(voteEntity.getVoteTitle()) - .voteItems(voteItems) .notice(notice) .build(); // Vote 엔티티 저장 - voteSaveService.saveVote(vote); + Vote savedVote = voteSaveService.saveVote(vote); + + // 투표 항목 개수 체크 후 각자 저장 + List titles = voteRequest.item(); + + for (String title : titles) { + VoteItem voteItemEntity = VoteItem.builder() + .voteItemName(title) + .vote(savedVote) // Vote ID 설정 + .build(); + voteSaveService.saveVoteItem(voteItemEntity); + } return vote.getId(); } diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java index 537c7e42..ec8e69ab 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/Vote.java @@ -5,9 +5,6 @@ import jakarta.persistence.*; import lombok.*; -import java.util.ArrayList; -import java.util.List; - @Builder @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -22,9 +19,6 @@ public class Vote extends BaseEntity { private String voteTitle; - @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) - private List voteItems = new ArrayList<>(); - @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "notice_id") private Notice notice; diff --git a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java index 2ac54711..eb3e0aea 100644 --- a/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java +++ b/core-module/src/main/java/com/koa/coremodule/vote/domain/entity/VoteItem.java @@ -16,6 +16,10 @@ public class VoteItem extends BaseEntity { @Column(name = "vote_item_id") private Long id; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "vote_id") + private Vote vote; + private String voteItemName; }