Skip to content

Commit

Permalink
fix: 응답 형식 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
linirini committed Jul 25, 2024
1 parent 8465f69 commit a2b3424
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.staccato.visit.repository.VisitImageRepository;
import com.staccato.visit.repository.VisitRepository;
import com.staccato.visit.service.dto.response.VisitResponse;
import com.staccato.visit.service.dto.response.VisitResponses;

import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -89,7 +88,7 @@ private TravelResponses getTravelResponses(List<TravelMember> travelMembers) {

public TravelDetailResponse readTravelById(long travelId) {
Travel travel = getTravelById(travelId);
VisitResponses visitResponses = getVisitResponses(visitRepository.findAllByTravelIdAndIsDeletedIsFalse(travelId));
List<VisitResponse> visitResponses = getVisitResponses(visitRepository.findAllByTravelIdAndIsDeletedIsFalse(travelId));
return new TravelDetailResponse(travel, visitResponses);
}

Expand All @@ -98,10 +97,10 @@ private Travel getTravelById(long travelId) {
.orElseThrow(() -> new StaccatoException("요청하신 여행을 찾을 수 없어요."));
}

private VisitResponses getVisitResponses(List<Visit> visits) {
return new VisitResponses(visits.stream()
private List<VisitResponse> getVisitResponses(List<Visit> visits) {
return visits.stream()
.map(visit -> new VisitResponse(visit, getFirstVisitImageUrl(visit)))
.toList());
.toList();
}

private String getFirstVisitImageUrl(Visit visit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.staccato.travel.service.dto.response;

import java.time.LocalDate;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.staccato.member.service.dto.response.MemberResponses;
import com.staccato.member.service.dto.response.MemberResponse;
import com.staccato.travel.domain.Travel;
import com.staccato.visit.service.dto.response.VisitResponses;
import com.staccato.visit.service.dto.response.VisitResponse;

public record TravelDetailResponse(
Long travelId,
Expand All @@ -14,19 +15,23 @@ public record TravelDetailResponse(
@JsonInclude(JsonInclude.Include.NON_NULL) String description,
LocalDate startAt,
LocalDate endAt,
MemberResponses mates,
VisitResponses visits
List<MemberResponse> mates,
List<VisitResponse> visits
) {
public TravelDetailResponse(Travel travel, VisitResponses visitResponses) {
public TravelDetailResponse(Travel travel, List<VisitResponse> visitResponses) {
this(
travel.getId(),
travel.getThumbnailUrl(),
travel.getTitle(),
travel.getDescription(),
travel.getStartAt(),
travel.getEndAt(),
MemberResponses.from(travel.getMates()),
toMemberResponses(travel),
visitResponses
);
}

private static List<MemberResponse> toMemberResponses(Travel travel) {
return travel.getMates().stream().map(MemberResponse::new).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ void readTravelById() {
// then
assertAll(
() -> assertThat(travelDetailResponse.travelId()).isEqualTo(targetId),
() -> assertThat(travelDetailResponse.mates().members()).hasSize(1),
() -> assertThat(travelDetailResponse.visits().visits()).hasSize(1),
() -> assertThat(travelDetailResponse.visits().visits().get(0).visitId()).isEqualTo(visit.getId())
() -> assertThat(travelDetailResponse.mates()).hasSize(1),
() -> assertThat(travelDetailResponse.visits()).hasSize(1),
() -> assertThat(travelDetailResponse.visits().get(0).visitId()).isEqualTo(visit.getId())
);
}

Expand Down

0 comments on commit a2b3424

Please sign in to comment.