diff --git a/src/main/java/com/example/demo/controller/StudyOnceController.java b/src/main/java/com/example/demo/controller/StudyOnceController.java index 01d8570..db40810 100644 --- a/src/main/java/com/example/demo/controller/StudyOnceController.java +++ b/src/main/java/com/example/demo/controller/StudyOnceController.java @@ -2,6 +2,7 @@ import static com.example.demo.exception.ExceptionType.*; +import java.time.LocalDate; import java.time.LocalDateTime; import org.springframework.http.HttpStatus; @@ -84,7 +85,8 @@ public ResponseEntity create( @RequestBody @Validated StudyOnceCreateRequest studyOnceCreateRequest, @RequestHeader("Authorization") String authorization) { long memberId = cafegoryTokenManager.getIdentityId(authorization); - StudyOnceCreateResponse response = studyOnceService.createStudy(memberId, studyOnceCreateRequest); + StudyOnceCreateResponse response = studyOnceService.createStudy(memberId, studyOnceCreateRequest, + LocalDate.now()); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/example/demo/domain/cafe/BusinessHour.java b/src/main/java/com/example/demo/domain/cafe/BusinessHour.java index b6434bb..6ce0770 100644 --- a/src/main/java/com/example/demo/domain/cafe/BusinessHour.java +++ b/src/main/java/com/example/demo/domain/cafe/BusinessHour.java @@ -51,4 +51,8 @@ public boolean existsMatchingDayOfWeek(LocalDateTime now) { return false; } } + + public boolean matchesDayOfWeek(DayOfWeek dayOfWeek) { + return day.equals(dayOfWeek.toString()); + } } diff --git a/src/main/java/com/example/demo/domain/cafe/BusinessHourOpenChecker.java b/src/main/java/com/example/demo/domain/cafe/BusinessHourOpenChecker.java index fe07a30..4df9a16 100644 --- a/src/main/java/com/example/demo/domain/cafe/BusinessHourOpenChecker.java +++ b/src/main/java/com/example/demo/domain/cafe/BusinessHourOpenChecker.java @@ -66,10 +66,10 @@ public boolean checkWithBusinessHours(List businessHours, LocalDat hour -> checkByNowTime(DayOfWeek.valueOf(hour.getDay()), hour.getStartTime(), hour.getEndTime(), now)); } - public boolean checkBetweenHours(LocalTime businessStartTime, LocalTime businessEndTime, + public boolean checkBetweenBusinessHours(LocalTime businessStartTime, LocalTime businessEndTime, LocalTime chosenStartTime, LocalTime chosenEndTime) { - if ((chosenStartTime.equals(businessStartTime) || chosenStartTime.isBefore(businessStartTime)) - && (chosenEndTime.equals(businessEndTime) || chosenEndTime.isAfter(businessEndTime))) { + if ((businessStartTime.equals(chosenStartTime) || businessStartTime.isBefore(chosenStartTime)) + && (businessEndTime.equals(chosenEndTime) || businessEndTime.isAfter(chosenEndTime))) { return true; } return false; diff --git a/src/main/java/com/example/demo/domain/cafe/Cafe.java b/src/main/java/com/example/demo/domain/cafe/Cafe.java index 3285e11..45d63ff 100644 --- a/src/main/java/com/example/demo/domain/cafe/Cafe.java +++ b/src/main/java/com/example/demo/domain/cafe/Cafe.java @@ -1,5 +1,8 @@ package com.example.demo.domain.cafe; +import static com.example.demo.exception.ExceptionType.*; + +import java.time.DayOfWeek; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -17,6 +20,7 @@ import com.example.demo.domain.review.Review; import com.example.demo.domain.study.StudyOnce; +import com.example.demo.exception.CafegoryException; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -87,4 +91,11 @@ public OptionalDouble calcAverageRating() { .mapToDouble(Review::getRate) .average(); } + + public BusinessHour findBusinessHour(DayOfWeek dayOfWeek) { + return businessHours.stream() + .filter(businessHour -> businessHour.matchesDayOfWeek(dayOfWeek)) + .findFirst() + .orElseThrow(() -> new CafegoryException(CAFE_NOT_FOUND_DAY_OF_WEEK)); + } } diff --git a/src/main/java/com/example/demo/exception/ExceptionType.java b/src/main/java/com/example/demo/exception/ExceptionType.java index 85582c9..31b8f2c 100644 --- a/src/main/java/com/example/demo/exception/ExceptionType.java +++ b/src/main/java/com/example/demo/exception/ExceptionType.java @@ -14,6 +14,7 @@ public enum ExceptionType { JWT_DESTROYED(UNAUTHORIZED, "JWT 토큰이 잘못되었습니다."), TOKEN_NOT_FOUND(UNAUTHORIZED, "토큰이 없습니다."), TOKEN_REFRESH_REJECT(UNAUTHORIZED, "토큰을 재발행할 수 없습니다."), + STUDY_ONCE_CREATE_BETWEEN_CAFE_BUSINESS_HOURS(BAD_REQUEST, "카공 생성시 시작시간과 종료시간은 카페 영업시간내에 포함되어야 합니다."), STUDY_ONCE_WRONG_START_TIME(BAD_REQUEST, "카공 시작 시간은 현재 시간보다 최소 3시간 이후여야 합니다."), STUDY_ONCE_SHORT_DURATION(BAD_REQUEST, "카공 시간은 1시간 이상이어야 합니다."), STUDY_ONCE_LONG_DURATION(BAD_REQUEST, "카공 시간은 5시간 미만이어야 합니다."), 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 c530d9b..5dfcfe6 100644 --- a/src/main/java/com/example/demo/service/study/StudyOnceService.java +++ b/src/main/java/com/example/demo/service/study/StudyOnceService.java @@ -1,5 +1,6 @@ package com.example.demo.service.study; +import java.time.LocalDate; import java.time.LocalDateTime; import com.example.demo.domain.study.Attendance; @@ -31,7 +32,8 @@ UpdateAttendanceResponse updateAttendances(long leaderId, long studyOnceId, void updateAttendance(long leaderId, long studyOnceId, long memberId, Attendance attendance, LocalDateTime now); - StudyOnceCreateResponse createStudy(long leaderId, StudyOnceCreateRequest studyOnceCreateRequest); + StudyOnceCreateResponse createStudy(long leaderId, StudyOnceCreateRequest studyOnceCreateRequest, + LocalDate nowDate); Long changeCafe(Long requestMemberId, Long studyOnceId, Long changingCafeId); 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 f08b662..d23eae2 100644 --- a/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java +++ b/src/main/java/com/example/demo/service/study/StudyOnceServiceImpl.java @@ -3,13 +3,17 @@ import static com.example.demo.exception.ExceptionType.*; import java.time.Duration; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.List; import java.util.stream.Collectors; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.example.demo.domain.cafe.BusinessHour; +import com.example.demo.domain.cafe.BusinessHourOpenChecker; import com.example.demo.domain.cafe.Cafe; import com.example.demo.domain.member.Member; import com.example.demo.domain.study.Attendance; @@ -51,6 +55,7 @@ public class StudyOnceServiceImpl implements StudyOnceService { private final StudyMemberRepository studyMemberRepository; private final StudyOnceMapper studyOnceMapper; private final StudyMemberMapper studyMemberMapper; + private final BusinessHourOpenChecker openChecker = new BusinessHourOpenChecker(); @Override public void tryJoin(long memberIdThatExpectedToJoin, long studyId) { @@ -190,16 +195,24 @@ private StudyOnce findStudyOnceById(long studyOnceId) { } @Override - public StudyOnceCreateResponse createStudy(long leaderId, StudyOnceCreateRequest studyOnceCreateRequest) { - Cafe cafe = cafeRepository.findById(studyOnceCreateRequest.getCafeId()) - .orElseThrow(() -> new CafegoryException(CAFE_NOT_FOUND)); - //ToDo 카페 영업시간 이내인지 확인 하는 작업 추가 필요 - LocalDateTime startDateTime = studyOnceCreateRequest.getStartDateTime(); - Member leader = getMember(leaderId, startDateTime); - StudyOnce studyOnce = studyOnceMapper.toNewEntity(studyOnceCreateRequest, cafe, leader); + public StudyOnceCreateResponse createStudy(long leaderId, StudyOnceCreateRequest request, LocalDate nowDate) { + Cafe cafe = findCafeById(request.getCafeId()); + BusinessHour businessHour = cafe.findBusinessHour(nowDate.getDayOfWeek()); + validateBetweenBusinessHour(request.getStartDateTime().toLocalTime(), request.getEndDateTime().toLocalTime(), + businessHour); + Member leader = getMember(leaderId, request.getStartDateTime()); + StudyOnce studyOnce = studyOnceMapper.toNewEntity(request, cafe, leader); StudyOnce saved = studyOnceRepository.save(studyOnce); - boolean canJoin = true; - return studyOnceMapper.toStudyOnceCreateResponse(saved, canJoin); + return studyOnceMapper.toStudyOnceCreateResponse(saved, true); + } + + private void validateBetweenBusinessHour(LocalTime studyOnceStartTime, LocalTime studyOnceEndTime, + BusinessHour businessHour) { + boolean isBetweenBusinessHour = openChecker.checkBetweenBusinessHours(businessHour.getStartTime(), + businessHour.getEndTime(), studyOnceStartTime, studyOnceEndTime); + if (!isBetweenBusinessHour) { + throw new CafegoryException(STUDY_ONCE_CREATE_BETWEEN_CAFE_BUSINESS_HOURS); + } } @Override diff --git a/src/test/java/com/example/demo/builder/TestBusinessHourBuilder.java b/src/test/java/com/example/demo/builder/TestBusinessHourBuilder.java new file mode 100644 index 0000000..08a3217 --- /dev/null +++ b/src/test/java/com/example/demo/builder/TestBusinessHourBuilder.java @@ -0,0 +1,50 @@ +package com.example.demo.builder; + +import java.time.LocalTime; + +import com.example.demo.domain.cafe.BusinessHour; +import com.example.demo.domain.cafe.Cafe; + +public class TestBusinessHourBuilder { + + private Long id; + private String day; + private LocalTime startTime = LocalTime.MIN; + private LocalTime endTime = LocalTime.MAX; + private Cafe cafe; + + public TestBusinessHourBuilder id(Long id) { + this.id = id; + return this; + } + + public TestBusinessHourBuilder day(String day) { + this.day = day; + return this; + } + + public TestBusinessHourBuilder startTime(LocalTime startTime) { + this.startTime = startTime; + return this; + } + + public TestBusinessHourBuilder endTime(LocalTime endTime) { + this.endTime = endTime; + return this; + } + + public TestBusinessHourBuilder cafe(Cafe cafe) { + this.cafe = cafe; + return this; + } + + public BusinessHour build() { + return BusinessHour.builder() + .id(id) + .day(day) + .startTime(startTime) + .endTime(endTime) + .cafe(cafe) + .build(); + } +} diff --git a/src/test/java/com/example/demo/builder/TestCafeBuilder.java b/src/test/java/com/example/demo/builder/TestCafeBuilder.java index 6cd1964..3bfa4f5 100644 --- a/src/test/java/com/example/demo/builder/TestCafeBuilder.java +++ b/src/test/java/com/example/demo/builder/TestCafeBuilder.java @@ -1,6 +1,10 @@ package com.example.demo.builder; +import java.util.ArrayList; +import java.util.List; + import com.example.demo.domain.cafe.Address; +import com.example.demo.domain.cafe.BusinessHour; import com.example.demo.domain.cafe.Cafe; import com.example.demo.domain.cafe.MaxAllowableStay; @@ -15,6 +19,8 @@ public class TestCafeBuilder { private boolean isAbleToStudy = true; private int minBeveragePrice = 3_000; + private List businessHours = new ArrayList<>(); + public TestCafeBuilder id(Long id) { this.id = id; return this; @@ -55,6 +61,11 @@ public TestCafeBuilder minBeveragePrice(int minBeveragePrice) { return this; } + public TestCafeBuilder businessHours(List businessHours) { + this.businessHours = businessHours; + return this; + } + public Cafe build() { return Cafe.builder() .id(id) @@ -65,6 +76,7 @@ public Cafe build() { .avgReviewRate(avgReviewRate) .isAbleToStudy(isAbleToStudy) .minBeveragePrice(minBeveragePrice) + .businessHours(businessHours) .build(); } } diff --git a/src/test/java/com/example/demo/domain/cafe/BusinessHourOpenCheckerTest.java b/src/test/java/com/example/demo/domain/cafe/BusinessHourOpenCheckerTest.java index 76a6321..4b6bf69 100644 --- a/src/test/java/com/example/demo/domain/cafe/BusinessHourOpenCheckerTest.java +++ b/src/test/java/com/example/demo/domain/cafe/BusinessHourOpenCheckerTest.java @@ -285,15 +285,15 @@ void checkDayOfWeekWithBusinessHours() { @ParameterizedTest @MethodSource("provideChosenTimeAndExpected") - @DisplayName("선택된 시간사이에 영업시간이 포함한다.") - void when_check_businessHours_between_chosen_hours_then_contains(LocalTime chosenStartTime, LocalTime chosenEndTime, + @DisplayName("영업시간 시간사이에 선택된 시간이 포함한다.") + void when_check_chosen_hours_between_businessHours_then_contains(LocalTime chosenStartTime, LocalTime chosenEndTime, boolean expected) { //given LocalTime businessStartTime = LocalTime.of(9, 0); LocalTime businessEndTime = LocalTime.of(21, 0); //when - boolean isBetween = openChecker.checkBetweenHours(businessStartTime, businessEndTime, + boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, chosenStartTime, chosenEndTime); //then assertThat(isBetween).isEqualTo(expected); @@ -304,29 +304,24 @@ private static Stream provideChosenTimeAndExpected() { // LocalTime chosenStartTime // LocalTime chosenEndTime, // boolean expected - Arguments.of( - LocalTime.of(8, 0), - LocalTime.of(22, 0), - true - ), Arguments.of( LocalTime.of(9, 0), LocalTime.of(21, 0), true ), Arguments.of( - LocalTime.of(8, 59, 59), + LocalTime.of(9, 0, 0, 1), LocalTime.of(21, 0), true ), Arguments.of( - LocalTime.of(8, 59, 59), - LocalTime.of(21, 0, 1), + LocalTime.of(9, 0), + LocalTime.of(20, 59, 59, 999_999_999), true ), Arguments.of( - LocalTime.of(0, 0, 0), - LocalTime.of(23, 59, 59, 999_999_999), + LocalTime.of(9, 0, 0, 1), + LocalTime.of(20, 59, 59, 999_999_999), true ) ); @@ -334,8 +329,8 @@ private static Stream provideChosenTimeAndExpected() { @ParameterizedTest @MethodSource("provideChosenTimeAndExpected2") - @DisplayName("선택된 시간사이에 영업시간이 포함되지 않는다.") - void when_check_businessHours_between_chosen_hours_then_not_contains(LocalTime chosenStartTime, + @DisplayName("영업시간 사이에 선택된 시간이 포함되지 않는다.") + void when_check_chosen_hours_between_businessHours_then_not_contains(LocalTime chosenStartTime, LocalTime chosenEndTime, boolean expected) { //given @@ -343,7 +338,7 @@ void when_check_businessHours_between_chosen_hours_then_not_contains(LocalTime c LocalTime businessEndTime = LocalTime.of(21, 0); //when - boolean isBetween = openChecker.checkBetweenHours(businessStartTime, businessEndTime, + boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, chosenStartTime, chosenEndTime); //then assertThat(isBetween).isEqualTo(expected); @@ -355,18 +350,18 @@ private static Stream provideChosenTimeAndExpected2() { // LocalTime chosenEndTime, // boolean expected Arguments.of( - LocalTime.of(9, 0), - LocalTime.of(20, 59, 59), + LocalTime.of(8, 59, 59, 999_999_999), + LocalTime.of(21, 0), false ), Arguments.of( - LocalTime.of(9, 0, 1), - LocalTime.of(21, 0), + LocalTime.of(9, 0, 0), + LocalTime.of(21, 0, 0, 1), false ), Arguments.of( - LocalTime.of(8, 59, 59), - LocalTime.of(20, 59, 59), + LocalTime.of(8, 59, 59, 999_999_999), + LocalTime.of(21, 0, 0, 1), false ) ); @@ -382,7 +377,7 @@ void when_businessHour_is_0_to_24() { //when LocalTime chosenStartTime1 = LocalTime.of(0, 0); LocalTime chosenEndTime = LocalTime.MAX; - boolean isBetween = openChecker.checkBetweenHours(businessStartTime, businessEndTime, + boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, chosenStartTime1, chosenEndTime); //then assertThat(isBetween).isTrue(); @@ -399,7 +394,7 @@ void when_businessHour_is_22_to_2(LocalTime chosenStartTime, LocalTime chosenEnd LocalTime businessEndTime = LocalTime.of(2, 0); //when - boolean isBetween = openChecker.checkBetweenHours(businessStartTime, businessEndTime, + boolean isBetween = openChecker.checkBetweenBusinessHours(businessStartTime, businessEndTime, chosenStartTime, chosenEndTime); //then assertThat(isBetween).isEqualTo(expected); @@ -416,24 +411,24 @@ private static Stream provideChosenTimeAndExpected3() { true ), Arguments.of( - LocalTime.of(21, 0), + LocalTime.of(22, 0, 0, 1), LocalTime.of(2, 0), true ), Arguments.of( - LocalTime.of(22, 0, 1), + LocalTime.of(21, 59, 59, 999_999_999), LocalTime.of(2, 0), false ), Arguments.of( LocalTime.of(22, 0, 0), - LocalTime.of(1, 59, 59), + LocalTime.of(2, 0, 0, 1), false ), Arguments.of( LocalTime.of(0, 0), LocalTime.MAX, - true + false ) ); } diff --git a/src/test/java/com/example/demo/domain/cafe/CafeTest.java b/src/test/java/com/example/demo/domain/cafe/CafeTest.java index bbd539d..20452ac 100644 --- a/src/test/java/com/example/demo/domain/cafe/CafeTest.java +++ b/src/test/java/com/example/demo/domain/cafe/CafeTest.java @@ -3,12 +3,16 @@ import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; +import java.time.DayOfWeek; +import java.time.LocalTime; import java.util.ArrayList; import java.util.List; import java.util.OptionalDouble; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import com.example.demo.domain.review.Review; @@ -49,4 +53,36 @@ void calcAverageRating_when_no_review() { OptionalDouble rating = cafe.calcAverageRating(); assertTrue(rating.isEmpty()); } + + @ParameterizedTest + @EnumSource(value = DayOfWeek.class) + @DisplayName("DayOfWeek에 맞는 영업시간을 찾는다.") + void findBusinessHour(DayOfWeek dayOfWeek) { + List businessHours = makeBusinessHourWith7daysFrom9To21(); + Cafe cafe = Cafe.builder() + .businessHours(businessHours) + .build(); + + BusinessHour businessHour = cafe.findBusinessHour(dayOfWeek); + + assertAll( + () -> assertThat(businessHour.getStartTime()).isEqualTo(LocalTime.of(9, 0)), + () -> assertThat(businessHour.getEndTime()).isEqualTo(LocalTime.of(21, 0)) + ); + } + + private List makeBusinessHourWith7daysFrom9To21() { + List daysOfWeek = List.of("MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"); + List businessHours = new ArrayList<>(); + for (String day : daysOfWeek) { + businessHours.add( + BusinessHour.builder() + .day(day) + .startTime(LocalTime.of(9, 0)) + .endTime(LocalTime.of(21, 0)) + .build() + ); + } + return businessHours; + } } diff --git a/src/test/java/com/example/demo/helper/CafePersistHelper.java b/src/test/java/com/example/demo/helper/CafePersistHelper.java index 04ae9e1..3b4889a 100644 --- a/src/test/java/com/example/demo/helper/CafePersistHelper.java +++ b/src/test/java/com/example/demo/helper/CafePersistHelper.java @@ -1,6 +1,11 @@ package com.example.demo.helper; +import java.util.ArrayList; +import java.util.List; + +import com.example.demo.builder.TestBusinessHourBuilder; import com.example.demo.builder.TestCafeBuilder; +import com.example.demo.domain.cafe.BusinessHour; import com.example.demo.domain.cafe.Cafe; import com.example.demo.helper.entitymanager.EntityManagerForPersistHelper; @@ -21,4 +26,28 @@ public Cafe persistCafeWithImpossibleStudy() { return em.save(cafe); } + public Cafe persistCafeWithBusinessHour(List businessHours) { + Cafe cafe = new TestCafeBuilder().businessHours(businessHours).build(); + return em.save(cafe); + } + + public Cafe persistCafeWith24For7() { + List businessHours = makeBusinessHourWith24For7(); + Cafe cafe = new TestCafeBuilder().businessHours(businessHours).build(); + return em.save(cafe); + } + + private List makeBusinessHourWith24For7() { + List daysOfWeek = List.of("MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"); + List businessHours = new ArrayList<>(); + for (String day : daysOfWeek) { + businessHours.add( + new TestBusinessHourBuilder() + .day(day) + .build() + ); + } + return businessHours; + } + } 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 dcbd572..a5403fc 100644 --- a/src/test/java/com/example/demo/service/profile/ProfileServiceImplTest.java +++ b/src/test/java/com/example/demo/service/profile/ProfileServiceImplTest.java @@ -2,6 +2,7 @@ import static com.example.demo.exception.ExceptionType.*; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -45,12 +46,13 @@ class ProfileServiceImplTest extends ServiceTest { @Test @DisplayName("자신이 스터디 장인 카공의 멤버면 프로필 조회 성공") void successWhenRequestMemberIsLeaderWithTargetMember() { - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); long requestMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long targetMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); LocalDateTime start = LocalDateTime.now().plusHours(4); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, start.plusHours(5), cafeId); - StudyOnceCreateResponse study = studyOnceService.createStudy(requestMemberId, studyOnceCreateRequest); + StudyOnceCreateResponse study = studyOnceService.createStudy(requestMemberId, studyOnceCreateRequest, + LocalDate.now()); studyOnceService.tryJoin(targetMemberId, study.getStudyOnceId()); Assertions.assertDoesNotThrow(() -> profileService.get(requestMemberId, targetMemberId)); } 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 631b910..f6fca4d 100644 --- a/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java +++ b/src/test/java/com/example/demo/service/study/StudyOnceServiceImplTest.java @@ -5,7 +5,10 @@ import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -17,6 +20,7 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import com.example.demo.domain.cafe.BusinessHour; import com.example.demo.domain.cafe.Cafe; import com.example.demo.domain.member.Member; import com.example.demo.domain.study.Attendance; @@ -73,10 +77,10 @@ void searchStudyByDto() { //given LocalDateTime start = LocalDateTime.now().plusHours(4).plusMinutes(1); LocalDateTime end = start.plusHours(1); - Cafe cafe = cafePersistHelper.persistDefaultCafe(); + Cafe cafe = cafePersistHelper.persistCafeWith24For7(); Member leader = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE); StudyOnceCreateResponse expectedStudyOnceSearchResponse = studyOnceService.createStudy(leader.getId(), - makeStudyOnceCreateRequest(start, end, cafe.getId())); + makeStudyOnceCreateRequest(start, end, cafe.getId()), LocalDate.now()); //when StudyOnceSearchRequest studyOnceSearchRequest = new StudyOnceSearchRequest("합정동"); studyOnceSearchRequest.setMaxMemberCount(expectedStudyOnceSearchResponse.getMaxMemberCount()); @@ -106,11 +110,12 @@ private void syncStudyOnceRepositoryAndStudyMemberRepository() { void searchByStudyId() { LocalDateTime start = LocalDateTime.now().plusHours(3).plusMinutes(1); LocalDateTime end = start.plusHours(1); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - StudyOnceCreateResponse result = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse result = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); StudyOnceSearchResponse studyOnceSearchResponse = studyOnceService.searchByStudyId(result.getStudyOnceId()); assertThat(studyOnceSearchResponse.getStudyOnceId()).isEqualTo(result.getStudyOnceId()); @@ -121,10 +126,11 @@ void searchByStudyId() { void searchByStudyId_when_not_member() { LocalDateTime start = LocalDateTime.now().plusHours(3).plusMinutes(1); LocalDateTime end = start.plusHours(1); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - StudyOnceCreateResponse result = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse result = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); StudyOnceSearchResponse studyOnceSearchResponse = studyOnceService.searchByStudyId(result.getStudyOnceId()); @@ -136,10 +142,11 @@ void searchByStudyId_when_not_member() { void searchStudyOnceWithMemberParticipation_when_takes_attendance() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long studyOnceId = searchResponse.getStudyOnceId(); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); studyOnceService.tryJoin(memberId, studyOnceId); @@ -156,10 +163,11 @@ void searchStudyOnceWithMemberParticipation_when_takes_attendance() { void searchStudyOnceWithMemberParticipation_when_not_take_attendance() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long studyOnceId = searchResponse.getStudyOnceId(); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); @@ -175,11 +183,12 @@ void create() { LocalDateTime start = LocalDateTime.now().plusHours(3).plusMinutes(1); LocalDateTime end = start.plusHours(1); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - StudyOnceCreateResponse result = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse result = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); StudyOnceCreateResponse expected = makeExpectedStudyOnceCreateResult(cafeId, studyOnceCreateRequest, result); assertThat(result).isEqualTo(expected); @@ -211,12 +220,12 @@ private static StudyOnceCreateResponse makeExpectedStudyOnceCreateResult(long ca void createFailByStartTime() { LocalDateTime start = LocalDateTime.now().plusHours(3).minusSeconds(1); LocalDateTime end = start.plusHours(3); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - assertThatThrownBy(() -> studyOnceService.createStudy(leaderId, studyOnceCreateRequest)) + assertThatThrownBy(() -> studyOnceService.createStudy(leaderId, studyOnceCreateRequest, LocalDate.now())) .isInstanceOf(CafegoryException.class) .hasMessage(STUDY_ONCE_WRONG_START_TIME.getErrorMessage()); } @@ -226,12 +235,12 @@ void createFailByStartTime() { void createFailByStartTimeAndEndTimePeriodIsTooShort() { LocalDateTime start = LocalDateTime.now().plusHours(3).plusMinutes(1); LocalDateTime end = start.plusMinutes(59).plusSeconds(59); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - assertThatThrownBy(() -> studyOnceService.createStudy(leaderId, studyOnceCreateRequest)) + assertThatThrownBy(() -> studyOnceService.createStudy(leaderId, studyOnceCreateRequest, LocalDate.now())) .isInstanceOf(CafegoryException.class) .hasMessage(STUDY_ONCE_SHORT_DURATION.getErrorMessage()); } @@ -241,12 +250,12 @@ void createFailByStartTimeAndEndTimePeriodIsTooShort() { void createFailByStartTimeAndEndTimePeriodIsTooLong() { LocalDateTime start = LocalDateTime.now().plusHours(3).plusMinutes(1); LocalDateTime end = start.plusHours(5).plusSeconds(1); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - assertThatThrownBy(() -> studyOnceService.createStudy(leaderId, studyOnceCreateRequest)) + assertThatThrownBy(() -> studyOnceService.createStudy(leaderId, studyOnceCreateRequest, LocalDate.now())) .isInstanceOf(CafegoryException.class) .hasMessage(STUDY_ONCE_LONG_DURATION.getErrorMessage()); } @@ -256,15 +265,16 @@ void createFailByStartTimeAndEndTimePeriodIsTooLong() { @DisplayName("이미 해당 시간에 카공장으로 참여중인 카공이 있는 경우 카공 생성 실패") void createFailByAlreadyStudyLeader(LocalDateTime start, LocalDateTime end, LocalDateTime left, LocalDateTime right) { - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + studyOnceService.createStudy(leaderId, studyOnceCreateRequest, LocalDate.now()); StudyOnceCreateRequest needToFailStudyOnceCreateRequest = makeStudyOnceCreateRequest(left, right, cafeId); syncStudyOnceRepositoryAndStudyMemberRepository(); - assertThatThrownBy(() -> studyOnceService.createStudy(leaderId, needToFailStudyOnceCreateRequest)) + assertThatThrownBy( + () -> studyOnceService.createStudy(leaderId, needToFailStudyOnceCreateRequest, LocalDate.now())) .isInstanceOf(CafegoryException.class) .hasMessage(STUDY_ONCE_CONFLICT_TIME.getErrorMessage()); } @@ -274,18 +284,19 @@ void createFailByAlreadyStudyLeader(LocalDateTime start, LocalDateTime end, Loca @DisplayName("이미 해당 시간에 참여중인 카공이 있는 경우 카공 생성 실패") void createFailByAlreadyStudyMember(LocalDateTime start, LocalDateTime end, LocalDateTime left, LocalDateTime right) { - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - StudyOnceCreateResponse study = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse study = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, LocalDate.now()); studyOnceService.tryJoin(memberId, study.getStudyOnceId()); // 오른쪽 끝에서 겹침 StudyOnceCreateRequest needToFailStudyOnceCreateRequest = makeStudyOnceCreateRequest(left, right, cafeId); syncStudyOnceRepositoryAndStudyMemberRepository(); - assertThatThrownBy(() -> studyOnceService.createStudy(memberId, needToFailStudyOnceCreateRequest)) + assertThatThrownBy( + () -> studyOnceService.createStudy(memberId, needToFailStudyOnceCreateRequest, LocalDate.now())) .isInstanceOf(CafegoryException.class) .hasMessage(STUDY_ONCE_CONFLICT_TIME.getErrorMessage()); } @@ -295,10 +306,10 @@ void createFailByAlreadyStudyMember(LocalDateTime start, LocalDateTime end, Loca void createTwo() { LocalDateTime start = LocalDateTime.now().plusYears(1).plusHours(3).plusMinutes(1); LocalDateTime end = start.plusHours(1); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + studyOnceService.createStudy(leaderId, studyOnceCreateRequest, LocalDate.now()); // 오른쪽 끝에서 1초 차이로 안 겹침 LocalDateTime rightLimitStart = end.plusSeconds(1); @@ -307,7 +318,7 @@ void createTwo() { rightLimitEnd, cafeId); syncStudyOnceRepositoryAndStudyMemberRepository(); - studyOnceService.createStudy(leaderId, needToFailStudyOnceCreateRequest); + studyOnceService.createStudy(leaderId, needToFailStudyOnceCreateRequest, LocalDate.now()); // 왼쪽 끝에서 1초 차이로 안 겹침 LocalDateTime leftLimitEnd = start.minusSeconds(1); @@ -316,7 +327,82 @@ void createTwo() { leftLimitEnd, cafeId); syncStudyOnceRepositoryAndStudyMemberRepository(); - studyOnceService.createStudy(leaderId, needToFailStudyOnceCreateRequest); + studyOnceService.createStudy(leaderId, needToFailStudyOnceCreateRequest, LocalDate.now()); + } + + @ParameterizedTest() + @MethodSource("provideStartAndEndDateTime1") + @DisplayName("카공 생성시 시작시간과 종료시간은 카페 영업시간내에 포함되지 않으면 예외가 터진다.") + void creat_studyOnce_between_not_contain_cafe_businessHours(LocalDateTime start, LocalDateTime end) { + List businessHours = makeBusinessHourWith7daysFrom9To21(); + long cafeId = cafePersistHelper.persistCafeWithBusinessHour(businessHours).getId(); + long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); + StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); + + assertThatThrownBy(() -> studyOnceService.createStudy(leaderId, studyOnceCreateRequest, LocalDate.now())) + .isInstanceOf(CafegoryException.class) + .hasMessage(STUDY_ONCE_CREATE_BETWEEN_CAFE_BUSINESS_HOURS.getErrorMessage()); + } + + static Stream provideStartAndEndDateTime1() { + return Stream.of( + Arguments.of( + LocalDateTime.of(2999, 1, 1, 8, 59, 59, 999_999_999), + LocalDateTime.of(2999, 1, 1, 10, 0) + ), + Arguments.of( + LocalDateTime.of(2999, 1, 1, 8, 0), + LocalDateTime.of(2999, 1, 1, 9, 0, 0, 1) + ), + Arguments.of( + LocalDateTime.of(2999, 1, 1, 20, 0), + LocalDateTime.of(2999, 1, 1, 21, 0, 0, 1) + ), + Arguments.of( + LocalDateTime.of(2999, 1, 1, 20, 59, 59, 999_999_999), + LocalDateTime.of(2999, 1, 1, 22, 0) + ) + ); + } + + @ParameterizedTest() + @MethodSource("provideStartAndEndDateTime2") + @DisplayName("카공 생성시 시작시간과 종료시간은 카페 영업시간내에 포함되면 카공이 생성된다.") + void creat_studyOnce_between_cafe_businessHours(LocalDateTime start, LocalDateTime end) { + List businessHours = makeBusinessHourWith7daysFrom9To21(); + long cafeId = cafePersistHelper.persistCafeWithBusinessHour(businessHours).getId(); + long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); + StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); + + assertDoesNotThrow(() -> studyOnceService.createStudy(leaderId, studyOnceCreateRequest, LocalDate.now())); + } + + static Stream provideStartAndEndDateTime2() { + return Stream.of( + Arguments.of( + LocalDateTime.of(2999, 1, 1, 9, 0), + LocalDateTime.of(2999, 1, 1, 10, 0) + ), + Arguments.of( + LocalDateTime.of(2999, 1, 1, 20, 0), + LocalDateTime.of(2999, 1, 1, 21, 0) + ) + ); + } + + private List makeBusinessHourWith7daysFrom9To21() { + List daysOfWeek = List.of("MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"); + List businessHours = new ArrayList<>(); + for (String day : daysOfWeek) { + businessHours.add( + BusinessHour.builder() + .day(day) + .startTime(LocalTime.of(9, 0)) + .endTime(LocalTime.of(21, 0)) + .build() + ); + } + return businessHours; } @Test @@ -324,11 +410,12 @@ void createTwo() { void tryJoin() { long firstMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long secondMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(LocalDateTime.now().plusHours(4), LocalDateTime.now().plusHours(7), cafeId); - StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest); + StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest, + LocalDate.now()); assertDoesNotThrow(() -> studyOnceService.tryJoin(secondMemberId, study.getStudyOnceId())); } @@ -338,10 +425,11 @@ void tryJoin() { void tryJoinFailCauseDuplicate() { long firstMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long secondMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(LocalDateTime.now().plusHours(4), LocalDateTime.now().plusHours(7), cafeId); - StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest); + StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest, + LocalDate.now()); studyOnceService.tryJoin(secondMemberId, study.getStudyOnceId()); @@ -359,15 +447,16 @@ void tryJoinFailCauseConflict(LocalDateTime start, LocalDateTime end, LocalDateT long firstMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long secondMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long thirdMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest); + StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest, + LocalDate.now()); studyOnceService.tryJoin(secondMemberId, study.getStudyOnceId()); StudyOnceCreateRequest conflictStudyOnceCreateRequest = makeStudyOnceCreateRequest(conflictStart, conflictEnd, cafeId); StudyOnceCreateResponse conflictStudy = studyOnceService.createStudy(thirdMemberId, - conflictStudyOnceCreateRequest); + conflictStudyOnceCreateRequest, LocalDate.now()); syncStudyOnceRepositoryAndStudyMemberRepository(); assertThatThrownBy(() -> studyOnceService.tryJoin(secondMemberId, conflictStudy.getStudyOnceId())) @@ -382,9 +471,10 @@ void tryQuit() { LocalDateTime end = start.plusHours(4); long firstMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long secondMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest); + StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest, + LocalDate.now()); studyOnceService.tryJoin(secondMemberId, study.getStudyOnceId()); assertDoesNotThrow(() -> studyOnceService.tryQuit(secondMemberId, study.getStudyOnceId())); @@ -397,9 +487,10 @@ void tryQuit_then_studyOnce_nowMemberCount_is_reduced() { LocalDateTime end = start.plusHours(4); long firstMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long secondMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest); + StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest, + LocalDate.now()); studyOnceService.tryJoin(secondMemberId, study.getStudyOnceId()); studyOnceService.tryQuit(secondMemberId, study.getStudyOnceId()); @@ -414,10 +505,11 @@ void tryQuitFailCauseNotJoin() { LocalDateTime end = start.plusHours(4); long firstMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long secondMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest); + StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest, + LocalDate.now()); assertThatThrownBy(() -> studyOnceService.tryQuit(secondMemberId, study.getStudyOnceId())) .isInstanceOf(CafegoryException.class) @@ -431,9 +523,10 @@ void tryQuitFailCauseNotOnlyLeader() { LocalDateTime end = start.plusHours(4); long firstMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long secondMemberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); - StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest); + StudyOnceCreateResponse study = studyOnceService.createStudy(firstMemberId, studyOnceCreateRequest, + LocalDate.now()); studyOnceService.tryJoin(secondMemberId, study.getStudyOnceId()); @@ -447,10 +540,11 @@ void tryQuitFailCauseNotOnlyLeader() { void take_attendance() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long studyOnceId = searchResponse.getStudyOnceId(); studyOnceService.tryJoin(memberId, studyOnceId); @@ -484,10 +578,11 @@ void take_attendance_study_exception() { void take_attendance_memberId_exception() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long studyOnceId = searchResponse.getStudyOnceId(); studyOnceService.tryJoin(memberId, studyOnceId); @@ -505,10 +600,11 @@ void take_attendance_memberId_exception() { void take_attendance_leaderId_exception() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long studyOnceId = searchResponse.getStudyOnceId(); studyOnceService.tryJoin(memberId, studyOnceId); @@ -526,10 +622,11 @@ void take_attendance_leaderId_exception() { void can_take_attendance_from_start_time_in_10min_exception() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long studyOnceId = searchResponse.getStudyOnceId(); studyOnceService.tryJoin(memberId, studyOnceId); @@ -547,10 +644,11 @@ void can_take_attendance_from_start_time_in_10min_exception() { void can_take_attendance_until_half_whole_study_time_exception() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long studyOnceId = searchResponse.getStudyOnceId(); studyOnceService.tryJoin(memberId, studyOnceId); @@ -568,10 +666,11 @@ void can_take_attendance_until_half_whole_study_time_exception() { void can_take_attendances() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long studyOnceId = searchResponse.getStudyOnceId(); studyOnceService.tryJoin(memberId, studyOnceId); @@ -592,10 +691,11 @@ void can_take_attendances() { void change_cafe() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long studyOnceId = searchResponse.getStudyOnceId(); long changingCafeId = cafePersistHelper.persistDefaultCafe().getId(); @@ -609,10 +709,11 @@ void change_cafe() { void change_cafe_by_leader_only() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long studyOnceId = searchResponse.getStudyOnceId(); long changingCafeId = cafePersistHelper.persistDefaultCafe().getId(); @@ -627,10 +728,11 @@ void change_cafe_by_leader_only() { void findStudyMembers() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long studyOnceId = searchResponse.getStudyOnceId(); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); studyOnceService.tryJoin(memberId, studyOnceId); @@ -650,12 +752,13 @@ void findStudyMembers() { void updateStudyOnce() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId1 = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId1 = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId1); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long studyOnceId = searchResponse.getStudyOnceId(); - long cafeId2 = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId2 = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceUpdateRequest request = new StudyOnceUpdateRequest(cafeId2, "변경된카공이름", start.plusHours(5), start.plusHours(6), 5, false, "오픈채팅방 링크"); @@ -678,10 +781,11 @@ void updateStudyOnce() { void update_studyOnce_by_invalid_cafe_then_exception() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId1 = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId1 = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId1); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long studyOnceId = searchResponse.getStudyOnceId(); StudyOnceUpdateRequest request = new StudyOnceUpdateRequest(999L, "변경된카공이름", start.plusHours(5), start.plusHours(6), 5, false, "오픈채팅방 링크"); @@ -696,10 +800,11 @@ void update_studyOnce_by_invalid_cafe_then_exception() { void update_studyOnce_by_invalid_member_then_exception() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId1 = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId1 = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId1); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long studyOnceId = searchResponse.getStudyOnceId(); StudyOnceUpdateRequest request = new StudyOnceUpdateRequest(cafeId1, "변경된카공이름", start.plusHours(5), start.plusHours(6), 5, false, "오픈채팅방 링크"); @@ -716,10 +821,11 @@ void update_studyOnce_by_invalid_member_then_exception() { void updateStudyOncePartially() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId1 = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId1 = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId1); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long studyOnceId = searchResponse.getStudyOnceId(); long cafeId2 = cafePersistHelper.persistDefaultCafe().getId(); @@ -747,10 +853,11 @@ void updateStudyOncePartially() { void update_studyOnce_partially_then_update_partially() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId1 = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId1 = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId1); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long studyOnceId = searchResponse.getStudyOnceId(); long cafeId2 = cafePersistHelper.persistDefaultCafe().getId(); @@ -778,10 +885,11 @@ void update_studyOnce_partially_then_update_partially() { void update_studyOnce_partially_by_invalid_member_then_exception() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId1 = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId1 = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId1); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long studyOnceId = searchResponse.getStudyOnceId(); StudyOnceUpdateRequest request = new StudyOnceUpdateRequest(cafeId1, null, null, null, 5, true, null); @@ -798,10 +906,11 @@ void update_studyOnce_partially_by_invalid_member_then_exception() { void doesOnlyStudyLeaderExist() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId1 = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId1 = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId1); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long studyOnceId = searchResponse.getStudyOnceId(); boolean doesOnlyStudyLeaderExist = studyOnceService.doesOnlyStudyLeaderExist(studyOnceId); @@ -814,10 +923,11 @@ void doesOnlyStudyLeaderExist() { void doesOnlyStudyLeaderExist_with_members() { LocalDateTime start = LocalDateTime.now().plusHours(4); LocalDateTime end = start.plusHours(4); - long cafeId1 = cafePersistHelper.persistDefaultCafe().getId(); + long cafeId1 = cafePersistHelper.persistCafeWith24For7().getId(); StudyOnceCreateRequest studyOnceCreateRequest = makeStudyOnceCreateRequest(start, end, cafeId1); long leaderId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); - StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest); + StudyOnceCreateResponse searchResponse = studyOnceService.createStudy(leaderId, studyOnceCreateRequest, + LocalDate.now()); long memberId = memberPersistHelper.persistDefaultMember(THUMBNAIL_IMAGE).getId(); long studyOnceId = searchResponse.getStudyOnceId(); studyOnceService.tryJoin(memberId, studyOnceId);