Skip to content

Commit

Permalink
shit : undone
Browse files Browse the repository at this point in the history
  • Loading branch information
ZZKIM committed Aug 8, 2023
1 parent 7af4ef7 commit 2681460
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/trip/waytrip/domain/DailyPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/trip/waytrip/domain/DailySchedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +34,7 @@ void init() {
@Test
@DisplayName("하루에 맞는 장소의 1개를 저장한다.")
void save(){
saveTeamAndFirstSchedule();
//saveTeamAndFirstSchedule();
//given
placeRepository.save(place);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand All @@ -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")
Expand All @@ -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("팀을 만들고 초기 스케쥴을 저장한다.")
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 2681460

Please sign in to comment.