From bf5b1f204cacf1b17427c2d31e0d3773a2209d35 Mon Sep 17 00:00:00 2001 From: donghyunkim Date: Thu, 25 Apr 2024 15:14:30 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20=EC=B9=B4=EA=B3=B5=20=EB=AA=A8?= =?UTF-8?q?=EC=A7=91=EA=B8=80=20=EC=83=9D=EC=84=B1=20=EC=98=A4=ED=94=88?= =?UTF-8?q?=EC=B1=84=ED=8C=85=EB=B0=A9url=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/demo/controller/StudyOnceController.java | 3 ++- src/main/java/com/example/demo/domain/study/StudyOnce.java | 4 +++- .../com/example/demo/dto/study/StudyOnceCreateRequest.java | 5 +++++ .../com/example/demo/dto/study/StudyOnceCreateResponse.java | 1 + src/main/java/com/example/demo/mapper/StudyOnceMapper.java | 2 ++ .../example/demo/service/profile/ProfileServiceImplTest.java | 2 +- .../example/demo/service/study/StudyOnceServiceImplTest.java | 2 +- 7 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/demo/controller/StudyOnceController.java b/src/main/java/com/example/demo/controller/StudyOnceController.java index 0a5825f..a058ec6 100644 --- a/src/main/java/com/example/demo/controller/StudyOnceController.java +++ b/src/main/java/com/example/demo/controller/StudyOnceController.java @@ -69,7 +69,8 @@ public ResponseEntity> searchList( } @PostMapping("") - public ResponseEntity create(@RequestBody StudyOnceCreateRequest studyOnceCreateRequest, + public ResponseEntity create( + @RequestBody @Validated StudyOnceCreateRequest studyOnceCreateRequest, @RequestHeader("Authorization") String authorization) { long memberId = cafegoryTokenManager.getIdentityId(authorization); StudyOnceCreateResponse response = studyOnceService.createStudy(memberId, studyOnceCreateRequest); diff --git a/src/main/java/com/example/demo/domain/study/StudyOnce.java b/src/main/java/com/example/demo/domain/study/StudyOnce.java index 69b4b9c..cd1743c 100644 --- a/src/main/java/com/example/demo/domain/study/StudyOnce.java +++ b/src/main/java/com/example/demo/domain/study/StudyOnce.java @@ -58,6 +58,7 @@ public class StudyOnce { private int nowMemberCount; private boolean isEnd; private boolean ableToTalk; + private String openChatUrl; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "leader_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) private Member leader; @@ -66,7 +67,7 @@ public class StudyOnce { @Builder private StudyOnce(Long id, String name, Cafe cafe, LocalDateTime startDateTime, LocalDateTime endDateTime, - int maxMemberCount, int nowMemberCount, boolean isEnd, boolean ableToTalk, Member leader) { + int maxMemberCount, int nowMemberCount, boolean isEnd, boolean ableToTalk, String openChatUrl, Member leader) { validateStartDateTime(startDateTime); validateStudyOnceTime(startDateTime, endDateTime); validateMaxMemberCount(maxMemberCount); @@ -80,6 +81,7 @@ private StudyOnce(Long id, String name, Cafe cafe, LocalDateTime startDateTime, this.nowMemberCount = nowMemberCount; this.isEnd = isEnd; this.ableToTalk = ableToTalk; + this.openChatUrl = openChatUrl; this.leader = leader; validateConflictJoin(leader); studyMembers = new ArrayList<>(); diff --git a/src/main/java/com/example/demo/dto/study/StudyOnceCreateRequest.java b/src/main/java/com/example/demo/dto/study/StudyOnceCreateRequest.java index 5e31053..1bc7694 100644 --- a/src/main/java/com/example/demo/dto/study/StudyOnceCreateRequest.java +++ b/src/main/java/com/example/demo/dto/study/StudyOnceCreateRequest.java @@ -2,6 +2,8 @@ import java.time.LocalDateTime; +import javax.validation.constraints.NotBlank; + import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -11,10 +13,13 @@ @NoArgsConstructor public class StudyOnceCreateRequest { private long cafeId; + @NotBlank private String name; private LocalDateTime startDateTime; private LocalDateTime endDateTime; private int maxMemberCount; private boolean canTalk; + @NotBlank + private String openChatUrl; } diff --git a/src/main/java/com/example/demo/dto/study/StudyOnceCreateResponse.java b/src/main/java/com/example/demo/dto/study/StudyOnceCreateResponse.java index 510358f..2c64ec0 100644 --- a/src/main/java/com/example/demo/dto/study/StudyOnceCreateResponse.java +++ b/src/main/java/com/example/demo/dto/study/StudyOnceCreateResponse.java @@ -19,4 +19,5 @@ public class StudyOnceCreateResponse { private boolean canTalk; private boolean canJoin; private boolean isEnd; + private String openChatUrl; } diff --git a/src/main/java/com/example/demo/mapper/StudyOnceMapper.java b/src/main/java/com/example/demo/mapper/StudyOnceMapper.java index 4d9a947..766bfbf 100644 --- a/src/main/java/com/example/demo/mapper/StudyOnceMapper.java +++ b/src/main/java/com/example/demo/mapper/StudyOnceMapper.java @@ -45,6 +45,7 @@ public StudyOnce toNewEntity(StudyOnceCreateRequest studyOnceCreateRequest, Cafe .nowMemberCount(0) .isEnd(false) .ableToTalk(studyOnceCreateRequest.isCanTalk()) + .openChatUrl(studyOnceCreateRequest.getOpenChatUrl()) .cafe(cafe) .leader(leader) .build(); @@ -112,6 +113,7 @@ public StudyOnceCreateResponse toStudyOnceCreateResponse(StudyOnce saved, boolea .canTalk(saved.isAbleToTalk()) .canJoin(canJoin) .isEnd(saved.isEnd()) + .openChatUrl(saved.getOpenChatUrl()) .build(); } diff --git a/src/test/java/com/example/demo/service/profile/ProfileServiceImplTest.java b/src/test/java/com/example/demo/service/profile/ProfileServiceImplTest.java index 7598373..7510b4c 100644 --- a/src/test/java/com/example/demo/service/profile/ProfileServiceImplTest.java +++ b/src/test/java/com/example/demo/service/profile/ProfileServiceImplTest.java @@ -85,7 +85,7 @@ private void syncStudyOnceRepositoryAndStudyMemberRepository() { private static StudyOnceCreateRequest makeStudyOnceCreateRequest(LocalDateTime start, LocalDateTime end, long cafeId) { - return new StudyOnceCreateRequest(cafeId, "테스트 카페", start, end, 4, true); + return new StudyOnceCreateRequest(cafeId, "테스트 카페", start, end, 4, true, "오픈채팅방 링크"); } @Test diff --git a/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java b/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java index 5173ec4..6b7eef5 100644 --- a/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java +++ b/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java @@ -90,7 +90,7 @@ void searchStudyByDto() { private StudyOnceCreateRequest makeStudyOnceCreateRequest(LocalDateTime start, LocalDateTime end, long cafeId) { - return new StudyOnceCreateRequest(cafeId, "테스트 스터디", start, end, 4, true); + return new StudyOnceCreateRequest(cafeId, "테스트 스터디", start, end, 4, true, "오픈채팅방 링크"); } private void syncStudyOnceRepositoryAndStudyMemberRepository() { From d0039f24acf3be78c622e2a1ee86b4a3a380fe4c Mon Sep 17 00:00:00 2001 From: donghyunkim Date: Thu, 25 Apr 2024 17:08:20 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20=EC=B9=B4=EA=B3=B5=20=EB=AA=A8?= =?UTF-8?q?=EC=A7=91=EA=B8=80=20=EC=88=98=EC=A0=95=20=EC=98=A4=ED=94=88?= =?UTF-8?q?=EC=B1=84=ED=8C=85=EB=B0=A9=20url=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/controller/StudyOnceController.java | 2 +- .../example/demo/domain/study/StudyOnce.java | 16 ++++- .../demo/dto/study/StudyOnceInfoResponse.java | 1 + .../dto/study/StudyOnceUpdateRequest.java | 2 + .../example/demo/exception/ExceptionType.java | 1 + .../example/demo/mapper/StudyOnceMapper.java | 1 + .../service/study/StudyOnceServiceImpl.java | 3 + .../demo/builder/TestStudyOnceBuilder.java | 7 +++ .../demo/domain/study/StudyMemberTest.java | 6 +- .../demo/domain/study/StudyOnceTest.java | 61 ++++++++++++++----- .../study/InMemoryStudyOnceRepository.java | 1 + .../study/StudyOnceServiceImplTest.java | 22 ++++--- 12 files changed, 93 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/example/demo/controller/StudyOnceController.java b/src/main/java/com/example/demo/controller/StudyOnceController.java index a058ec6..4525b04 100644 --- a/src/main/java/com/example/demo/controller/StudyOnceController.java +++ b/src/main/java/com/example/demo/controller/StudyOnceController.java @@ -79,7 +79,7 @@ public ResponseEntity create( @PatchMapping("/{studyOnceId:[0-9]+}") public ResponseEntity update(@PathVariable Long studyOnceId, - @RequestBody StudyOnceUpdateRequest request, + @RequestBody @Validated StudyOnceUpdateRequest request, @RequestHeader("Authorization") String authorization) { long leaderId = cafegoryTokenManager.getIdentityId(authorization); if (studyOnceService.doesOnlyStudyLeaderExist(studyOnceId)) { diff --git a/src/main/java/com/example/demo/domain/study/StudyOnce.java b/src/main/java/com/example/demo/domain/study/StudyOnce.java index cd1743c..90fa6fd 100644 --- a/src/main/java/com/example/demo/domain/study/StudyOnce.java +++ b/src/main/java/com/example/demo/domain/study/StudyOnce.java @@ -72,6 +72,7 @@ private StudyOnce(Long id, String name, Cafe cafe, LocalDateTime startDateTime, validateStudyOnceTime(startDateTime, endDateTime); validateMaxMemberCount(maxMemberCount); this.id = id; + validateEmptyOrWhiteSpace(name, STUDY_ONCE_NAME_EMPTY_OR_WHITESPACE); this.name = name; this.cafe = cafe; this.startDateTime = startDateTime; @@ -81,6 +82,7 @@ private StudyOnce(Long id, String name, Cafe cafe, LocalDateTime startDateTime, this.nowMemberCount = nowMemberCount; this.isEnd = isEnd; this.ableToTalk = ableToTalk; + validateEmptyOrWhiteSpace(openChatUrl, STUDY_ONCE_OPEN_CHAT_URL_EMPTY_OR_WHITESPACE); this.openChatUrl = openChatUrl; this.leader = leader; validateConflictJoin(leader); @@ -183,9 +185,7 @@ public boolean canJoin(LocalDateTime baseDateTime) { } public void changeName(String name) { - if (StringUtils.isEmptyOrWhitespace(name)) { - throw new CafegoryException(STUDY_ONCE_NAME_EMPTY_OR_WHITESPACE); - } + validateEmptyOrWhiteSpace(name, STUDY_ONCE_NAME_EMPTY_OR_WHITESPACE); this.name = name; } @@ -210,4 +210,14 @@ public boolean doesOnlyLeaderExist() { return this.studyMembers.size() == 1 && this.studyMembers.get(0).isLeader(this.leader); } + public void changeOpenChatUrl(String openChatUrl) { + validateEmptyOrWhiteSpace(openChatUrl, STUDY_ONCE_OPEN_CHAT_URL_EMPTY_OR_WHITESPACE); + this.openChatUrl = openChatUrl; + } + + private void validateEmptyOrWhiteSpace(String target, ExceptionType exceptionType) { + if (StringUtils.isEmptyOrWhitespace(target)) { + throw new CafegoryException(exceptionType); + } + } } diff --git a/src/main/java/com/example/demo/dto/study/StudyOnceInfoResponse.java b/src/main/java/com/example/demo/dto/study/StudyOnceInfoResponse.java index dad5997..c3e63e5 100644 --- a/src/main/java/com/example/demo/dto/study/StudyOnceInfoResponse.java +++ b/src/main/java/com/example/demo/dto/study/StudyOnceInfoResponse.java @@ -19,4 +19,5 @@ public class StudyOnceInfoResponse { private boolean canTalk; private boolean canJoin; private boolean isEnd; + private String openChatUrl; } diff --git a/src/main/java/com/example/demo/dto/study/StudyOnceUpdateRequest.java b/src/main/java/com/example/demo/dto/study/StudyOnceUpdateRequest.java index 0595937..b05c746 100644 --- a/src/main/java/com/example/demo/dto/study/StudyOnceUpdateRequest.java +++ b/src/main/java/com/example/demo/dto/study/StudyOnceUpdateRequest.java @@ -25,4 +25,6 @@ public class StudyOnceUpdateRequest { private int maxMemberCount; @Nullable private boolean canTalk; + @Nullable + private String openChatUrl; } diff --git a/src/main/java/com/example/demo/exception/ExceptionType.java b/src/main/java/com/example/demo/exception/ExceptionType.java index 867250d..85582c9 100644 --- a/src/main/java/com/example/demo/exception/ExceptionType.java +++ b/src/main/java/com/example/demo/exception/ExceptionType.java @@ -40,6 +40,7 @@ public enum ExceptionType { STUDY_ONCE_PARENT_COMMENT_MODIFICATION_BLOCKED(FORBIDDEN, "답변이 존재하는 질문은 수정 할 수 없습니다."), STUDY_ONCE_PARENT_COMMENT_REMOVAL_BLOCKED(FORBIDDEN, "답변이 존재하는 질문은 삭제 할 수 없습니다."), STUDY_ONCE_NAME_EMPTY_OR_WHITESPACE(BAD_REQUEST, "스터디 이름은 null, 빈 값, 혹은 공백만으로 이루어질 수 없습니다."), + STUDY_ONCE_OPEN_CHAT_URL_EMPTY_OR_WHITESPACE(BAD_REQUEST, "스터디의 오픈채팅방 URL은 null, 빈 값, 혹은 공백만으로 이루어질 수 없습니다."), MEMBER_NOT_FOUND(NOT_FOUND, "없는 회원입니다."), REVIEW_NOT_FOUND(NOT_FOUND, "없는 리뷰입니다."), REVIEW_OVER_CONTENT_SIZE(BAD_REQUEST, "리뷰 글자수가 최대 글자수 이하여야 합니다."), diff --git a/src/main/java/com/example/demo/mapper/StudyOnceMapper.java b/src/main/java/com/example/demo/mapper/StudyOnceMapper.java index 766bfbf..8510efa 100644 --- a/src/main/java/com/example/demo/mapper/StudyOnceMapper.java +++ b/src/main/java/com/example/demo/mapper/StudyOnceMapper.java @@ -64,6 +64,7 @@ public StudyOnceInfoResponse toStudyOnceInfoResponse(StudyOnce saved, boolean ca .canTalk(saved.isAbleToTalk()) .canJoin(canJoin) .isEnd(saved.isEnd()) + .openChatUrl(saved.getOpenChatUrl()) .build(); } diff --git a/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java b/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java index 5e7c89e..3f052f4 100644 --- a/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java +++ b/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java @@ -208,6 +208,9 @@ public void updateStudyOnce(long requestedMemberId, long studyOnceId, StudyOnceU if (request.getStartDateTime() != null && request.getEndDateTime() != null) { studyOnce.changeStudyOnceTime(request.getStartDateTime(), request.getEndDateTime()); } + if (request.getOpenChatUrl() != null) { + studyOnce.changeOpenChatUrl(request.getOpenChatUrl()); + } studyOnce.changeMaxMemberCount(request.getMaxMemberCount()); studyOnce.changeCanTalk(request.isCanTalk()); } diff --git a/src/test/java/com/example/demo/builder/TestStudyOnceBuilder.java b/src/test/java/com/example/demo/builder/TestStudyOnceBuilder.java index 228ce7e..2e28db3 100644 --- a/src/test/java/com/example/demo/builder/TestStudyOnceBuilder.java +++ b/src/test/java/com/example/demo/builder/TestStudyOnceBuilder.java @@ -17,6 +17,7 @@ public class TestStudyOnceBuilder { private int nowMemberCount = 0; private boolean isEnd = false; private boolean ableToTalk = true; + private String openChatUrl = "오픈채팅방 링크"; private Member leader; public TestStudyOnceBuilder id(Long id) { @@ -69,6 +70,11 @@ public TestStudyOnceBuilder leader(Member leader) { return this; } + public TestStudyOnceBuilder openChatUrl(String openChatUrl) { + this.openChatUrl = openChatUrl; + return this; + } + public StudyOnce build() { StudyOnce studyOnce = StudyOnce.builder() .id(id) @@ -81,6 +87,7 @@ public StudyOnce build() { .isEnd(isEnd) .ableToTalk(ableToTalk) .leader(leader) + .openChatUrl(openChatUrl) .build(); return studyOnce; } diff --git a/src/test/java/com/example/demo/domain/study/StudyMemberTest.java b/src/test/java/com/example/demo/domain/study/StudyMemberTest.java index 738cb38..c16e049 100644 --- a/src/test/java/com/example/demo/domain/study/StudyMemberTest.java +++ b/src/test/java/com/example/demo/domain/study/StudyMemberTest.java @@ -45,7 +45,7 @@ static Stream isConflictParameters() { void isConflict(TimeInterval timeInterval, boolean expected) { LocalDateTime start = BASE_TIME.plusHours(4); LocalDateTime end = BASE_TIME.plusHours(7); - StudyOnce studyOnce = makeStudyOnce(start, end); + StudyOnce studyOnce = makeStudyOnce("스터디 이름", start, end, "오픈채팅방 링크"); StudyMember studyMember = makeStudyMember(studyOnce); boolean actual = studyMember.isConflictWith(timeInterval.start, timeInterval.end); @@ -54,11 +54,13 @@ void isConflict(TimeInterval timeInterval, boolean expected) { .isEqualTo(expected); } - private StudyOnce makeStudyOnce(LocalDateTime start, LocalDateTime end) { + private StudyOnce makeStudyOnce(String name, LocalDateTime start, LocalDateTime end, String openChatUrl) { return StudyOnce.builder() + .name(name) .startDateTime(start) .endDateTime(end) .leader(new TestMemberBuilder().build()) + .openChatUrl(openChatUrl) .build(); } diff --git a/src/test/java/com/example/demo/domain/study/StudyOnceTest.java b/src/test/java/com/example/demo/domain/study/StudyOnceTest.java index 74f7648..773ff4a 100644 --- a/src/test/java/com/example/demo/domain/study/StudyOnceTest.java +++ b/src/test/java/com/example/demo/domain/study/StudyOnceTest.java @@ -84,9 +84,11 @@ void createStudyOnceFailCauseLongStudyTime() { @DisplayName("참여 가능 여부 결정 테스트") void canJoin(LocalDateTime base, LocalDateTime start, boolean expected) { StudyOnce studyOnce = StudyOnce.builder() + .name("스터디 이름") .startDateTime(start) .endDateTime(start.plusHours(4)) .leader(Member.builder().build()) + .openChatUrl("오픈채팅방 링크") .build(); boolean canJoin = studyOnce.canJoin(base); @@ -102,9 +104,11 @@ void create() { Member leader = Member.builder().id(LEADER_ID).build(); StudyOnce studyOnce = StudyOnce.builder() + .name("스터디 이름") .startDateTime(start) .endDateTime(start.plusHours(4)) .leader(leader) + .openChatUrl("오픈채팅방 링크") .build(); StudyOnce study = studyOnce.getStudyMembers().get(0).getStudy(); @@ -119,7 +123,7 @@ void create() { void tryJoin() { Member leader = Member.builder().id(LEADER_ID).build(); Member member = makeMemberWithStudyOnce(NOW.plusHours(9), NOW.plusHours(13)); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); studyOnce.tryJoin(member, NOW.plusHours(3).minusSeconds(1)); List collect = studyOnce.getStudyMembers() @@ -133,16 +137,20 @@ void tryJoin() { private static Member makeMemberWithStudyOnce(LocalDateTime start, LocalDateTime end) { Member member = Member.builder().id(MEMBER_ID).build(); - StudyMember studyMember = new StudyMember(member, makeStudy(member, start, end)); + StudyMember studyMember = new StudyMember(member, makeStudy(member, "스터디 이름", start, end, "오픈채팅방 링크")); member.setStudyMembers(new ArrayList<>(List.of(studyMember))); return member; } - private static StudyOnce makeStudy(Member leader, LocalDateTime start, LocalDateTime end) { + private static StudyOnce makeStudy(Member leader, String studyName, LocalDateTime start, LocalDateTime end, + String openChatUrl) { return StudyOnce.builder() + .name(studyName) .startDateTime(start) .endDateTime(end) .leader(leader) + .name(studyName) + .openChatUrl(openChatUrl) .build(); } @@ -152,7 +160,7 @@ void tryJoinFailByTimeOver() { Member leader = Member.builder().id(LEADER_ID).build(); Member member = Member.builder().id(MEMBER_ID).build(); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); Assertions.assertThatThrownBy( () -> studyOnce.tryJoin(member, NOW.plusHours(3).plusSeconds(1))) @@ -166,7 +174,7 @@ void tryJoinFailByConflict() { Member leader = Member.builder().id(LEADER_ID).build(); Member member = makeMemberWithStudyOnce(NOW.plusHours(9), NOW.plusHours(13)); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(5), NOW.plusHours(9)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(5), NOW.plusHours(9), "오픈채팅방 링크"); Assertions.assertThatThrownBy(() -> studyOnce.tryJoin(member, NOW)) .isInstanceOf(CafegoryException.class) @@ -178,7 +186,7 @@ void tryJoinFailByConflict() { void tryJoinFailByDuplicate() { Member leader = Member.builder().id(LEADER_ID).build(); Member member = makeMemberWithStudyOnce(NOW.plusHours(9), NOW.plusHours(13)); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); studyOnce.tryJoin(member, NOW); @@ -193,7 +201,7 @@ void tryQuit() { Member leader = Member.builder().id(LEADER_ID).build(); Member member = Member.builder().id(MEMBER_ID).build(); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); studyOnce.tryJoin(member, NOW); LocalDateTime validRequestTime = NOW.plusHours(3).minusSeconds(1); @@ -205,7 +213,7 @@ void tryQuit() { void tryQuitFailByTimeOver() { Member leader = Member.builder().id(LEADER_ID).build(); Member member = Member.builder().id(MEMBER_ID).build(); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); studyOnce.tryJoin(member, NOW); Assertions.assertThatThrownBy( () -> studyOnce.tryQuit(member, NOW.plusHours(3).plusSeconds(1))) @@ -218,7 +226,7 @@ void tryQuitFailByTimeOver() { void tryQuitFailByNotJoin() { Member leader = Member.builder().id(LEADER_ID).build(); Member member = Member.builder().id(MEMBER_ID).build(); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); Assertions.assertThatThrownBy( () -> studyOnce.tryQuit(member, NOW)) .isInstanceOf(CafegoryException.class) @@ -229,7 +237,7 @@ void tryQuitFailByNotJoin() { @DisplayName("스터디 이름 변경, null 검증") void validate_null_by_changeName() { Member leader = Member.builder().id(LEADER_ID).build(); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); assertThatThrownBy(() -> studyOnce.changeName(null)) .isInstanceOf(CafegoryException.class) .hasMessage(STUDY_ONCE_NAME_EMPTY_OR_WHITESPACE.getErrorMessage()); @@ -240,17 +248,38 @@ void validate_null_by_changeName() { @DisplayName("스터디 이름 변경, 빈값, 공백문자 검증") void validate_empty_or_whitespace_by_changeName(String value) { Member leader = Member.builder().id(LEADER_ID).build(); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); assertThatThrownBy(() -> studyOnce.changeName(value)) .isInstanceOf(CafegoryException.class) .hasMessage(STUDY_ONCE_NAME_EMPTY_OR_WHITESPACE.getErrorMessage()); } + @Test + @DisplayName("스터디 오픈채팅방 url 변경, null 검증") + void validate_null_by_changeOpenChatUrl() { + Member leader = Member.builder().id(LEADER_ID).build(); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); + assertThatThrownBy(() -> studyOnce.changeOpenChatUrl(null)) + .isInstanceOf(CafegoryException.class) + .hasMessage(STUDY_ONCE_OPEN_CHAT_URL_EMPTY_OR_WHITESPACE.getErrorMessage()); + } + + @ParameterizedTest + @ValueSource(strings = {"", " "}) + @DisplayName("스터디 오픈채팅방 url 변경, 빈값, 공백문자 검증") + void validate_empty_or_whitespace_by_changeOpenChatUrl(String value) { + Member leader = Member.builder().id(LEADER_ID).build(); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); + assertThatThrownBy(() -> studyOnce.changeOpenChatUrl(value)) + .isInstanceOf(CafegoryException.class) + .hasMessage(STUDY_ONCE_OPEN_CHAT_URL_EMPTY_OR_WHITESPACE.getErrorMessage()); + } + @Test @DisplayName("최대 참여인원 5명이다. 정상동작") void changeMaxMemberCount() { Member leader = Member.builder().id(LEADER_ID).build(); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); assertDoesNotThrow(() -> studyOnce.changeMaxMemberCount(5)); } @@ -258,7 +287,7 @@ void changeMaxMemberCount() { @DisplayName("최대 참여인원은 5명이다. 6명이면 예외가 터진다.") void validate_maxMemberCount_by_changeMaxMemberCount() { Member leader = Member.builder().id(LEADER_ID).build(); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); assertThatThrownBy(() -> studyOnce.changeMaxMemberCount(6)) .isInstanceOf(CafegoryException.class) .hasMessage(STUDY_ONCE_LIMIT_MEMBER_CAPACITY.getErrorMessage()); @@ -269,11 +298,13 @@ void validate_maxMemberCount_by_changeMaxMemberCount() { void validate_maxOrNowMemberCount_by_changeMaxMemberCount() { Member leader = Member.builder().id(LEADER_ID).build(); StudyOnce studyOnce = StudyOnce.builder() + .name("스터디 이름") .startDateTime(NOW.plusHours(4)) .endDateTime(NOW.plusHours(8)) .maxMemberCount(4) .nowMemberCount(1) .leader(leader) + .openChatUrl("오픈채팅방 링크") .build(); assertThatThrownBy(() -> studyOnce.changeMaxMemberCount(0)) @@ -285,7 +316,7 @@ void validate_maxOrNowMemberCount_by_changeMaxMemberCount() { @DisplayName("카공에 참여인원이 카공장만 있으면 true 반환") void doesOnlyLeaderExist_then_true() { Member leader = Member.builder().id(LEADER_ID).build(); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); boolean doesOnlyLeaderExist = studyOnce.doesOnlyLeaderExist(); assertThat(doesOnlyLeaderExist).isTrue(); @@ -296,7 +327,7 @@ void doesOnlyLeaderExist_then_true() { void doesOnlyLeaderExist_then_false() { Member leader = Member.builder().id(LEADER_ID).build(); Member member = makeMemberWithStudyOnce(NOW.plusHours(9), NOW.plusHours(13)); - StudyOnce studyOnce = makeStudy(leader, NOW.plusHours(4), NOW.plusHours(8)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); studyOnce.tryJoin(member, NOW.plusHours(3).minusSeconds(1)); diff --git a/src/test/java/com/example/demo/repository/study/InMemoryStudyOnceRepository.java b/src/test/java/com/example/demo/repository/study/InMemoryStudyOnceRepository.java index 520aecf..0952eff 100644 --- a/src/test/java/com/example/demo/repository/study/InMemoryStudyOnceRepository.java +++ b/src/test/java/com/example/demo/repository/study/InMemoryStudyOnceRepository.java @@ -38,6 +38,7 @@ private StudyOnce makeStudyOnceWithId(StudyOnce studyOnce) { .ableToTalk(studyOnce.isAbleToTalk()) .cafe(studyOnce.getCafe()) .isEnd(studyOnce.isEnd()) + .openChatUrl(studyOnce.getOpenChatUrl()) .build(); } diff --git a/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java b/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java index 6b7eef5..8ee9872 100644 --- a/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java +++ b/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java @@ -148,6 +148,7 @@ private static StudyOnceCreateResponse makeExpectedStudyOnceCreateResult(long ca .canTalk(studyOnceCreateRequest.isCanTalk()) .canJoin(canJoin) .isEnd(isEnd) + .openChatUrl(studyOnceCreateRequest.getOpenChatUrl()) .build(); } @@ -585,7 +586,7 @@ void updateStudyOnce() { long studyOnceId = searchResponse.getStudyOnceId(); long cafeId2 = cafePersistHelper.persistDefaultCafe().getId(); StudyOnceUpdateRequest request = new StudyOnceUpdateRequest(cafeId2, "변경된카공이름", start.plusHours(5), - start.plusHours(6), 5, false); + start.plusHours(6), 5, false, "오픈채팅방 링크"); studyOnceService.updateStudyOnce(leaderId, studyOnceId, request, LocalDateTime.now()); StudyOnce studyOnce = studyOnceRepository.findById(studyOnceId).get(); @@ -596,7 +597,8 @@ void updateStudyOnce() { () -> assertThat(studyOnce.getStartDateTime()).isEqualTo(request.getStartDateTime()), () -> assertThat(studyOnce.getEndDateTime()).isEqualTo(request.getEndDateTime()), () -> assertThat(studyOnce.getMaxMemberCount()).isEqualTo(request.getMaxMemberCount()), - () -> assertThat(studyOnce.isAbleToTalk()).isEqualTo(request.isCanTalk()) + () -> assertThat(studyOnce.isAbleToTalk()).isEqualTo(request.isCanTalk()), + () -> assertThat(studyOnce.getOpenChatUrl()).isEqualTo(request.getOpenChatUrl()) ); } @@ -611,7 +613,7 @@ void update_studyOnce_by_invalid_cafe_then_exception() { StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); long studyOnceId = searchResponse.getStudyOnceId(); StudyOnceUpdateRequest request = new StudyOnceUpdateRequest(999L, "변경된카공이름", start.plusHours(5), - start.plusHours(6), 5, false); + start.plusHours(6), 5, false, "오픈채팅방 링크"); assertThatThrownBy(() -> studyOnceService.updateStudyOnce(leaderId, studyOnceId, request, LocalDateTime.now())) .isInstanceOf(CafegoryException.class) @@ -629,7 +631,7 @@ void update_studyOnce_by_invalid_member_then_exception() { StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); long studyOnceId = searchResponse.getStudyOnceId(); StudyOnceUpdateRequest request = new StudyOnceUpdateRequest(cafeId1, "변경된카공이름", start.plusHours(5), - start.plusHours(6), 5, false); + start.plusHours(6), 5, false, "오픈채팅방 링크"); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); assertThatThrownBy( @@ -654,7 +656,7 @@ void updateStudyOncePartially() { syncStudyOnceRepositoryAndStudyMemberRepository(); StudyOnceUpdateRequest request = new StudyOnceUpdateRequest(cafeId2, null, null, - null, 5, false); + null, 5, false, null); studyOnceService.updateStudyOncePartially(leaderId, studyOnceId, request, LocalDateTime.now()); StudyOnce studyOnce = studyOnceRepository.findById(studyOnceId).get(); @@ -664,7 +666,8 @@ void updateStudyOncePartially() { () -> assertThat(studyOnce.getStartDateTime()).isEqualTo(searchResponse.getStartDateTime()), () -> assertThat(studyOnce.getEndDateTime()).isEqualTo(searchResponse.getEndDateTime()), () -> assertThat(studyOnce.getMaxMemberCount()).isEqualTo(request.getMaxMemberCount()), - () -> assertThat(studyOnce.isAbleToTalk()).isEqualTo(searchResponse.isCanTalk()) + () -> assertThat(studyOnce.isAbleToTalk()).isEqualTo(searchResponse.isCanTalk()), + () -> assertThat(studyOnce.getOpenChatUrl()).isEqualTo(searchResponse.getOpenChatUrl()) ); } @@ -684,7 +687,7 @@ void update_studyOnce_partially_then_update_partially() { syncStudyOnceRepositoryAndStudyMemberRepository(); StudyOnceUpdateRequest request = new StudyOnceUpdateRequest(cafeId2, "변경된카공이름", start.plusHours(5), - start.plusHours(6), 5, false); + start.plusHours(6), 5, false, "오픈채팅방 링크"); studyOnceService.updateStudyOncePartially(leaderId, studyOnceId, request, LocalDateTime.now()); StudyOnce studyOnce = studyOnceRepository.findById(studyOnceId).get(); @@ -694,7 +697,8 @@ void update_studyOnce_partially_then_update_partially() { () -> assertThat(studyOnce.getStartDateTime()).isEqualTo(searchResponse.getStartDateTime()), () -> assertThat(studyOnce.getEndDateTime()).isEqualTo(searchResponse.getEndDateTime()), () -> assertThat(studyOnce.getMaxMemberCount()).isEqualTo(request.getMaxMemberCount()), - () -> assertThat(studyOnce.isAbleToTalk()).isEqualTo(searchResponse.isCanTalk()) + () -> assertThat(studyOnce.isAbleToTalk()).isEqualTo(searchResponse.isCanTalk()), + () -> assertThat(studyOnce.getOpenChatUrl()).isEqualTo(searchResponse.getOpenChatUrl()) ); } @@ -709,7 +713,7 @@ void update_studyOnce_partially_by_invalid_member_then_exception() { StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); long studyOnceId = searchResponse.getStudyOnceId(); StudyOnceUpdateRequest request = new StudyOnceUpdateRequest(cafeId1, null, null, - null, 5, true); + null, 5, true, null); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); assertThatThrownBy( From cd7ca52f36956ec7930045bfb1a0a006f34c1446 Mon Sep 17 00:00:00 2001 From: donghyunkim Date: Thu, 25 Apr 2024 17:15:01 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20=EC=B9=B4=EA=B3=B5=20=EB=AA=A8?= =?UTF-8?q?=EC=A7=91=EA=B8=80=20=EC=A1=B0=ED=9A=8C=20=EC=98=A4=ED=94=88?= =?UTF-8?q?=EC=B1=84=ED=8C=85=EB=B0=A9=20=EB=A7=81=ED=81=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/demo/dto/study/StudyOnceSearchResponse.java | 1 + src/main/java/com/example/demo/mapper/StudyOnceMapper.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/example/demo/dto/study/StudyOnceSearchResponse.java b/src/main/java/com/example/demo/dto/study/StudyOnceSearchResponse.java index e0baec5..8b590db 100644 --- a/src/main/java/com/example/demo/dto/study/StudyOnceSearchResponse.java +++ b/src/main/java/com/example/demo/dto/study/StudyOnceSearchResponse.java @@ -20,5 +20,6 @@ public class StudyOnceSearchResponse { private boolean canTalk; private boolean canJoin; private boolean isEnd; + private String openChatUrl; } diff --git a/src/main/java/com/example/demo/mapper/StudyOnceMapper.java b/src/main/java/com/example/demo/mapper/StudyOnceMapper.java index 8510efa..1b5d54a 100644 --- a/src/main/java/com/example/demo/mapper/StudyOnceMapper.java +++ b/src/main/java/com/example/demo/mapper/StudyOnceMapper.java @@ -82,6 +82,7 @@ public StudyOnceSearchResponse toStudyOnceSearchResponse(StudyOnce saved, boolea .canTalk(saved.isAbleToTalk()) .canJoin(canJoin) .isEnd(saved.isEnd()) + .openChatUrl(saved.getOpenChatUrl()) .build(); } From 8d34c4df1bee871bf6468f60bf8e0bef7e94c8e6 Mon Sep 17 00:00:00 2001 From: donghyunkim Date: Thu, 25 Apr 2024 19:50:57 +0900 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EC=9D=B4=20?= =?UTF-8?q?=EC=95=84=EB=8B=90=EB=95=8C=20=EC=B9=B4=EA=B3=B5=20=EB=AA=A8?= =?UTF-8?q?=EC=A7=91=EA=B8=80=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20=EC=B0=B8?= =?UTF-8?q?=EC=84=9D=EC=97=AC=EB=B6=80=20false=20=EB=B0=98=ED=99=98=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/demo/domain/study/StudyOnce.java | 5 +++++ .../dto/study/StudyOnceSearchResponse.java | 1 + .../example/demo/mapper/StudyOnceMapper.java | 3 ++- .../demo/service/study/StudyOnceService.java | 2 ++ .../service/study/StudyOnceServiceImpl.java | 7 +++++- .../demo/domain/study/StudyOnceTest.java | 22 +++++++++++++++++++ .../study/StudyOnceServiceImplTest.java | 16 ++++++++++++++ 7 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/demo/domain/study/StudyOnce.java b/src/main/java/com/example/demo/domain/study/StudyOnce.java index 90fa6fd..c20327f 100644 --- a/src/main/java/com/example/demo/domain/study/StudyOnce.java +++ b/src/main/java/com/example/demo/domain/study/StudyOnce.java @@ -220,4 +220,9 @@ private void validateEmptyOrWhiteSpace(String target, ExceptionType exceptionTyp throw new CafegoryException(exceptionType); } } + + public boolean isAttendance(Member member) { + return studyMembers.stream() + .anyMatch(s -> s.getId().getMemberId().equals(member.getId())); + } } diff --git a/src/main/java/com/example/demo/dto/study/StudyOnceSearchResponse.java b/src/main/java/com/example/demo/dto/study/StudyOnceSearchResponse.java index 8b590db..14dd563 100644 --- a/src/main/java/com/example/demo/dto/study/StudyOnceSearchResponse.java +++ b/src/main/java/com/example/demo/dto/study/StudyOnceSearchResponse.java @@ -21,5 +21,6 @@ public class StudyOnceSearchResponse { private boolean canJoin; private boolean isEnd; private String openChatUrl; + private boolean isAttendance; } diff --git a/src/main/java/com/example/demo/mapper/StudyOnceMapper.java b/src/main/java/com/example/demo/mapper/StudyOnceMapper.java index 1b5d54a..c50aa76 100644 --- a/src/main/java/com/example/demo/mapper/StudyOnceMapper.java +++ b/src/main/java/com/example/demo/mapper/StudyOnceMapper.java @@ -68,7 +68,7 @@ public StudyOnceInfoResponse toStudyOnceInfoResponse(StudyOnce saved, boolean ca .build(); } - public StudyOnceSearchResponse toStudyOnceSearchResponse(StudyOnce saved, boolean canJoin) { + public StudyOnceSearchResponse toStudyOnceSearchResponse(StudyOnce saved, boolean canJoin, boolean isAttendance) { return StudyOnceSearchResponse.builder() .cafeId(saved.getCafe().getId()) .creatorId(saved.getLeader().getId()) @@ -83,6 +83,7 @@ public StudyOnceSearchResponse toStudyOnceSearchResponse(StudyOnce saved, boolea .canJoin(canJoin) .isEnd(saved.isEnd()) .openChatUrl(saved.getOpenChatUrl()) + .isAttendance(isAttendance) .build(); } diff --git a/src/main/java/com/example/demo/service/study/StudyOnceService.java b/src/main/java/com/example/demo/service/study/StudyOnceService.java index 5b3ae97..1ff9419 100644 --- a/src/main/java/com/example/demo/service/study/StudyOnceService.java +++ b/src/main/java/com/example/demo/service/study/StudyOnceService.java @@ -24,6 +24,8 @@ public interface StudyOnceService { StudyOnceSearchResponse searchByStudyId(long studyId); + StudyOnceSearchResponse searchStudyOnceWithMemberParticipation(long studyId, long memberId); + UpdateAttendanceResponse updateAttendances(long leaderId, long studyOnceId, UpdateAttendanceRequest request, LocalDateTime now); diff --git a/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java b/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java index 3f052f4..cdd8787 100644 --- a/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java +++ b/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java @@ -108,7 +108,12 @@ public StudyOnceSearchResponse searchByStudyId(long studyId) { StudyOnce searched = studyOnceRepository.findById(studyId) .orElseThrow(() -> new CafegoryException(STUDY_ONCE_NOT_FOUND)); boolean canJoin = searched.canJoin(LocalDateTime.now()); - return studyOnceMapper.toStudyOnceSearchResponse(searched, canJoin); + return studyOnceMapper.toStudyOnceSearchResponse(searched, canJoin, false); + } + + @Override + public StudyOnceSearchResponse searchStudyOnceWithMemberParticipation(long studyId, long memberId) { + return null; } @Override diff --git a/src/test/java/com/example/demo/domain/study/StudyOnceTest.java b/src/test/java/com/example/demo/domain/study/StudyOnceTest.java index 773ff4a..afdde1b 100644 --- a/src/test/java/com/example/demo/domain/study/StudyOnceTest.java +++ b/src/test/java/com/example/demo/domain/study/StudyOnceTest.java @@ -335,4 +335,26 @@ void doesOnlyLeaderExist_then_false() { assertThat(doesOnlyLeaderExist).isFalse(); } + @Test + @DisplayName("멤버가 스터디에 참여했으면 true 반환") + void isAttendance() { + Member leader = Member.builder().id(LEADER_ID).build(); + Member member = makeMemberWithStudyOnce(NOW.plusHours(9), NOW.plusHours(13)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); + studyOnce.tryJoin(member, NOW.plusHours(3).minusSeconds(1)); + + boolean isAttendance = studyOnce.isAttendance(member); + assertThat(isAttendance).isTrue(); + } + + @Test + @DisplayName("멤버가 스터디에 참여하지 않았으면 false 반환") + void isNotAttendance() { + Member leader = Member.builder().id(LEADER_ID).build(); + Member member = makeMemberWithStudyOnce(NOW.plusHours(9), NOW.plusHours(13)); + StudyOnce studyOnce = makeStudy(leader, "스터디 이름", NOW.plusHours(4), NOW.plusHours(8), "오픈채팅방 링크"); + + boolean isAttendance = studyOnce.isAttendance(member); + assertThat(isAttendance).isFalse(); + } } diff --git a/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java b/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java index 8ee9872..dd2cfef 100644 --- a/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java +++ b/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java @@ -116,9 +116,25 @@ void searchByStudyId() { assertThat(studyOnceSearchResponse.getStudyOnceId()).isEqualTo(result.getStudyOnceId()); } + @Test + @DisplayName("회원이 아닐떄 카공을 조회하면 카공의 참석여부는 false를 반환한다.") + void searchByStudyId_when_not_member() { + LocalDateTime start = LocalDateTime.now().plusHours(3).plusMinutes(1); + LocalDateTime end = start.plusHours(1); + long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); + StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); + + StudyOnceCreateResponse result = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceSearchResponse studyOnceSearchResponse = studyOnceService.searchByStudyId(result.getStudyOnceId()); + + assertThat(studyOnceSearchResponse.isAttendance()).isFalse(); + } + @Test @DisplayName("정상 생성 테스트") void create() { + LocalDateTime start = LocalDateTime.now().plusHours(3).plusMinutes(1); LocalDateTime end = start.plusHours(1); long cafeId = cafePersistHelper.persistDefaultCafe().getId(); From 0154a50f41074dcfe9e4ca1e20add7ae33a172b1 Mon Sep 17 00:00:00 2001 From: donghyunkim Date: Thu, 25 Apr 2024 20:00:52 +0900 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20=EC=B9=B4=EA=B3=B5=20=EB=A9=A4?= =?UTF-8?q?=EB=B2=84=EA=B0=80=20=EC=B9=B4=EA=B3=B5=EC=9D=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=ED=95=A0=EB=95=8C=20=EC=B0=B8=EC=84=9D=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/service/study/StudyOnceService.java | 2 +- .../service/study/StudyOnceServiceImpl.java | 8 +++- .../study/StudyOnceServiceImplTest.java | 40 ++++++++++++++++++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/demo/service/study/StudyOnceService.java b/src/main/java/com/example/demo/service/study/StudyOnceService.java index 1ff9419..a765432 100644 --- a/src/main/java/com/example/demo/service/study/StudyOnceService.java +++ b/src/main/java/com/example/demo/service/study/StudyOnceService.java @@ -24,7 +24,7 @@ public interface StudyOnceService { StudyOnceSearchResponse searchByStudyId(long studyId); - StudyOnceSearchResponse searchStudyOnceWithMemberParticipation(long studyId, long memberId); + StudyOnceSearchResponse searchStudyOnceWithMemberParticipation(long studyOnceId, long memberId); UpdateAttendanceResponse updateAttendances(long leaderId, long studyOnceId, UpdateAttendanceRequest request, LocalDateTime now); diff --git a/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java b/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java index cdd8787..2cbb8ad 100644 --- a/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java +++ b/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java @@ -112,8 +112,12 @@ public StudyOnceSearchResponse searchByStudyId(long studyId) { } @Override - public StudyOnceSearchResponse searchStudyOnceWithMemberParticipation(long studyId, long memberId) { - return null; + public StudyOnceSearchResponse searchStudyOnceWithMemberParticipation(long studyOnceId, long memberId) { + StudyOnce searched = studyOnceRepository.findById(studyOnceId) + .orElseThrow(() -> new CafegoryException(STUDY_ONCE_NOT_FOUND)); + boolean canJoin = searched.canJoin(LocalDateTime.now()); + boolean isAttendance = searched.isAttendance(findMemberById(memberId)); + return studyOnceMapper.toStudyOnceSearchResponse(searched, canJoin, isAttendance); } @Override diff --git a/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java b/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java index dd2cfef..6b95a83 100644 --- a/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java +++ b/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java @@ -124,13 +124,51 @@ void searchByStudyId_when_not_member() { long cafeId = cafePersistHelper.persistDefaultCafe().getId(); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - StudyOnceCreateResponse result = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceSearchResponse studyOnceSearchResponse = studyOnceService.searchByStudyId(result.getStudyOnceId()); assertThat(studyOnceSearchResponse.isAttendance()).isFalse(); } + @Test + @DisplayName("회원이 카공을 조회할때 카공 멤버라면 참석여부는 true를 반환한다.") + void searchStudyOnceWithMemberParticipation_when_takes_attendance() { + LocalDateTime start = LocalDateTime.now().plusHours(4); + LocalDateTime end = start.plusHours(4); + long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); + long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + long studyOnceId = searchResponse.getStudyOnceId(); + long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); + studyOnceService.tryJoin(memberId, studyOnceId); + syncStudyOnceRepositoryAndStudyMemberRepository(); + + StudyOnceSearchResponse response = studyOnceService.searchStudyOnceWithMemberParticipation( + studyOnceId, memberId); + + assertThat(response.isAttendance()).isTrue(); + } + + @Test + @DisplayName("회원이 카공을 조회할때 카공 멤버가 아니라면 참석여부는 false를 반환한다.") + void searchStudyOnceWithMemberParticipation_when_not_take_attendance() { + LocalDateTime start = LocalDateTime.now().plusHours(4); + LocalDateTime end = start.plusHours(4); + long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); + long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + long studyOnceId = searchResponse.getStudyOnceId(); + long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); + + StudyOnceSearchResponse response = studyOnceService.searchStudyOnceWithMemberParticipation( + studyOnceId, memberId); + + assertThat(response.isAttendance()).isFalse(); + } + @Test @DisplayName("정상 생성 테스트") void create() { From 571578498ee396939819630a7a711ab9f4688867 Mon Sep 17 00:00:00 2001 From: donghyunkim Date: Thu, 25 Apr 2024 20:06:52 +0900 Subject: [PATCH 6/6] =?UTF-8?q?feat:=20=EC=B9=B4=EA=B3=B5=20=EB=AA=A8?= =?UTF-8?q?=EC=A7=91=EA=B8=80=20=EC=A1=B0=ED=9A=8C=EC=97=90=20=EB=A9=A4?= =?UTF-8?q?=EB=B2=84=20=EC=B0=B8=EC=97=AC=EC=A0=95=EB=B3=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/demo/controller/StudyOnceController.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/demo/controller/StudyOnceController.java b/src/main/java/com/example/demo/controller/StudyOnceController.java index 4525b04..dec8ca4 100644 --- a/src/main/java/com/example/demo/controller/StudyOnceController.java +++ b/src/main/java/com/example/demo/controller/StudyOnceController.java @@ -4,7 +4,9 @@ import java.time.LocalDateTime; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -56,7 +58,14 @@ public class StudyOnceController { private final StudyOnceCommentQueryService studyOnceCommentQueryService; @GetMapping("/{studyOnceId:[0-9]+}") - public ResponseEntity search(@PathVariable Long studyOnceId) { + public ResponseEntity search(@PathVariable Long studyOnceId, + @RequestHeader(value = "Authorization", required = false) String authorization) { + if (StringUtils.hasText(authorization)) { + long memberId = cafegoryTokenManager.getIdentityId(authorization); + StudyOnceSearchResponse response = studyOnceService.searchStudyOnceWithMemberParticipation(studyOnceId, + memberId); + return new ResponseEntity<>(response, HttpStatus.OK); + } StudyOnceSearchResponse response = studyOnceService.searchByStudyId(studyOnceId); return ResponseEntity.ok(response); }