diff --git a/src/main/java/com/trip/waytrip/domain/DailyPlace.java b/src/main/java/com/trip/waytrip/domain/DailyPlace.java index 95191dc..b0cc411 100644 --- a/src/main/java/com/trip/waytrip/domain/DailyPlace.java +++ b/src/main/java/com/trip/waytrip/domain/DailyPlace.java @@ -17,8 +17,8 @@ public class DailyPlace { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - - @ManyToOne(optional = false) + @Setter + @ManyToOne(optional = false, fetch = FetchType.LAZY) private DailySchedule dailySchedule; //@JoinColumn diff --git a/src/main/java/com/trip/waytrip/domain/DailySchedule.java b/src/main/java/com/trip/waytrip/domain/DailySchedule.java index 45bfbc7..ab7b9d7 100644 --- a/src/main/java/com/trip/waytrip/domain/DailySchedule.java +++ b/src/main/java/com/trip/waytrip/domain/DailySchedule.java @@ -34,6 +34,8 @@ public DailySchedule(Schedule schedule, ScheduleDto.DailyScheduleRequestDto requ this.date = requestDto.getDate(); } public void addDailyPlace(DailyPlace dailyPlace){ + dailyPlaces.add(dailyPlace); + dailyPlace.setDailySchedule(this); } } diff --git a/src/main/java/com/trip/waytrip/service/ScheduleService.java b/src/main/java/com/trip/waytrip/service/ScheduleService.java index 6a45105..e68e180 100644 --- a/src/main/java/com/trip/waytrip/service/ScheduleService.java +++ b/src/main/java/com/trip/waytrip/service/ScheduleService.java @@ -41,6 +41,7 @@ public void createTeamAndFirstSchedule(ScheduleDto.FirstRequestDto requestDto, L public void createTotalSchedule(Long scheduleId, ScheduleDto.DailyScheduleRequestDto requestDto){ createDailySchedule(scheduleId, requestDto); } + //ok public void createDailySchedule(Long scheduleId, ScheduleDto.DailyScheduleRequestDto requestDto){ Schedule schedule = scheduleRepository.findById(scheduleId).orElseThrow(); DailySchedule dailySchedule = new DailySchedule(schedule, requestDto); diff --git a/src/test/java/com/trip/waytrip/repositoryTest/DailyPlaceRepositoryTest.java b/src/test/java/com/trip/waytrip/repositoryTest/DailyPlaceRepositoryTest.java index be7a1d8..0dda40a 100644 --- a/src/test/java/com/trip/waytrip/repositoryTest/DailyPlaceRepositoryTest.java +++ b/src/test/java/com/trip/waytrip/repositoryTest/DailyPlaceRepositoryTest.java @@ -11,7 +11,7 @@ import static org.assertj.core.api.Assertions.assertThat; -public class DailyPlaceRepositoryTest extends ScheduleRepositoryTest { +public class DailyPlaceRepositoryTest extends RepositoryTest { private Address address; private Place place; private DailySchedule dailySchedule; @@ -34,7 +34,7 @@ void init() { @Test @DisplayName("하루에 맞는 장소의 1개를 저장한다.") void save(){ - saveTeamAndFirstSchedule(); + //saveTeamAndFirstSchedule(); //given placeRepository.save(place); diff --git a/src/test/java/com/trip/waytrip/repositoryTest/ScheduleRepositoryTest.java b/src/test/java/com/trip/waytrip/repositoryTest/ScheduleRepositoryTest.java index ecb47f7..aca8974 100644 --- a/src/test/java/com/trip/waytrip/repositoryTest/ScheduleRepositoryTest.java +++ b/src/test/java/com/trip/waytrip/repositoryTest/ScheduleRepositoryTest.java @@ -12,8 +12,15 @@ public class ScheduleRepositoryTest extends RepositoryTest{ private User user; + private Address address; + private Place place; private Schedule schedule; private Schedule schedule1; + private DailyPlace dailyPlace; + private DailyPlace dailyPlace1; + private DailyPlace dailyPlace2; + private DailyPlace dailyPlace3; + private DailyPlace dailyPlace4; @BeforeEach void init(){ @@ -22,6 +29,19 @@ void init(){ .nickname("가희") .profileUrl("이미지") .build(); + address = Address.builder() + .specificAddress("address1") + .latitude(35.8905477) + .longitude(128.6121117) + .build(); + place = Place.builder() + .name("경북대학교") + .openTime("1") + .closeTime("2") + .address(address) + .imageUrl("image") + .detail("detail") + .build(); schedule = Schedule.builder() .name("제주도") .imageUrl("image") @@ -33,7 +53,21 @@ void init(){ ) ) .build(); - + dailyPlace = DailyPlace.builder() + .place(placeRepository.save(place)) + .build(); + dailyPlace1 = DailyPlace.builder() + .place(placeRepository.save(place)) + .build(); + dailyPlace2 = DailyPlace.builder() + .place(placeRepository.save(place)) + .build(); + dailyPlace3 = DailyPlace.builder() + .place(placeRepository.save(place)) + .build(); + dailyPlace4 = DailyPlace.builder() + .place(placeRepository.save(place)) + .build(); } @Test @DisplayName("팀을 만들고 초기 스케쥴을 저장한다.") @@ -117,4 +151,51 @@ void saveDailySchedules(){ assertThat(dailyScheduleList.size()).isEqualTo(5); assertThat(dailyScheduleList).contains(new_dailySchedule, new1_dailySchedule, new2_dailySchedule, new3_dailySchedule, new4_dailySchedule); } +// @Test +// @DisplayName("일정의 하루일정에 장소 하나를 추가한다.") +// void addDailyPlaceToDailySchedule1(){ +// //given +// dailyPlaceRepository.save(dailyPlace); +// //given +// scheduleRepository.save(schedule); +// +// DailySchedule dailySchedule = DailySchedule.builder() +// .date(LocalDate.of(2023,01,01)) +// .schedule(schedule) +// .build(); +// //when +// +// dailyScheduleRepository.save(dailySchedule); +// dailySchedule.addDailyPlace(dailyPlace); +// dailyPlaceRepository.save(dailyPlace); +// dailyScheduleRepository.save(dailySchedule); +// //then +// assertThat(dailySchedule.getDailyPlaces().size()).isEqualTo(1); +// } + @Test + @DisplayName("일정의 하루일정에 장소 하나를 추가한다.") + void addDailyPlaceToDailySchedule(){ + //given + scheduleRepository.save(schedule); + DailySchedule dailySchedule = dailyScheduleRepository.save( + DailySchedule.builder() + .date(LocalDate.of(2023,01,01)) + .schedule(schedule) + .build() + ); + dailyScheduleRepository.save(dailySchedule); + +// dailyPlaceRepository.save(dailyPlace); +// dailyPlaceRepository.save(dailyPlace1); +// dailyPlaceRepository.save(dailyPlace2); +// dailyPlaceRepository.save(dailyPlace3); +// dailyPlaceRepository.save(dailyPlace4); + + //when +// dailyPlace.setDailySchedule(dailySchedule); +// dailySchedule.getDailyPlaces().add(dailyPlace); +// +// //then +// assertThat(dailySchedule.getDailyPlaces().size()).isEqualTo(1); + } }