Skip to content

Commit

Permalink
[Feature] - 여행기 상세 조회 Service 생성
Browse files Browse the repository at this point in the history
* refactor: 장소에 대한 위도, 경도의 타입을 Double에서 String 으로 변경

* feat: 여행기 상세 조회 응답 response 생성

* feat: 여행기 상세 조회 Service 생성

* refactor: 여행기 상세 조회 응답 구조 변경
  • Loading branch information
nak-honest authored Jul 15, 2024
1 parent 33f4aeb commit 0c75d30
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class Place {
private String name;

@Column(nullable = false)
private Double latitude;
private String latitude;

@Column(nullable = false)
private Double longitude;
private String longitude;

private String googlePlaceId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package woowacourse.touroot.travelogue.dto;

import java.util.List;
import woowacourse.touroot.travelogueday.dto.TravelogueDayResponse;

public record TravelogueResponse(String title, String thumbnail, List<TravelogueDayResponse> days) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package woowacourse.touroot.travelogue.service;

import java.util.Comparator;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import woowacourse.touroot.travelogue.domain.Travelogue;
import woowacourse.touroot.travelogue.dto.TravelogueResponse;
import woowacourse.touroot.travelogue.repository.TravelogueRepository;
import woowacourse.touroot.travelogueday.domain.TravelogueDay;
import woowacourse.touroot.travelogueday.dto.TravelogueDayResponse;
import woowacourse.touroot.traveloguephoto.domain.TraveloguePhoto;
import woowacourse.touroot.travelogueplace.domain.TraveloguePlace;
import woowacourse.touroot.travelogueplace.dto.TraveloguePlaceResponse;

@RequiredArgsConstructor
@Service
public class TravelogueService {

private final TravelogueRepository travelogueRepository;

@Transactional(readOnly = true)
public TravelogueResponse findTravelogueById(Long id) {
Travelogue travelogue = travelogueRepository.findById(id).get();

return new TravelogueResponse(travelogue.getTitle(), travelogue.getThumbnail(), getDayResponses(travelogue));
}

private List<TravelogueDayResponse> getDayResponses(Travelogue travelogue) {
return travelogue.getTravelogueDays()
.stream()
.sorted(Comparator.comparing(TravelogueDay::getOrder))
.map(travelogueDay -> new TravelogueDayResponse(getPlaceResponses(travelogueDay)))
.toList();
}

private List<TraveloguePlaceResponse> getPlaceResponses(TravelogueDay day) {
return day.getTraveloguePlaces()
.stream()
.sorted(Comparator.comparing(TraveloguePlace::getOrder))
.map(traveloguePlace -> new TraveloguePlaceResponse(
traveloguePlace.getPlace().getName(),
getPhotoUrls(traveloguePlace),
traveloguePlace.getDescription(),
traveloguePlace.getPlace().getLatitude(),
traveloguePlace.getPlace().getLongitude()
))
.toList();
}

private List<String> getPhotoUrls(TraveloguePlace traveloguePlace) {
return traveloguePlace.getTraveloguePhotos()
.stream()
.sorted(Comparator.comparing(TraveloguePhoto::getOrder))
.map(TraveloguePhoto::getKey)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package woowacourse.touroot.travelogueday.dto;

import java.util.List;
import woowacourse.touroot.travelogueplace.dto.TraveloguePlaceResponse;

public record TravelogueDayResponse(List<TraveloguePlaceResponse> places) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package woowacourse.touroot.travelogueplace.dto;

import java.util.List;

public record TraveloguePlaceResponse(
String name,
List<String> photoUrls,
String description,
String latitude,
String longitude
) {
}

0 comments on commit 0c75d30

Please sign in to comment.