-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: 장소에 대한 위도, 경도의 타입을 Double에서 String 으로 변경 * feat: 여행기 상세 조회 응답 response 생성 * feat: 여행기 상세 조회 Service 생성 * refactor: 여행기 상세 조회 응답 구조 변경
- Loading branch information
1 parent
33f4aeb
commit 0c75d30
Showing
5 changed files
with
87 additions
and
2 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
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueResponse.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,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) { | ||
} |
59 changes: 59 additions & 0 deletions
59
backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.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,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(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/woowacourse/touroot/travelogueday/dto/TravelogueDayResponse.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,7 @@ | ||
package woowacourse.touroot.travelogueday.dto; | ||
|
||
import java.util.List; | ||
import woowacourse.touroot.travelogueplace.dto.TraveloguePlaceResponse; | ||
|
||
public record TravelogueDayResponse(List<TraveloguePlaceResponse> places) { | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/woowacourse/touroot/travelogueplace/dto/TraveloguePlaceResponse.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,12 @@ | ||
package woowacourse.touroot.travelogueplace.dto; | ||
|
||
import java.util.List; | ||
|
||
public record TraveloguePlaceResponse( | ||
String name, | ||
List<String> photoUrls, | ||
String description, | ||
String latitude, | ||
String longitude | ||
) { | ||
} |