From efb9362e474e4f4aa349643fb9fafca3f9e2235a Mon Sep 17 00:00:00 2001 From: hangillee Date: Fri, 19 Jul 2024 16:17:44 +0900 Subject: [PATCH 01/11] =?UTF-8?q?feat:=20=EC=97=AC=ED=96=89=EA=B8=B0=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20API=EB=A5=BC=20=EC=9C=84=ED=95=9C=20DTO=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../place/dto/TravelogueLocationResponse.java | 16 ++++++++++ .../travelogue/dto/TravelogueDayRequest.java | 18 +++++++++++ .../dto/TravelogueLocationRequest.java | 14 +++++++++ .../dto/TraveloguePhotoRequest.java | 17 ++++++++++ .../dto/TraveloguePlaceRequest.java | 31 +++++++++++++++++++ .../travelogue/dto/TravelogueRequest.java | 23 ++++++++++++++ 6 files changed, 119 insertions(+) create mode 100644 backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TravelogueLocationResponse.java create mode 100644 backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueDayRequest.java create mode 100644 backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueLocationRequest.java create mode 100644 backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePhotoRequest.java create mode 100644 backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePlaceRequest.java create mode 100644 backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueRequest.java diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TravelogueLocationResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TravelogueLocationResponse.java new file mode 100644 index 00000000..bbb4c5e8 --- /dev/null +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TravelogueLocationResponse.java @@ -0,0 +1,16 @@ +package woowacourse.touroot.travelogue.domain.place.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Builder; + +@Builder +public record TravelogueLocationResponse( + @Schema(description = "여행기 장소 위도", example = "37.5175896") + @NotBlank(message = "여행기 장소 위도는 비어있을 수 없습니다.") + String lat, + @Schema(description = "여행기 장소 설명", example = "127.0867236") + @NotBlank(message = "여행기 장소 경도는 비어있을 수 없습니다.") + String lng +) { +} diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueDayRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueDayRequest.java new file mode 100644 index 00000000..cc4ae0d1 --- /dev/null +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueDayRequest.java @@ -0,0 +1,18 @@ +package woowacourse.touroot.travelogue.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import java.util.List; +import woowacourse.touroot.travelogue.domain.Travelogue; +import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; + +public record TravelogueDayRequest( + @Schema(description = "여행기 장소 목록") + @NotNull(message = "여행기 장소 목록은 비어있을 수 없습니다.") + List places +) { + + public TravelogueDay toTravelogueDay(int order, Travelogue travelogue) { + return new TravelogueDay(order, travelogue); + } +} diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueLocationRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueLocationRequest.java new file mode 100644 index 00000000..7ea14f96 --- /dev/null +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueLocationRequest.java @@ -0,0 +1,14 @@ +package woowacourse.touroot.travelogue.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; + +public record TravelogueLocationRequest( + @Schema(description = "여행기 장소 위도", example = "37.5175896") + @NotNull(message = "여행기 장소 위도는 비어있을 수 없습니다.") + String lat, + @Schema(description = "여행기 장소 경도", example = "127.0867236") + @NotNull(message = "여행기 장소 경도는 비어있을 수 없습니다.") + String lng +) { +} diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePhotoRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePhotoRequest.java new file mode 100644 index 00000000..98a1d117 --- /dev/null +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePhotoRequest.java @@ -0,0 +1,17 @@ +package woowacourse.touroot.travelogue.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import woowacourse.touroot.travelogue.domain.photo.domain.TraveloguePhoto; +import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; + +public record TraveloguePhotoRequest( + @Schema(description = "여행기 장소 위도", example = "37.5175896") + @NotNull(message = "여행기 장소 위도는 비어있을 수 없습니다.") + String key +) { + + public TraveloguePhoto toTraveloguePhoto(int order, TraveloguePlace traveloguePlace) { + return new TraveloguePhoto(order, key, traveloguePlace); + } +} diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePlaceRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePlaceRequest.java new file mode 100644 index 00000000..8bbfbf18 --- /dev/null +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePlaceRequest.java @@ -0,0 +1,31 @@ +package woowacourse.touroot.travelogue.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import java.util.List; +import woowacourse.touroot.place.domain.Place; +import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; +import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; + +public record TraveloguePlaceRequest( + @Schema(description = "여행기 장소 이름", example = "선릉 캠퍼스") + @NotNull(message = "여행기 장소 이름은 비어있을 수 없습니다.") + String name, + @Schema(description = "여행기 장소 위치 정보") + @NotNull(message = "여행기 장소 위치 정보는 비어있을 수 없습니다.") + TravelogueLocationRequest location, + @Schema(description = "여행기 장소 설명", example = "성담 빌딩에 위치한 선릉 캠퍼스입니다.") + String description, + @Schema(description = "여행기 장소 사진") + @NotNull(message = "여행기 장소 사진은 비어있을 수 없습니다.") + List photos +) { + + public TraveloguePlace toTraveloguePlace(int order, Place place, TravelogueDay travelogueDay) { + return new TraveloguePlace(order, description, place, travelogueDay); + } + + public Place toPlace() { + return new Place(name, location.lat(), location.lng()); + } +} diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueRequest.java new file mode 100644 index 00000000..bdb45f12 --- /dev/null +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueRequest.java @@ -0,0 +1,23 @@ +package woowacourse.touroot.travelogue.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import java.util.List; +import woowacourse.touroot.travelogue.domain.Travelogue; + +public record TravelogueRequest( + @Schema(description = "여행기 제목", example = "서울 강남 여행기") + @NotNull(message = "여행기 제목은 비어있을 수 없습니다.") + String title, + @Schema(description = "여행기 섬네일", example = "https://thumbnail.png") + @NotNull(message = "여행기 섬네일은 비어있을 수 없습니다.") + String thumbnail, + @Schema(description = "여행기 일자 목록") + @NotNull(message = "여행기 일자 목록은 비어있을 수 없습니다.") + List days +) { + + public Travelogue toTravelogue() { + return new Travelogue(title, thumbnail); + } +} From 2bfb7496f68fd1f9e81fa564d272219e851d319b Mon Sep 17 00:00:00 2001 From: hangillee Date: Fri, 19 Jul 2024 16:18:28 +0900 Subject: [PATCH 02/11] =?UTF-8?q?feat:=20=EC=97=AC=ED=96=89=EA=B8=B0=20?= =?UTF-8?q?=EC=82=AC=EC=A7=84=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EB=A7=A4=EA=B0=9C=EB=B3=80=EC=88=98=20?= =?UTF-8?q?=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../travelogue/domain/photo/domain/TraveloguePhoto.java | 2 +- .../src/test/java/woowacourse/touroot/utils/TestFixture.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/domain/TraveloguePhoto.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/domain/TraveloguePhoto.java index bdc59bd6..af8b03ca 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/domain/TraveloguePhoto.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/domain/TraveloguePhoto.java @@ -35,7 +35,7 @@ public class TraveloguePhoto extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) private TraveloguePlace traveloguePlace; - public TraveloguePhoto(String key, Integer order, TraveloguePlace traveloguePlace) { + public TraveloguePhoto(Integer order, String key, TraveloguePlace traveloguePlace) { this(null, key, order, traveloguePlace); } } diff --git a/backend/src/test/java/woowacourse/touroot/utils/TestFixture.java b/backend/src/test/java/woowacourse/touroot/utils/TestFixture.java index 32a27c68..179a9e44 100644 --- a/backend/src/test/java/woowacourse/touroot/utils/TestFixture.java +++ b/backend/src/test/java/woowacourse/touroot/utils/TestFixture.java @@ -29,7 +29,7 @@ public class TestFixture { @Autowired TraveloguePhotoRepository traveloguePhotoRepository; - + @Autowired private PlaceRepository placeRepository; @@ -51,7 +51,7 @@ public static TraveloguePlace getTraveloguePlace(Integer order, String descripti } public static TraveloguePhoto getTraveloguePhoto(String key, Integer order, TraveloguePlace traveloguePlace) { - return new TraveloguePhoto(key, order, traveloguePlace); + return new TraveloguePhoto(order, key, traveloguePlace); } public void initTravelogueTestData() { From 2bbbda664305029b3bf8a17a36471487a96349ba Mon Sep 17 00:00:00 2001 From: hangillee Date: Fri, 19 Jul 2024 16:18:41 +0900 Subject: [PATCH 03/11] =?UTF-8?q?feat:=20=EC=97=AC=ED=96=89=EA=B8=B0=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TravelogueController.java | 13 ++++ .../day/service/TravelogueDayService.java | 20 ++++++ .../photo/service/TraveloguePhotoService.java | 17 +++++ .../place/dto/TraveloguePlaceResponse.java | 7 +-- .../place/service/TraveloguePlaceService.java | 26 ++++++++ .../service/TravelogueFacadeService.java | 62 ++++++++++++++++++- .../travelogue/service/TravelogueService.java | 7 +++ 7 files changed, 145 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/controller/TravelogueController.java b/backend/src/main/java/woowacourse/touroot/travelogue/controller/TravelogueController.java index 41792d9d..19d32cdd 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/controller/TravelogueController.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/controller/TravelogueController.java @@ -3,12 +3,16 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import java.net.URI; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import woowacourse.touroot.travelogue.dto.TravelogueRequest; import woowacourse.touroot.travelogue.dto.TravelogueResponse; import woowacourse.touroot.travelogue.service.TravelogueFacadeService; @@ -20,6 +24,15 @@ public class TravelogueController { private final TravelogueFacadeService travelogueFacadeService; + @Operation(description = "여행기 작성") + @PostMapping + public ResponseEntity createTravelogue(@Valid @RequestBody TravelogueRequest request) { + TravelogueResponse response = travelogueFacadeService.createTravelogue(request); + + return ResponseEntity.created(URI.create("/api/v1/travelogues/" + response.id())) + .body(response); + } + @Operation(description = "여행기 상세 조회") @GetMapping("/{id}") public ResponseEntity findTravelogue(@Valid @PathVariable Long id) { diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/service/TravelogueDayService.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/service/TravelogueDayService.java index 93a99bbd..5bcf9655 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/service/TravelogueDayService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/service/TravelogueDayService.java @@ -1,6 +1,8 @@ package woowacourse.touroot.travelogue.domain.day.service; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -8,6 +10,8 @@ import woowacourse.touroot.travelogue.domain.Travelogue; import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; import woowacourse.touroot.travelogue.domain.day.repository.TravelogueDayRepository; +import woowacourse.touroot.travelogue.dto.TravelogueDayRequest; +import woowacourse.touroot.travelogue.dto.TraveloguePlaceRequest; @RequiredArgsConstructor @Service @@ -15,6 +19,22 @@ public class TravelogueDayService { private final TravelogueDayRepository travelogueDayRepository; + @Transactional + public Map> createDays( + List requests, + Travelogue travelogue + ) { + Map> daysWithPlaceRequests = new LinkedHashMap<>(); + + for (int i = 0; i < requests.size(); i++) { + TravelogueDayRequest request = requests.get(i); + TravelogueDay travelogueDay = request.toTravelogueDay(i, travelogue); + daysWithPlaceRequests.put(travelogueDayRepository.save(travelogueDay), request.places()); + } + + return daysWithPlaceRequests; + } + @Transactional(readOnly = true) public List findDaysByTravelogue(Travelogue travelogue) { return travelogueDayRepository.findByTravelogue(travelogue); diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/service/TraveloguePhotoService.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/service/TraveloguePhotoService.java index eb082eb8..5a561407 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/service/TraveloguePhotoService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/service/TraveloguePhotoService.java @@ -1,12 +1,15 @@ package woowacourse.touroot.travelogue.domain.photo.service; +import java.util.ArrayList; 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.photo.domain.TraveloguePhoto; import woowacourse.touroot.travelogue.domain.photo.repository.TraveloguePhotoRepository; import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; +import woowacourse.touroot.travelogue.dto.TraveloguePhotoRequest; @RequiredArgsConstructor @Service @@ -14,6 +17,20 @@ public class TraveloguePhotoService { private final TraveloguePhotoRepository traveloguePhotoRepository; + @Transactional + public List createPhotos(List requests, TraveloguePlace place) { + List photos = new ArrayList<>(); + + for (int i = 0; i < requests.size(); i++) { + TraveloguePhotoRequest request = requests.get(i); + TraveloguePhoto photo = request.toTraveloguePhoto(i, place); + photos.add(traveloguePhotoRepository.save(photo)); + } + + return photos; + } + + @Transactional(readOnly = true) public List findPhotoUrlsByPlace(TraveloguePlace traveloguePlace) { List photos = traveloguePhotoRepository.findByTraveloguePlace(traveloguePlace); diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java index d89220af..b52d861c 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java @@ -17,12 +17,7 @@ public record TraveloguePlaceResponse( @Schema(description = "여행기 장소 설명", example = "성담 빌딩에 위치한 선릉 캠퍼스입니다.") @NotBlank(message = "여행기 장소 설명은 비어있을 수 없습니다.") String description, - @Schema(description = "여행기 장소 위도", example = "37.5175896") - @NotBlank(message = "여행기 장소 위도는 비어있을 수 없습니다.") - String lat, - @Schema(description = "여행기 장소 설명", example = "127.0867236") - @NotBlank(message = "여행기 장소 경도는 비어있을 수 없습니다.") - String lng, + @NotNull TravelogueLocationResponse location, List photoUrls ) { } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/service/TraveloguePlaceService.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/service/TraveloguePlaceService.java index 9a6694de..4021ba4d 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/service/TraveloguePlaceService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/service/TraveloguePlaceService.java @@ -1,20 +1,46 @@ package woowacourse.touroot.travelogue.domain.place.service; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import woowacourse.touroot.global.exception.BadRequestException; +import woowacourse.touroot.place.domain.Place; +import woowacourse.touroot.place.repository.PlaceRepository; import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; import woowacourse.touroot.travelogue.domain.place.repsitory.TraveloguePlaceRepository; +import woowacourse.touroot.travelogue.dto.TraveloguePhotoRequest; +import woowacourse.touroot.travelogue.dto.TraveloguePlaceRequest; @RequiredArgsConstructor @Service public class TraveloguePlaceService { + private final PlaceRepository placeRepository; private final TraveloguePlaceRepository traveloguePlaceRepository; + @Transactional + public Map> createPlaces( + List requests, + TravelogueDay day + ) { + Map> places = new LinkedHashMap<>(); + + for (int i = 0; i < requests.size(); i++) { + TraveloguePlaceRequest request = requests.get(i); + Place place = request.toPlace(); + placeRepository.save(place); + + TraveloguePlace traveloguePlace = request.toTraveloguePlace(i, place, day); + places.put(traveloguePlaceRepository.save(traveloguePlace), request.photos()); + } + + return places; + } + @Transactional(readOnly = true) public List findTraveloguePlaceByDay(TravelogueDay travelogueDay) { return traveloguePlaceRepository.findByTravelogueDay(travelogueDay); diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java index d2418d36..5b591d91 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java @@ -2,16 +2,23 @@ import java.util.Comparator; import java.util.List; +import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import woowacourse.touroot.travelogue.domain.Travelogue; import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; import woowacourse.touroot.travelogue.domain.day.dto.TravelogueDayResponse; import woowacourse.touroot.travelogue.domain.day.service.TravelogueDayService; +import woowacourse.touroot.travelogue.domain.photo.domain.TraveloguePhoto; import woowacourse.touroot.travelogue.domain.photo.service.TraveloguePhotoService; import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; +import woowacourse.touroot.travelogue.domain.place.dto.TravelogueLocationResponse; import woowacourse.touroot.travelogue.domain.place.dto.TraveloguePlaceResponse; import woowacourse.touroot.travelogue.domain.place.service.TraveloguePlaceService; +import woowacourse.touroot.travelogue.dto.TravelogueDayRequest; +import woowacourse.touroot.travelogue.dto.TraveloguePhotoRequest; +import woowacourse.touroot.travelogue.dto.TraveloguePlaceRequest; +import woowacourse.touroot.travelogue.dto.TravelogueRequest; import woowacourse.touroot.travelogue.dto.TravelogueResponse; @RequiredArgsConstructor @@ -23,6 +30,53 @@ public class TravelogueFacadeService { private final TraveloguePlaceService traveloguePlaceService; private final TraveloguePhotoService traveloguePhotoService; + public TravelogueResponse createTravelogue(TravelogueRequest request) { + Travelogue travelogue = travelogueService.createTravelogue(request); + List dayRequests = request.days(); + + return TravelogueResponse.builder() + .id(travelogue.getId()) + .title(travelogue.getTitle()) + .thumbnail(travelogue.getThumbnail()) + .days(createDays(dayRequests, travelogue)) + .build(); + } + + private List createDays(List requests, Travelogue travelogue) { + Map> days = travelogueDayService.createDays(requests, travelogue); + + return days.keySet() + .stream() + .map(travelogueDay -> TravelogueDayResponse.builder() + .id(travelogueDay.getId()) + .places(createPlaces(days.get(travelogueDay), travelogueDay)) + .build()) + .toList(); + } + + private List createPlaces(List requests, TravelogueDay day) { + Map> places = traveloguePlaceService.createPlaces(requests, day); + + return places.keySet() + .stream() + .map(traveloguePlace -> TraveloguePlaceResponse.builder() + .id(traveloguePlace.getId()) + .name(traveloguePlace.getName()) + .description(traveloguePlace.getDescription()) + .location(getTravelogueLocationResponse(traveloguePlace)) + .photoUrls(createPhotos(places.get(traveloguePlace), traveloguePlace)) + .build()) + .toList(); + } + + private List createPhotos(List requests, TraveloguePlace place) { + List photos = traveloguePhotoService.createPhotos(requests, place); + + return photos.stream() + .map(TraveloguePhoto::getKey) + .toList(); + } + public TravelogueResponse findTravelogueById(Long id) { Travelogue travelogue = travelogueService.getTravelogueById(id); @@ -64,9 +118,15 @@ private TraveloguePlaceResponse getTraveloguePlaceResponse(TraveloguePlace place .id(place.getId()) .name(place.getName()) .description(place.getDescription()) + .location(getTravelogueLocationResponse(place)) + .photoUrls(findPhotoUrlsOfTraveloguePlace(place)) + .build(); + } + + private static TravelogueLocationResponse getTravelogueLocationResponse(TraveloguePlace place) { + return TravelogueLocationResponse.builder() .lat(place.getLatitude()) .lng(place.getLongitude()) - .photoUrls(findPhotoUrlsOfTraveloguePlace(place)) .build(); } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java index 41fe3571..6869df26 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java @@ -5,6 +5,7 @@ import org.springframework.transaction.annotation.Transactional; import woowacourse.touroot.global.exception.BadRequestException; import woowacourse.touroot.travelogue.domain.Travelogue; +import woowacourse.touroot.travelogue.dto.TravelogueRequest; import woowacourse.touroot.travelogue.repository.TravelogueRepository; @RequiredArgsConstructor @@ -13,6 +14,12 @@ public class TravelogueService { private final TravelogueRepository travelogueRepository; + @Transactional + public Travelogue createTravelogue(TravelogueRequest request) { + Travelogue travelogue = request.toTravelogue(); + return travelogueRepository.save(travelogue); + } + @Transactional(readOnly = true) public Travelogue getTravelogueById(Long id) { return travelogueRepository.findById(id) From 583bf62fd722fa49d9193bf7a7a8c146b62c54b9 Mon Sep 17 00:00:00 2001 From: hangillee Date: Fri, 19 Jul 2024 17:08:29 +0900 Subject: [PATCH 04/11] =?UTF-8?q?feat:=20=EB=A9=94=EC=9D=B8=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=EB=A5=BC=20=EC=9C=84=ED=95=9C=20=EC=97=AC?= =?UTF-8?q?=ED=96=89=EA=B8=B0=20=EC=A0=84=EC=B2=B4=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TravelogueController.java | 17 +++++++++++++++++ .../place/service/TraveloguePlaceService.java | 11 +++++++++-- .../travelogue/dto/TraveloguePhotoRequest.java | 4 ++-- .../service/TravelogueFacadeService.java | 15 +++++++++++++++ .../travelogue/service/TravelogueService.java | 6 ++++++ 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/controller/TravelogueController.java b/backend/src/main/java/woowacourse/touroot/travelogue/controller/TravelogueController.java index 19d32cdd..abdc3284 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/controller/TravelogueController.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/controller/TravelogueController.java @@ -1,10 +1,16 @@ package woowacourse.touroot.travelogue.controller; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import java.net.URI; import lombok.RequiredArgsConstructor; +import org.springdoc.core.converters.models.PageableAsQueryParam; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort.Direction; +import org.springframework.data.web.PageableDefault; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -38,4 +44,15 @@ public ResponseEntity createTravelogue(@Valid @RequestBody T public ResponseEntity findTravelogue(@Valid @PathVariable Long id) { return ResponseEntity.ok(travelogueFacadeService.findTravelogueById(id)); } + + @Operation(description = "여행기 메인 페이지 조회") + @PageableAsQueryParam + @GetMapping + public ResponseEntity> findMainPageTravelogues( + @Parameter(hidden = true) + @PageableDefault(size = 5, sort = "id", direction = Direction.DESC) + Pageable pageable + ) { + return ResponseEntity.ok(travelogueFacadeService.findTravelogues(pageable)); + } } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/service/TraveloguePlaceService.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/service/TraveloguePlaceService.java index 4021ba4d..8b2a71a5 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/service/TraveloguePlaceService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/service/TraveloguePlaceService.java @@ -31,8 +31,7 @@ public Map> createPlaces( for (int i = 0; i < requests.size(); i++) { TraveloguePlaceRequest request = requests.get(i); - Place place = request.toPlace(); - placeRepository.save(place); + Place place = getPlace(request); TraveloguePlace traveloguePlace = request.toTraveloguePlace(i, place, day); places.put(traveloguePlaceRepository.save(traveloguePlace), request.photos()); @@ -41,6 +40,14 @@ public Map> createPlaces( return places; } + private Place getPlace(TraveloguePlaceRequest request) { + return placeRepository.findByNameAndLatitudeAndLongitude( + request.name(), + request.location().lat(), + request.location().lng() + ).orElseGet(() -> placeRepository.save(request.toPlace())); + } + @Transactional(readOnly = true) public List findTraveloguePlaceByDay(TravelogueDay travelogueDay) { return traveloguePlaceRepository.findByTravelogueDay(travelogueDay); diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePhotoRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePhotoRequest.java index 98a1d117..8b6c1277 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePhotoRequest.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePhotoRequest.java @@ -6,8 +6,8 @@ import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; public record TraveloguePhotoRequest( - @Schema(description = "여행기 장소 위도", example = "37.5175896") - @NotNull(message = "여행기 장소 위도는 비어있을 수 없습니다.") + @Schema(description = "여행기 장소 사진 Key", example = "photo.png") + @NotNull(message = "여행기 장소 사진 Key 값은 비어있을 수 없습니다.") String key ) { diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java index 5b591d91..b77e2da7 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java @@ -4,6 +4,9 @@ import java.util.List; import java.util.Map; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import woowacourse.touroot.travelogue.domain.Travelogue; import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; @@ -80,6 +83,10 @@ private List createPhotos(List requests, Travelo public TravelogueResponse findTravelogueById(Long id) { Travelogue travelogue = travelogueService.getTravelogueById(id); + return getTravelogueResponse(travelogue); + } + + private TravelogueResponse getTravelogueResponse(final Travelogue travelogue) { return TravelogueResponse.builder() .id(travelogue.getId()) .title(travelogue.getTitle()) @@ -133,4 +140,12 @@ private static TravelogueLocationResponse getTravelogueLocationResponse(Travelog private List findPhotoUrlsOfTraveloguePlace(TraveloguePlace place) { return traveloguePhotoService.findPhotoUrlsByPlace(place); } + + public Page findTravelogues(final Pageable pageable) { + Page travelogues = travelogueService.findAll(pageable); + + return new PageImpl<>(travelogues.stream() + .map(this::getTravelogueResponse) + .toList()); + } } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java index 6869df26..4d433516 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java @@ -1,6 +1,8 @@ package woowacourse.touroot.travelogue.service; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import woowacourse.touroot.global.exception.BadRequestException; @@ -25,4 +27,8 @@ public Travelogue getTravelogueById(Long id) { return travelogueRepository.findById(id) .orElseThrow(() -> new BadRequestException("존재하지 않는 여행기입니다.")); } + + public Page findAll(final Pageable pageable) { + return travelogueRepository.findAll(pageable); + } } From 4bffdff980c72425527ca24620f7cae85e5ed59c Mon Sep 17 00:00:00 2001 From: hangillee Date: Fri, 19 Jul 2024 17:23:11 +0900 Subject: [PATCH 05/11] =?UTF-8?q?chore:=20EOL=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../touroot/travelogue/controller/TravelogueControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/test/java/woowacourse/touroot/travelogue/controller/TravelogueControllerTest.java b/backend/src/test/java/woowacourse/touroot/travelogue/controller/TravelogueControllerTest.java index adfa3748..20d04067 100644 --- a/backend/src/test/java/woowacourse/touroot/travelogue/controller/TravelogueControllerTest.java +++ b/backend/src/test/java/woowacourse/touroot/travelogue/controller/TravelogueControllerTest.java @@ -43,4 +43,4 @@ void findTravelogue() { .statusCode(200) .body("title", is("여행기 1")); } -} \ No newline at end of file +} From 7c343654a0fe92335a759981645207aee1402aae Mon Sep 17 00:00:00 2001 From: hangillee Date: Sun, 21 Jul 2024 13:42:11 +0900 Subject: [PATCH 06/11] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20Bean=20validation=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../travelogue/domain/day/dto/TravelogueDayResponse.java | 3 --- .../domain/place/dto/TravelogueLocationResponse.java | 3 --- .../domain/place/dto/TraveloguePlaceResponse.java | 6 ------ .../touroot/travelogue/dto/TravelogueResponse.java | 2 ++ 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/dto/TravelogueDayResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/dto/TravelogueDayResponse.java index 15fbd212..3bcdca7b 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/dto/TravelogueDayResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/dto/TravelogueDayResponse.java @@ -1,7 +1,6 @@ package woowacourse.touroot.travelogue.domain.day.dto; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotNull; import java.util.List; import lombok.Builder; import woowacourse.touroot.travelogue.domain.place.dto.TraveloguePlaceResponse; @@ -9,10 +8,8 @@ @Builder public record TravelogueDayResponse( @Schema(description = "여행기 일자 ID", example = "1") - @NotNull(message = "ID는 비어있을 수 없습니다.") Long id, @Schema(description = "여행기 장소 목록") - @NotNull(message = "여행기 장소 정보는 비어있을 수 없습니다.") List places ) { } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TravelogueLocationResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TravelogueLocationResponse.java index bbb4c5e8..08825e0c 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TravelogueLocationResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TravelogueLocationResponse.java @@ -1,16 +1,13 @@ package woowacourse.touroot.travelogue.domain.place.dto; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotBlank; import lombok.Builder; @Builder public record TravelogueLocationResponse( @Schema(description = "여행기 장소 위도", example = "37.5175896") - @NotBlank(message = "여행기 장소 위도는 비어있을 수 없습니다.") String lat, @Schema(description = "여행기 장소 설명", example = "127.0867236") - @NotBlank(message = "여행기 장소 경도는 비어있을 수 없습니다.") String lng ) { } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java index b52d861c..2bd1e5e2 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java @@ -1,23 +1,17 @@ package woowacourse.touroot.travelogue.domain.place.dto; import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; import java.util.List; import lombok.Builder; @Builder public record TraveloguePlaceResponse( @Schema(description = "여행기 장소 ID", example = "1") - @NotNull(message = "ID는 비어있을 수 없습니다.") Long id, @Schema(description = "여행기 장소 이름", example = "선릉 캠퍼스") - @NotBlank(message = "여행기 장소 이름은 비어있을 수 없습니다.") String name, @Schema(description = "여행기 장소 설명", example = "성담 빌딩에 위치한 선릉 캠퍼스입니다.") - @NotBlank(message = "여행기 장소 설명은 비어있을 수 없습니다.") String description, - @NotNull TravelogueLocationResponse location, List photoUrls ) { } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueResponse.java index e9f44219..2d848980 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueResponse.java @@ -1,6 +1,7 @@ package woowacourse.touroot.travelogue.dto; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import java.util.List; import lombok.Builder; @@ -19,6 +20,7 @@ public record TravelogueResponse( String thumbnail, @Schema(description = "여행기 일자 목록") @NotNull(message = "여행기 일자 목록은 비어있을 수 없습니다.") + @Valid List days ) { } From 0d17f0fdca1c976cb3c36c76dd6f166e51f9c94a Mon Sep 17 00:00:00 2001 From: hangillee Date: Sun, 21 Jul 2024 13:43:01 +0900 Subject: [PATCH 07/11] =?UTF-8?q?refactor:=20embedded=20DTO=20bean=20valid?= =?UTF-8?q?ation=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../touroot/travelogue/dto/TravelogueDayRequest.java | 2 ++ .../touroot/travelogue/dto/TraveloguePlaceRequest.java | 3 +++ .../woowacourse/touroot/travelogue/dto/TravelogueRequest.java | 2 ++ 3 files changed, 7 insertions(+) diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueDayRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueDayRequest.java index cc4ae0d1..827a1c83 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueDayRequest.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueDayRequest.java @@ -1,6 +1,7 @@ package woowacourse.touroot.travelogue.dto; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import java.util.List; import woowacourse.touroot.travelogue.domain.Travelogue; @@ -9,6 +10,7 @@ public record TravelogueDayRequest( @Schema(description = "여행기 장소 목록") @NotNull(message = "여행기 장소 목록은 비어있을 수 없습니다.") + @Valid List places ) { diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePlaceRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePlaceRequest.java index 8bbfbf18..216218ed 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePlaceRequest.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePlaceRequest.java @@ -1,6 +1,7 @@ package woowacourse.touroot.travelogue.dto; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import java.util.List; import woowacourse.touroot.place.domain.Place; @@ -13,11 +14,13 @@ public record TraveloguePlaceRequest( String name, @Schema(description = "여행기 장소 위치 정보") @NotNull(message = "여행기 장소 위치 정보는 비어있을 수 없습니다.") + @Valid TravelogueLocationRequest location, @Schema(description = "여행기 장소 설명", example = "성담 빌딩에 위치한 선릉 캠퍼스입니다.") String description, @Schema(description = "여행기 장소 사진") @NotNull(message = "여행기 장소 사진은 비어있을 수 없습니다.") + @Valid List photos ) { diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueRequest.java index bdb45f12..d398518f 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueRequest.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueRequest.java @@ -1,6 +1,7 @@ package woowacourse.touroot.travelogue.dto; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import java.util.List; import woowacourse.touroot.travelogue.domain.Travelogue; @@ -14,6 +15,7 @@ public record TravelogueRequest( String thumbnail, @Schema(description = "여행기 일자 목록") @NotNull(message = "여행기 일자 목록은 비어있을 수 없습니다.") + @Valid List days ) { From 24b2bdd041c72791f638bfc6c3cc0e367be34e46 Mon Sep 17 00:00:00 2001 From: hangillee Date: Sun, 21 Jul 2024 13:50:22 +0900 Subject: [PATCH 08/11] =?UTF-8?q?chore:=20=EC=8B=A4=EC=88=98=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=ED=95=9C=20=ED=95=84=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../travelogue/domain/place/dto/TraveloguePlaceResponse.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java index 2bd1e5e2..9f553e7a 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java @@ -12,6 +12,7 @@ public record TraveloguePlaceResponse( String name, @Schema(description = "여행기 장소 설명", example = "성담 빌딩에 위치한 선릉 캠퍼스입니다.") String description, + TravelogueLocationResponse location, List photoUrls ) { } From 12b278d5fed020bedd04a694e404c14dc45648bb Mon Sep 17 00:00:00 2001 From: hangillee Date: Sun, 21 Jul 2024 21:32:13 +0900 Subject: [PATCH 09/11] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TravelogueController.java | 4 +-- .../{day/domain => }/TravelogueDay.java | 3 +-- .../{photo/domain => }/TraveloguePhoto.java | 3 +-- .../{place/domain => }/TraveloguePlace.java | 3 +-- .../{ => request}/TravelogueDayRequest.java | 4 +-- .../TravelogueLocationRequest.java | 2 +- .../{ => request}/TraveloguePhotoRequest.java | 6 ++--- .../{ => request}/TraveloguePlaceRequest.java | 6 ++--- .../dto/{ => request}/TravelogueRequest.java | 2 +- .../response}/TravelogueDayResponse.java | 3 +-- .../response}/TravelogueLocationResponse.java | 2 +- .../response}/TraveloguePlaceResponse.java | 2 +- .../{ => response}/TravelogueResponse.java | 3 +-- .../repository/TravelogueDayRepository.java | 6 ++--- .../repository/TraveloguePhotoRepository.java | 6 ++--- .../TraveloguePlaceRepository.java | 8 +++--- .../service/TravelogueDayService.java | 10 ++++---- .../service/TravelogueFacadeService.java | 25 ++++++++----------- .../service/TraveloguePhotoService.java | 10 ++++---- .../service/TraveloguePlaceService.java | 12 ++++----- .../travelogue/service/TravelogueService.java | 2 +- .../touroot/utils/TestFixture.java | 15 ++++++----- 22 files changed, 64 insertions(+), 73 deletions(-) rename backend/src/main/java/woowacourse/touroot/travelogue/domain/{day/domain => }/TravelogueDay.java (89%) rename backend/src/main/java/woowacourse/touroot/travelogue/domain/{photo/domain => }/TraveloguePhoto.java (89%) rename backend/src/main/java/woowacourse/touroot/travelogue/domain/{place/domain => }/TraveloguePlace.java (91%) rename backend/src/main/java/woowacourse/touroot/travelogue/dto/{ => request}/TravelogueDayRequest.java (83%) rename backend/src/main/java/woowacourse/touroot/travelogue/dto/{ => request}/TravelogueLocationRequest.java (90%) rename backend/src/main/java/woowacourse/touroot/travelogue/dto/{ => request}/TraveloguePhotoRequest.java (72%) rename backend/src/main/java/woowacourse/touroot/travelogue/dto/{ => request}/TraveloguePlaceRequest.java (87%) rename backend/src/main/java/woowacourse/touroot/travelogue/dto/{ => request}/TravelogueRequest.java (94%) rename backend/src/main/java/woowacourse/touroot/travelogue/{domain/day/dto => dto/response}/TravelogueDayResponse.java (71%) rename backend/src/main/java/woowacourse/touroot/travelogue/{domain/place/dto => dto/response}/TravelogueLocationResponse.java (85%) rename backend/src/main/java/woowacourse/touroot/travelogue/{domain/place/dto => dto/response}/TraveloguePlaceResponse.java (90%) rename backend/src/main/java/woowacourse/touroot/travelogue/dto/{ => response}/TravelogueResponse.java (89%) rename backend/src/main/java/woowacourse/touroot/travelogue/{domain/day => }/repository/TravelogueDayRepository.java (68%) rename backend/src/main/java/woowacourse/touroot/travelogue/{domain/photo => }/repository/TraveloguePhotoRepository.java (55%) rename backend/src/main/java/woowacourse/touroot/travelogue/{domain/place/repsitory => repository}/TraveloguePlaceRepository.java (54%) rename backend/src/main/java/woowacourse/touroot/travelogue/{domain/day => }/service/TravelogueDayService.java (81%) rename backend/src/main/java/woowacourse/touroot/travelogue/{domain/photo => }/service/TraveloguePhotoService.java (77%) rename backend/src/main/java/woowacourse/touroot/travelogue/{domain/place => }/service/TraveloguePlaceService.java (82%) diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/controller/TravelogueController.java b/backend/src/main/java/woowacourse/touroot/travelogue/controller/TravelogueController.java index abdc3284..57fd67c8 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/controller/TravelogueController.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/controller/TravelogueController.java @@ -18,8 +18,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import woowacourse.touroot.travelogue.dto.TravelogueRequest; -import woowacourse.touroot.travelogue.dto.TravelogueResponse; +import woowacourse.touroot.travelogue.dto.request.TravelogueRequest; +import woowacourse.touroot.travelogue.dto.response.TravelogueResponse; import woowacourse.touroot.travelogue.service.TravelogueFacadeService; @Tag(name = "여행기") diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/domain/TravelogueDay.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/TravelogueDay.java similarity index 89% rename from backend/src/main/java/woowacourse/touroot/travelogue/domain/day/domain/TravelogueDay.java rename to backend/src/main/java/woowacourse/touroot/travelogue/domain/TravelogueDay.java index e3d306e9..2ba62d65 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/domain/TravelogueDay.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/TravelogueDay.java @@ -1,4 +1,4 @@ -package woowacourse.touroot.travelogue.domain.day.domain; +package woowacourse.touroot.travelogue.domain; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -13,7 +13,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; import woowacourse.touroot.entity.BaseEntity; -import woowacourse.touroot.travelogue.domain.Travelogue; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/domain/TraveloguePhoto.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/TraveloguePhoto.java similarity index 89% rename from backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/domain/TraveloguePhoto.java rename to backend/src/main/java/woowacourse/touroot/travelogue/domain/TraveloguePhoto.java index af8b03ca..38d64560 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/domain/TraveloguePhoto.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/TraveloguePhoto.java @@ -1,4 +1,4 @@ -package woowacourse.touroot.travelogue.domain.photo.domain; +package woowacourse.touroot.travelogue.domain; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -13,7 +13,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; import woowacourse.touroot.entity.BaseEntity; -import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/domain/TraveloguePlace.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/TraveloguePlace.java similarity index 91% rename from backend/src/main/java/woowacourse/touroot/travelogue/domain/place/domain/TraveloguePlace.java rename to backend/src/main/java/woowacourse/touroot/travelogue/domain/TraveloguePlace.java index 21942047..b09d2ac5 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/domain/TraveloguePlace.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/TraveloguePlace.java @@ -1,4 +1,4 @@ -package woowacourse.touroot.travelogue.domain.place.domain; +package woowacourse.touroot.travelogue.domain; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -14,7 +14,6 @@ import lombok.NoArgsConstructor; import woowacourse.touroot.entity.BaseEntity; import woowacourse.touroot.place.domain.Place; -import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueDayRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TravelogueDayRequest.java similarity index 83% rename from backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueDayRequest.java rename to backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TravelogueDayRequest.java index 827a1c83..9a84a0ed 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueDayRequest.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TravelogueDayRequest.java @@ -1,11 +1,11 @@ -package woowacourse.touroot.travelogue.dto; +package woowacourse.touroot.travelogue.dto.request; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import java.util.List; import woowacourse.touroot.travelogue.domain.Travelogue; -import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; +import woowacourse.touroot.travelogue.domain.TravelogueDay; public record TravelogueDayRequest( @Schema(description = "여행기 장소 목록") diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueLocationRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TravelogueLocationRequest.java similarity index 90% rename from backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueLocationRequest.java rename to backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TravelogueLocationRequest.java index 7ea14f96..9f995d1f 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueLocationRequest.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TravelogueLocationRequest.java @@ -1,4 +1,4 @@ -package woowacourse.touroot.travelogue.dto; +package woowacourse.touroot.travelogue.dto.request; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePhotoRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TraveloguePhotoRequest.java similarity index 72% rename from backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePhotoRequest.java rename to backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TraveloguePhotoRequest.java index 8b6c1277..9e07e8a0 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePhotoRequest.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TraveloguePhotoRequest.java @@ -1,9 +1,9 @@ -package woowacourse.touroot.travelogue.dto; +package woowacourse.touroot.travelogue.dto.request; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; -import woowacourse.touroot.travelogue.domain.photo.domain.TraveloguePhoto; -import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; +import woowacourse.touroot.travelogue.domain.TraveloguePhoto; +import woowacourse.touroot.travelogue.domain.TraveloguePlace; public record TraveloguePhotoRequest( @Schema(description = "여행기 장소 사진 Key", example = "photo.png") diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePlaceRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TraveloguePlaceRequest.java similarity index 87% rename from backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePlaceRequest.java rename to backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TraveloguePlaceRequest.java index 216218ed..fe6c92a1 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TraveloguePlaceRequest.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TraveloguePlaceRequest.java @@ -1,12 +1,12 @@ -package woowacourse.touroot.travelogue.dto; +package woowacourse.touroot.travelogue.dto.request; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import java.util.List; import woowacourse.touroot.place.domain.Place; -import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; -import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; +import woowacourse.touroot.travelogue.domain.TravelogueDay; +import woowacourse.touroot.travelogue.domain.TraveloguePlace; public record TraveloguePlaceRequest( @Schema(description = "여행기 장소 이름", example = "선릉 캠퍼스") diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueRequest.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TravelogueRequest.java similarity index 94% rename from backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueRequest.java rename to backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TravelogueRequest.java index d398518f..1450b8c8 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueRequest.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/request/TravelogueRequest.java @@ -1,4 +1,4 @@ -package woowacourse.touroot.travelogue.dto; +package woowacourse.touroot.travelogue.dto.request; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.Valid; diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/dto/TravelogueDayResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueDayResponse.java similarity index 71% rename from backend/src/main/java/woowacourse/touroot/travelogue/domain/day/dto/TravelogueDayResponse.java rename to backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueDayResponse.java index 3bcdca7b..cf0501cf 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/dto/TravelogueDayResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueDayResponse.java @@ -1,9 +1,8 @@ -package woowacourse.touroot.travelogue.domain.day.dto; +package woowacourse.touroot.travelogue.dto.response; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; import lombok.Builder; -import woowacourse.touroot.travelogue.domain.place.dto.TraveloguePlaceResponse; @Builder public record TravelogueDayResponse( diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TravelogueLocationResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueLocationResponse.java similarity index 85% rename from backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TravelogueLocationResponse.java rename to backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueLocationResponse.java index 08825e0c..0cb17521 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TravelogueLocationResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueLocationResponse.java @@ -1,4 +1,4 @@ -package woowacourse.touroot.travelogue.domain.place.dto; +package woowacourse.touroot.travelogue.dto.response; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TraveloguePlaceResponse.java similarity index 90% rename from backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java rename to backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TraveloguePlaceResponse.java index 9f553e7a..299c2297 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/dto/TraveloguePlaceResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TraveloguePlaceResponse.java @@ -1,4 +1,4 @@ -package woowacourse.touroot.travelogue.domain.place.dto; +package woowacourse.touroot.travelogue.dto.response; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueResponse.java similarity index 89% rename from backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueResponse.java rename to backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueResponse.java index 2d848980..6e39278e 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/TravelogueResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueResponse.java @@ -1,11 +1,10 @@ -package woowacourse.touroot.travelogue.dto; +package woowacourse.touroot.travelogue.dto.response; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import java.util.List; import lombok.Builder; -import woowacourse.touroot.travelogue.domain.day.dto.TravelogueDayResponse; @Builder public record TravelogueResponse( diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/repository/TravelogueDayRepository.java b/backend/src/main/java/woowacourse/touroot/travelogue/repository/TravelogueDayRepository.java similarity index 68% rename from backend/src/main/java/woowacourse/touroot/travelogue/domain/day/repository/TravelogueDayRepository.java rename to backend/src/main/java/woowacourse/touroot/travelogue/repository/TravelogueDayRepository.java index d480bf83..b1fe0a89 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/repository/TravelogueDayRepository.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/repository/TravelogueDayRepository.java @@ -1,11 +1,11 @@ -package woowacourse.touroot.travelogue.domain.day.repository; +package woowacourse.touroot.travelogue.repository; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import woowacourse.touroot.travelogue.domain.Travelogue; -import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; +import woowacourse.touroot.travelogue.domain.TravelogueDay; public interface TravelogueDayRepository extends JpaRepository { - + List findByTravelogue(Travelogue travelogue); } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/repository/TraveloguePhotoRepository.java b/backend/src/main/java/woowacourse/touroot/travelogue/repository/TraveloguePhotoRepository.java similarity index 55% rename from backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/repository/TraveloguePhotoRepository.java rename to backend/src/main/java/woowacourse/touroot/travelogue/repository/TraveloguePhotoRepository.java index a63e83a3..90f508a2 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/repository/TraveloguePhotoRepository.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/repository/TraveloguePhotoRepository.java @@ -1,9 +1,9 @@ -package woowacourse.touroot.travelogue.domain.photo.repository; +package woowacourse.touroot.travelogue.repository; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; -import woowacourse.touroot.travelogue.domain.photo.domain.TraveloguePhoto; -import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; +import woowacourse.touroot.travelogue.domain.TraveloguePhoto; +import woowacourse.touroot.travelogue.domain.TraveloguePlace; public interface TraveloguePhotoRepository extends JpaRepository { diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/repsitory/TraveloguePlaceRepository.java b/backend/src/main/java/woowacourse/touroot/travelogue/repository/TraveloguePlaceRepository.java similarity index 54% rename from backend/src/main/java/woowacourse/touroot/travelogue/domain/place/repsitory/TraveloguePlaceRepository.java rename to backend/src/main/java/woowacourse/touroot/travelogue/repository/TraveloguePlaceRepository.java index d6e886c4..f28af54d 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/repsitory/TraveloguePlaceRepository.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/repository/TraveloguePlaceRepository.java @@ -1,11 +1,11 @@ -package woowacourse.touroot.travelogue.domain.place.repsitory; +package woowacourse.touroot.travelogue.repository; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; -import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; -import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; +import woowacourse.touroot.travelogue.domain.TravelogueDay; +import woowacourse.touroot.travelogue.domain.TraveloguePlace; public interface TraveloguePlaceRepository extends JpaRepository { - + List findByTravelogueDay(TravelogueDay travelogueDay); } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/service/TravelogueDayService.java b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueDayService.java similarity index 81% rename from backend/src/main/java/woowacourse/touroot/travelogue/domain/day/service/TravelogueDayService.java rename to backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueDayService.java index 5bcf9655..cbc3ba1e 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/day/service/TravelogueDayService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueDayService.java @@ -1,4 +1,4 @@ -package woowacourse.touroot.travelogue.domain.day.service; +package woowacourse.touroot.travelogue.service; import java.util.LinkedHashMap; import java.util.List; @@ -8,10 +8,10 @@ import org.springframework.transaction.annotation.Transactional; import woowacourse.touroot.global.exception.BadRequestException; import woowacourse.touroot.travelogue.domain.Travelogue; -import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; -import woowacourse.touroot.travelogue.domain.day.repository.TravelogueDayRepository; -import woowacourse.touroot.travelogue.dto.TravelogueDayRequest; -import woowacourse.touroot.travelogue.dto.TraveloguePlaceRequest; +import woowacourse.touroot.travelogue.domain.TravelogueDay; +import woowacourse.touroot.travelogue.dto.request.TravelogueDayRequest; +import woowacourse.touroot.travelogue.dto.request.TraveloguePlaceRequest; +import woowacourse.touroot.travelogue.repository.TravelogueDayRepository; @RequiredArgsConstructor @Service diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java index b77e2da7..152ef2e8 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java @@ -9,20 +9,17 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import woowacourse.touroot.travelogue.domain.Travelogue; -import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; -import woowacourse.touroot.travelogue.domain.day.dto.TravelogueDayResponse; -import woowacourse.touroot.travelogue.domain.day.service.TravelogueDayService; -import woowacourse.touroot.travelogue.domain.photo.domain.TraveloguePhoto; -import woowacourse.touroot.travelogue.domain.photo.service.TraveloguePhotoService; -import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; -import woowacourse.touroot.travelogue.domain.place.dto.TravelogueLocationResponse; -import woowacourse.touroot.travelogue.domain.place.dto.TraveloguePlaceResponse; -import woowacourse.touroot.travelogue.domain.place.service.TraveloguePlaceService; -import woowacourse.touroot.travelogue.dto.TravelogueDayRequest; -import woowacourse.touroot.travelogue.dto.TraveloguePhotoRequest; -import woowacourse.touroot.travelogue.dto.TraveloguePlaceRequest; -import woowacourse.touroot.travelogue.dto.TravelogueRequest; -import woowacourse.touroot.travelogue.dto.TravelogueResponse; +import woowacourse.touroot.travelogue.domain.TravelogueDay; +import woowacourse.touroot.travelogue.domain.TraveloguePhoto; +import woowacourse.touroot.travelogue.domain.TraveloguePlace; +import woowacourse.touroot.travelogue.dto.request.TravelogueDayRequest; +import woowacourse.touroot.travelogue.dto.request.TraveloguePhotoRequest; +import woowacourse.touroot.travelogue.dto.request.TraveloguePlaceRequest; +import woowacourse.touroot.travelogue.dto.request.TravelogueRequest; +import woowacourse.touroot.travelogue.dto.response.TravelogueDayResponse; +import woowacourse.touroot.travelogue.dto.response.TravelogueLocationResponse; +import woowacourse.touroot.travelogue.dto.response.TraveloguePlaceResponse; +import woowacourse.touroot.travelogue.dto.response.TravelogueResponse; @RequiredArgsConstructor @Service diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/service/TraveloguePhotoService.java b/backend/src/main/java/woowacourse/touroot/travelogue/service/TraveloguePhotoService.java similarity index 77% rename from backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/service/TraveloguePhotoService.java rename to backend/src/main/java/woowacourse/touroot/travelogue/service/TraveloguePhotoService.java index 5a561407..24b11db7 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/photo/service/TraveloguePhotoService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/service/TraveloguePhotoService.java @@ -1,4 +1,4 @@ -package woowacourse.touroot.travelogue.domain.photo.service; +package woowacourse.touroot.travelogue.service; import java.util.ArrayList; import java.util.Comparator; @@ -6,10 +6,10 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import woowacourse.touroot.travelogue.domain.photo.domain.TraveloguePhoto; -import woowacourse.touroot.travelogue.domain.photo.repository.TraveloguePhotoRepository; -import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; -import woowacourse.touroot.travelogue.dto.TraveloguePhotoRequest; +import woowacourse.touroot.travelogue.domain.TraveloguePhoto; +import woowacourse.touroot.travelogue.domain.TraveloguePlace; +import woowacourse.touroot.travelogue.dto.request.TraveloguePhotoRequest; +import woowacourse.touroot.travelogue.repository.TraveloguePhotoRepository; @RequiredArgsConstructor @Service diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/service/TraveloguePlaceService.java b/backend/src/main/java/woowacourse/touroot/travelogue/service/TraveloguePlaceService.java similarity index 82% rename from backend/src/main/java/woowacourse/touroot/travelogue/domain/place/service/TraveloguePlaceService.java rename to backend/src/main/java/woowacourse/touroot/travelogue/service/TraveloguePlaceService.java index 8b2a71a5..fcb72b29 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/place/service/TraveloguePlaceService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/service/TraveloguePlaceService.java @@ -1,4 +1,4 @@ -package woowacourse.touroot.travelogue.domain.place.service; +package woowacourse.touroot.travelogue.service; import java.util.LinkedHashMap; import java.util.List; @@ -9,11 +9,11 @@ import woowacourse.touroot.global.exception.BadRequestException; import woowacourse.touroot.place.domain.Place; import woowacourse.touroot.place.repository.PlaceRepository; -import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; -import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; -import woowacourse.touroot.travelogue.domain.place.repsitory.TraveloguePlaceRepository; -import woowacourse.touroot.travelogue.dto.TraveloguePhotoRequest; -import woowacourse.touroot.travelogue.dto.TraveloguePlaceRequest; +import woowacourse.touroot.travelogue.domain.TravelogueDay; +import woowacourse.touroot.travelogue.domain.TraveloguePlace; +import woowacourse.touroot.travelogue.dto.request.TraveloguePhotoRequest; +import woowacourse.touroot.travelogue.dto.request.TraveloguePlaceRequest; +import woowacourse.touroot.travelogue.repository.TraveloguePlaceRepository; @RequiredArgsConstructor @Service diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java index 4d433516..c841aa48 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java @@ -7,7 +7,7 @@ import org.springframework.transaction.annotation.Transactional; import woowacourse.touroot.global.exception.BadRequestException; import woowacourse.touroot.travelogue.domain.Travelogue; -import woowacourse.touroot.travelogue.dto.TravelogueRequest; +import woowacourse.touroot.travelogue.dto.request.TravelogueRequest; import woowacourse.touroot.travelogue.repository.TravelogueRepository; @RequiredArgsConstructor diff --git a/backend/src/test/java/woowacourse/touroot/utils/TestFixture.java b/backend/src/test/java/woowacourse/touroot/utils/TestFixture.java index 5c0f3de0..18cd9122 100644 --- a/backend/src/test/java/woowacourse/touroot/utils/TestFixture.java +++ b/backend/src/test/java/woowacourse/touroot/utils/TestFixture.java @@ -1,16 +1,17 @@ package woowacourse.touroot.utils; +import java.time.LocalDate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import woowacourse.touroot.place.domain.Place; import woowacourse.touroot.place.repository.PlaceRepository; import woowacourse.touroot.travelogue.domain.Travelogue; -import woowacourse.touroot.travelogue.domain.day.domain.TravelogueDay; -import woowacourse.touroot.travelogue.domain.day.repository.TravelogueDayRepository; -import woowacourse.touroot.travelogue.domain.photo.domain.TraveloguePhoto; -import woowacourse.touroot.travelogue.domain.photo.repository.TraveloguePhotoRepository; -import woowacourse.touroot.travelogue.domain.place.domain.TraveloguePlace; -import woowacourse.touroot.travelogue.domain.place.repsitory.TraveloguePlaceRepository; +import woowacourse.touroot.travelogue.domain.TravelogueDay; +import woowacourse.touroot.travelogue.domain.TraveloguePhoto; +import woowacourse.touroot.travelogue.domain.TraveloguePlace; +import woowacourse.touroot.travelogue.repository.TravelogueDayRepository; +import woowacourse.touroot.travelogue.repository.TraveloguePhotoRepository; +import woowacourse.touroot.travelogue.repository.TraveloguePlaceRepository; import woowacourse.touroot.travelogue.repository.TravelogueRepository; import woowacourse.touroot.travelplan.domain.TravelPlan; import woowacourse.touroot.travelplan.domain.TravelPlanDay; @@ -19,8 +20,6 @@ import woowacourse.touroot.travelplan.repository.TravelPlanPlaceRepository; import woowacourse.touroot.travelplan.repository.TravelPlanRepository; -import java.time.LocalDate; - @Component public class TestFixture { From 6d3062ecff2e8059326cbc80c4ea93df22b9870f Mon Sep 17 00:00:00 2001 From: hangillee Date: Sun, 21 Jul 2024 21:36:23 +0900 Subject: [PATCH 10/11] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20final=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../touroot/travelogue/service/TravelogueService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java index c841aa48..e9d805bb 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueService.java @@ -28,7 +28,7 @@ public Travelogue getTravelogueById(Long id) { .orElseThrow(() -> new BadRequestException("존재하지 않는 여행기입니다.")); } - public Page findAll(final Pageable pageable) { + public Page findAll(Pageable pageable) { return travelogueRepository.findAll(pageable); } } From 4853904be7e61db652a9c38d9eb5aee2dba15d17 Mon Sep 17 00:00:00 2001 From: hangillee Date: Mon, 22 Jul 2024 00:24:23 +0900 Subject: [PATCH 11/11] =?UTF-8?q?refactor:=20=EC=97=AC=ED=96=89=EA=B8=B0?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=EC=95=84=20=EC=A0=95=EC=A0=81=20?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A6=AC=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=EB=A5=BC=20=ED=99=9C=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../travelogue/domain/TravelogueDay.java | 2 + .../dto/response/TravelogueDayResponse.java | 8 ++ .../response/TravelogueLocationResponse.java | 8 ++ .../dto/response/TraveloguePlaceResponse.java | 11 +++ .../dto/response/TravelogueResponse.java | 10 +++ .../service/TravelogueFacadeService.java | 75 ++++--------------- 6 files changed, 52 insertions(+), 62 deletions(-) diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/domain/TravelogueDay.java b/backend/src/main/java/woowacourse/touroot/travelogue/domain/TravelogueDay.java index 2ba62d65..9d15e83a 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/domain/TravelogueDay.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/domain/TravelogueDay.java @@ -10,11 +10,13 @@ import jakarta.persistence.ManyToOne; import lombok.AccessLevel; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import woowacourse.touroot.entity.BaseEntity; @Getter +@EqualsAndHashCode(of = "id", callSuper = false) @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @Entity diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueDayResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueDayResponse.java index cf0501cf..bc81a312 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueDayResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueDayResponse.java @@ -3,6 +3,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; import lombok.Builder; +import woowacourse.touroot.travelogue.domain.TravelogueDay; @Builder public record TravelogueDayResponse( @@ -11,4 +12,11 @@ public record TravelogueDayResponse( @Schema(description = "여행기 장소 목록") List places ) { + + public static TravelogueDayResponse of(TravelogueDay day, List places) { + return TravelogueDayResponse.builder() + .id(day.getId()) + .places(places) + .build(); + } } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueLocationResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueLocationResponse.java index 0cb17521..e3a18728 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueLocationResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueLocationResponse.java @@ -2,6 +2,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; +import woowacourse.touroot.travelogue.domain.TraveloguePlace; @Builder public record TravelogueLocationResponse( @@ -10,4 +11,11 @@ public record TravelogueLocationResponse( @Schema(description = "여행기 장소 설명", example = "127.0867236") String lng ) { + + public static TravelogueLocationResponse from(TraveloguePlace place) { + return TravelogueLocationResponse.builder() + .lat(place.getLatitude()) + .lng(place.getLongitude()) + .build(); + } } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TraveloguePlaceResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TraveloguePlaceResponse.java index 299c2297..ef8f20eb 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TraveloguePlaceResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TraveloguePlaceResponse.java @@ -3,6 +3,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; import lombok.Builder; +import woowacourse.touroot.travelogue.domain.TraveloguePlace; @Builder public record TraveloguePlaceResponse( @@ -15,4 +16,14 @@ public record TraveloguePlaceResponse( TravelogueLocationResponse location, List photoUrls ) { + + public static TraveloguePlaceResponse of(TraveloguePlace place, List photoUrls) { + return TraveloguePlaceResponse.builder() + .id(place.getId()) + .name(place.getName()) + .description(place.getDescription()) + .location(TravelogueLocationResponse.from(place)) + .photoUrls(photoUrls) + .build(); + } } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueResponse.java b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueResponse.java index 6e39278e..cfb554a4 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueResponse.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/dto/response/TravelogueResponse.java @@ -5,6 +5,7 @@ import jakarta.validation.constraints.NotNull; import java.util.List; import lombok.Builder; +import woowacourse.touroot.travelogue.domain.Travelogue; @Builder public record TravelogueResponse( @@ -22,4 +23,13 @@ public record TravelogueResponse( @Valid List days ) { + + public static TravelogueResponse of(Travelogue travelogue, List days) { + return TravelogueResponse.builder() + .id(travelogue.getId()) + .title(travelogue.getTitle()) + .thumbnail(travelogue.getThumbnail()) + .days(days) + .build(); + } } diff --git a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java index 152ef2e8..3f261cbc 100644 --- a/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java +++ b/backend/src/main/java/woowacourse/touroot/travelogue/service/TravelogueFacadeService.java @@ -17,7 +17,6 @@ import woowacourse.touroot.travelogue.dto.request.TraveloguePlaceRequest; import woowacourse.touroot.travelogue.dto.request.TravelogueRequest; import woowacourse.touroot.travelogue.dto.response.TravelogueDayResponse; -import woowacourse.touroot.travelogue.dto.response.TravelogueLocationResponse; import woowacourse.touroot.travelogue.dto.response.TraveloguePlaceResponse; import woowacourse.touroot.travelogue.dto.response.TravelogueResponse; @@ -32,14 +31,8 @@ public class TravelogueFacadeService { public TravelogueResponse createTravelogue(TravelogueRequest request) { Travelogue travelogue = travelogueService.createTravelogue(request); - List dayRequests = request.days(); - - return TravelogueResponse.builder() - .id(travelogue.getId()) - .title(travelogue.getTitle()) - .thumbnail(travelogue.getThumbnail()) - .days(createDays(dayRequests, travelogue)) - .build(); + + return TravelogueResponse.of(travelogue, createDays(request.days(), travelogue)); } private List createDays(List requests, Travelogue travelogue) { @@ -47,10 +40,7 @@ private List createDays(List reques return days.keySet() .stream() - .map(travelogueDay -> TravelogueDayResponse.builder() - .id(travelogueDay.getId()) - .places(createPlaces(days.get(travelogueDay), travelogueDay)) - .build()) + .map(day -> TravelogueDayResponse.of(day, createPlaces(days.get(day), day))) .toList(); } @@ -59,13 +49,7 @@ private List createPlaces(List return places.keySet() .stream() - .map(traveloguePlace -> TraveloguePlaceResponse.builder() - .id(traveloguePlace.getId()) - .name(traveloguePlace.getName()) - .description(traveloguePlace.getDescription()) - .location(getTravelogueLocationResponse(traveloguePlace)) - .photoUrls(createPhotos(places.get(traveloguePlace), traveloguePlace)) - .build()) + .map(place -> TraveloguePlaceResponse.of(place, createPhotos(places.get(place), place))) .toList(); } @@ -80,16 +64,15 @@ private List createPhotos(List requests, Travelo public TravelogueResponse findTravelogueById(Long id) { Travelogue travelogue = travelogueService.getTravelogueById(id); - return getTravelogueResponse(travelogue); + return TravelogueResponse.of(travelogue, findDaysOfTravelogue(travelogue)); } - private TravelogueResponse getTravelogueResponse(final Travelogue travelogue) { - return TravelogueResponse.builder() - .id(travelogue.getId()) - .title(travelogue.getTitle()) - .thumbnail(travelogue.getThumbnail()) - .days(findDaysOfTravelogue(travelogue)) - .build(); + public Page findTravelogues(final Pageable pageable) { + Page travelogues = travelogueService.findAll(pageable); + + return new PageImpl<>(travelogues.stream() + .map(travelogue -> TravelogueResponse.of(travelogue, findDaysOfTravelogue(travelogue))) + .toList()); } private List findDaysOfTravelogue(Travelogue travelogue) { @@ -97,52 +80,20 @@ private List findDaysOfTravelogue(Travelogue travelogue) return travelogueDays.stream() .sorted(Comparator.comparing(TravelogueDay::getOrder)) - .map(this::getTravelogueDayResponse) + .map(day -> TravelogueDayResponse.of(day, findPlacesOfTravelogueDay(day))) .toList(); } - private TravelogueDayResponse getTravelogueDayResponse(TravelogueDay day) { - return TravelogueDayResponse.builder() - .id(day.getId()) - .places(findPlacesOfTravelogueDay(day)) - .build(); - } - private List findPlacesOfTravelogueDay(TravelogueDay travelogueDay) { List places = traveloguePlaceService.findTraveloguePlaceByDay(travelogueDay); return places.stream() .sorted(Comparator.comparing(TraveloguePlace::getOrder)) - .map(this::getTraveloguePlaceResponse) + .map(place -> TraveloguePlaceResponse.of(place, findPhotoUrlsOfTraveloguePlace(place))) .toList(); } - private TraveloguePlaceResponse getTraveloguePlaceResponse(TraveloguePlace place) { - return TraveloguePlaceResponse.builder() - .id(place.getId()) - .name(place.getName()) - .description(place.getDescription()) - .location(getTravelogueLocationResponse(place)) - .photoUrls(findPhotoUrlsOfTraveloguePlace(place)) - .build(); - } - - private static TravelogueLocationResponse getTravelogueLocationResponse(TraveloguePlace place) { - return TravelogueLocationResponse.builder() - .lat(place.getLatitude()) - .lng(place.getLongitude()) - .build(); - } - private List findPhotoUrlsOfTraveloguePlace(TraveloguePlace place) { return traveloguePhotoService.findPhotoUrlsByPlace(place); } - - public Page findTravelogues(final Pageable pageable) { - Page travelogues = travelogueService.findAll(pageable); - - return new PageImpl<>(travelogues.stream() - .map(this::getTravelogueResponse) - .toList()); - } }