Skip to content

Commit

Permalink
feat: Trip 생성자 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mcodnjs committed Jul 27, 2023
1 parent c70cc52 commit 5f482bc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 46 deletions.
53 changes: 11 additions & 42 deletions backend/src/main/java/hanglog/trip/domain/Trip.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static lombok.AccessLevel.PROTECTED;

import hanglog.global.BaseEntity;
import hanglog.global.type.StatusType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand All @@ -19,7 +18,6 @@
import java.util.List;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

Expand All @@ -38,47 +36,20 @@ public class Trip extends BaseEntity {
private String title;

@Column(nullable = false)
@ColumnDefault("https://github.com/woowacourse-teams/2023-hang-log/assets/64852591/65607364-3bf7-4920-abd1-edfdbc8d4df0")
private String imageUrl;

@Column(nullable = false)
private LocalDate startDate;

@Column(nullable = false)
private LocalDate endDate;

@Column(nullable = false)
@ColumnDefault("''")
private String description;

@OneToMany(mappedBy = "trip", cascade = {PERSIST, REMOVE, MERGE}, orphanRemoval = true)
private List<DayLog> dayLogs = new ArrayList<>();

private Trip(
final Long id,
final String title,
final LocalDate startDate,
final LocalDate endDate,
final String description,
final StatusType status
) {
super(status);
this.id = id;
this.title = title;
this.startDate = startDate;
this.endDate = endDate;
this.description = description;
}

public Trip(
final Long id,
final String title,
final LocalDate startDate,
final LocalDate endDate,
final String description
) {
this(id, title, startDate, endDate, description, USABLE);
}

public Trip(
final Long id,
final String title,
Expand All @@ -98,17 +69,15 @@ public Trip(
this.dayLogs = dayLogs;
}

public Trip(
final String title,
final LocalDate startDate,
final LocalDate endDate,
final String description
) {
this(null, title, startDate, endDate, description);
}

public Trip(final String title, final LocalDate startDate, final LocalDate endDate
) {
this(title, startDate, endDate, "");
public static Trip of(final String title, final LocalDate startDate, final LocalDate endDate) {
return new Trip(
null,
title,
"https://github.com/woowacourse-teams/2023-hang-log/assets/64852591/65607364-3bf7-4920-abd1-edfdbc8d4df0",
startDate,
endDate,
"",
new ArrayList<>()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static TripDetailResponse of(final Trip trip, final List<City> cities) {
trip.getStartDate(),
trip.getEndDate(),
trip.getDescription(),
"https://a.cdn-hotels.com/gdcs/production153/d1371/e6c1f55e-51ac-41d5-8c63-2d0c63faf59e.jpg",
trip.getImageUrl(),
dayLogGetResponses
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static TripResponse of(final Trip trip, final List<City> cities) {
trip.getStartDate(),
trip.getEndDate(),
trip.getDescription(),
"https://a.cdn-hotels.com/gdcs/production153/d1371/e6c1f55e-51ac-41d5-8c63-2d0c63faf59e.jpg"
trip.getImageUrl()
);
}
}
3 changes: 2 additions & 1 deletion backend/src/main/java/hanglog/trip/service/TripService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Long save(final TripCreateRequest tripCreateRequest) {
.orElseThrow(() -> new BadRequestException(NOT_FOUND_CITY_ID)))
.toList();

final Trip newTrip = new Trip(
final Trip newTrip = Trip.of(
getInitTitle(cites),
tripCreateRequest.getStartDate(),
tripCreateRequest.getEndDate()
Expand Down Expand Up @@ -101,6 +101,7 @@ public void update(final Long tripId, final TripUpdateRequest updateRequest) {
updateRequest.getDescription(),
trip.getDayLogs()
);
System.out.println(updatedTrip.getImageUrl());
tripRepository.save(updatedTrip);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void delete_InvalidTripId() {
class UpdateTripTests {

TripUpdateRequest updateRequest;
Trip trip = new Trip(
Trip trip = Trip.of(
"파리 여행",
LocalDate.of(2023, 7, 1),
LocalDate.of(2023, 7, 3)
Expand Down

0 comments on commit 5f482bc

Please sign in to comment.