forked from codesquad-members-2022/airbnb
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: List<Reservation>을 일급 컬렉션으로 래핑 (#39)
- Loading branch information
Showing
4 changed files
with
35 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
BE/src/main/java/org/team4/airbnb/reservation/Reservations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.team4.airbnb.reservation; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import org.team4.airbnb.reservation.dto.ReservationElement; | ||
import org.team4.airbnb.reservation.dto.ReservationResponse; | ||
|
||
public class Reservations { | ||
|
||
private final List<Reservation> elements; | ||
|
||
public Reservations(List<Reservation> elements) { | ||
this.elements = elements; | ||
} | ||
|
||
public Set<Long> getAccommodationIds() { | ||
return elements.stream() | ||
.map(Reservation::getAccommodationId) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
public ReservationResponse toReservationResponse() { | ||
return new ReservationResponse(elements.stream() | ||
.map(ReservationElement::new) | ||
.collect(Collectors.toList())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 2 additions & 8 deletions
10
BE/src/main/java/org/team4/airbnb/reservation/dto/ReservationResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
package org.team4.airbnb.reservation.dto; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.team4.airbnb.reservation.Reservation; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public class ReservationResponse { | ||
|
||
private final List<ReservationElement> data; | ||
|
||
public static ReservationResponse from(List<Reservation> reservations) { | ||
return new ReservationResponse(reservations.stream() | ||
.map(ReservationElement::new) | ||
.collect(Collectors.toList())); | ||
public ReservationResponse(List<ReservationElement> data) { | ||
this.data = List.copyOf(data); | ||
} | ||
} |