Skip to content

Commit

Permalink
[refactor] 여행 경로 조회 기능 수정 (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaeyoung22 committed Aug 21, 2023
1 parent c19e472 commit 45bd5c9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
6 changes: 6 additions & 0 deletions backend/src/main/java/dev/tripdraw/domain/trip/Route.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ public void deletePointById(Long pointId) {

pointToDelete.delete();
}

public List<Point> points() {
return points.stream()
.filter(point -> !point.isDeleted())
.toList();
}
}
4 changes: 1 addition & 3 deletions backend/src/main/java/dev/tripdraw/domain/trip/Trip.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ public void deletePointById(Long pointId) {
}

public List<Point> points() {
return route.points().stream()
.filter(point -> !point.isDeleted())
.toList();
return route.points();
}

public String nameValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,10 @@ void setUp() {
tripService.deletePoint(loginUser, response.pointId(), trip.id());

// then
Point deletedPoint = trip.route().points()
assertThat(trip.route().points()
.stream()
.filter(point -> Objects.equals(point.id(), response.pointId()))
.findFirst()
.get();

assertThat(deletedPoint.isDeleted()).isTrue();
.anyMatch(point -> Objects.equals(point.id(), response.pointId())))
.isFalse();
}

@Test
Expand Down
16 changes: 16 additions & 0 deletions backend/src/test/java/dev/tripdraw/domain/trip/RouteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,21 @@ class RouteTest {
.isInstanceOf(TripException.class)
.hasMessage(POINT_NOT_FOUND.message());
}

@Test
void 삭제된_위치정보는_반환하지_않는다() {
// given
Route route = new Route();
Point point1 = new Point(1L, 1.1, 2.1, false, LocalDateTime.now());
Point point2 = new Point(2L, 3.1, 4.1, false, LocalDateTime.now());
route.add(point1);
route.add(point2);

// when
route.deletePointById(1L);

// then
assertThat(route.points()).containsExactly(point2);
}
}

0 comments on commit 45bd5c9

Please sign in to comment.