From 9940342a3e4623e21418da0376b87afce0425e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Sat, 16 Nov 2024 22:48:41 +0900 Subject: [PATCH 01/10] =?UTF-8?q?refactor:=20=EC=9E=98=EB=AA=BB=EB=90=9C?= =?UTF-8?q?=20=EB=B3=80=EC=88=98=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/findy/findy_be/place/api/PlaceController.java | 6 +++--- .../findy_be/place/application/find/FindAllPagedPlaces.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/findy/findy_be/place/api/PlaceController.java b/src/main/java/org/findy/findy_be/place/api/PlaceController.java index 6474a56..b89ae0a 100644 --- a/src/main/java/org/findy/findy_be/place/api/PlaceController.java +++ b/src/main/java/org/findy/findy_be/place/api/PlaceController.java @@ -34,9 +34,9 @@ public void registerPlace(@LoginUser User user, @PathVariable("bookmarkId") Long registerPlace.invoke(bookmarkId, request, user.getUserId()); } - @GetMapping("/{bookId}") - public SliceResponse getPlaces(@LoginUser User user, @PathVariable("bookId") Long bookId, + @GetMapping("/{bookmarkId}") + public SliceResponse getPlaces(@LoginUser User user, @PathVariable("bookmarkId") Long bookmarkId, @ModelAttribute PagedRequest request) { - return findAllPagedPlaces.invoke(user.getUserId(), bookId, request.cursor(), request.size()); + return findAllPagedPlaces.invoke(user.getUserId(), bookmarkId, request.cursor(), request.size()); } } diff --git a/src/main/java/org/findy/findy_be/place/application/find/FindAllPagedPlaces.java b/src/main/java/org/findy/findy_be/place/application/find/FindAllPagedPlaces.java index 98d3b09..6ecee22 100644 --- a/src/main/java/org/findy/findy_be/place/application/find/FindAllPagedPlaces.java +++ b/src/main/java/org/findy/findy_be/place/application/find/FindAllPagedPlaces.java @@ -4,5 +4,5 @@ import org.findy.findy_be.place.dto.response.PlaceResponse; public interface FindAllPagedPlaces { - SliceResponse invoke(final String userId, final Long bookId, final Long cursor, final int size); + SliceResponse invoke(final String userId, final Long bookmarkId, final Long cursor, final int size); } From f63507af606eefb327c99030f73a1f91194354f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Sat, 16 Nov 2024 23:01:46 +0900 Subject: [PATCH 02/10] refactor: marker refactoring --- .../findy_be/marker/api/MarkerController.java | 42 +++++++++++++++++++ .../api/swagger/MarkerAPIPresentation.java} | 23 +++++----- .../find/FindAllPagedMarkers.java} | 4 +- .../find/FindAllPagedMarkersService.java} | 4 +- .../application/register/RegisterMarker.java | 7 ++++ .../register/RegisterMarkerService.java} | 8 ++-- .../RegisterSearchedMarkerRequest.java} | 4 +- .../findy_be/place/api/PlaceController.java | 42 ------------------- .../application/register/RegisterPlace.java | 7 ---- .../api/MarkerControllerTest.java} | 20 ++++----- .../find/FindAllPagedMarkersServiceTest.java} | 18 ++++---- .../register/RegisterMarkerServiceTest.java} | 18 ++++---- 12 files changed, 99 insertions(+), 98 deletions(-) create mode 100644 src/main/java/org/findy/findy_be/marker/api/MarkerController.java rename src/main/java/org/findy/findy_be/{place/api/swagger/PlaceAPIPresentation.java => marker/api/swagger/MarkerAPIPresentation.java} (70%) rename src/main/java/org/findy/findy_be/{place/application/find/FindAllPagedPlaces.java => marker/application/find/FindAllPagedMarkers.java} (73%) rename src/main/java/org/findy/findy_be/{place/application/find/FindAllPagedPlacesService.java => marker/application/find/FindAllPagedMarkersService.java} (90%) create mode 100644 src/main/java/org/findy/findy_be/marker/application/register/RegisterMarker.java rename src/main/java/org/findy/findy_be/{place/application/register/RegisterPlaceService.java => marker/application/register/RegisterMarkerService.java} (88%) rename src/main/java/org/findy/findy_be/{place/dto/request/RegisterSearchedPlaceRequest.java => marker/dto/request/RegisterSearchedMarkerRequest.java} (94%) delete mode 100644 src/main/java/org/findy/findy_be/place/api/PlaceController.java delete mode 100644 src/main/java/org/findy/findy_be/place/application/register/RegisterPlace.java rename src/test/java/org/findy/findy_be/{place/api/PlaceControllerTest.java => marker/api/MarkerControllerTest.java} (91%) rename src/test/java/org/findy/findy_be/{place/application/find/FindAllPagedPlacesServiceTest.java => marker/application/find/FindAllPagedMarkersServiceTest.java} (80%) rename src/test/java/org/findy/findy_be/{place/application/register/RegisterPlaceServiceTest.java => marker/application/register/RegisterMarkerServiceTest.java} (86%) diff --git a/src/main/java/org/findy/findy_be/marker/api/MarkerController.java b/src/main/java/org/findy/findy_be/marker/api/MarkerController.java new file mode 100644 index 0000000..500217d --- /dev/null +++ b/src/main/java/org/findy/findy_be/marker/api/MarkerController.java @@ -0,0 +1,42 @@ +package org.findy.findy_be.marker.api; + +import org.findy.findy_be.common.dto.pagination.request.PagedRequest; +import org.findy.findy_be.common.dto.pagination.response.SliceResponse; +import org.findy.findy_be.common.meta.LoginUser; +import org.findy.findy_be.marker.api.swagger.MarkerAPIPresentation; +import org.findy.findy_be.marker.application.find.FindAllPagedMarkers; +import org.findy.findy_be.marker.application.register.RegisterMarker; +import org.findy.findy_be.marker.dto.request.RegisterSearchedMarkerRequest; +import org.findy.findy_be.place.dto.response.PlaceResponse; +import org.findy.findy_be.user.domain.User; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +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 jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; + +@RestController +@RequestMapping("/api/markers") +@RequiredArgsConstructor +public class MarkerController implements MarkerAPIPresentation { + + private final RegisterMarker registerMarker; + private final FindAllPagedMarkers findAllPagedMarkers; + + @PostMapping("/{bookmarkId}") + public void registerMarker(@LoginUser User user, @PathVariable("bookmarkId") Long bookmarkId, + @Valid @RequestBody RegisterSearchedMarkerRequest request) { + registerMarker.invoke(bookmarkId, request, user.getUserId()); + } + + @GetMapping("/{bookmarkId}") + public SliceResponse getMarkers(@LoginUser User user, @PathVariable("bookmarkId") Long bookmarkId, + @ModelAttribute PagedRequest request) { + return findAllPagedMarkers.invoke(user.getUserId(), bookmarkId, request.cursor(), request.size()); + } +} diff --git a/src/main/java/org/findy/findy_be/place/api/swagger/PlaceAPIPresentation.java b/src/main/java/org/findy/findy_be/marker/api/swagger/MarkerAPIPresentation.java similarity index 70% rename from src/main/java/org/findy/findy_be/place/api/swagger/PlaceAPIPresentation.java rename to src/main/java/org/findy/findy_be/marker/api/swagger/MarkerAPIPresentation.java index 505ecc5..82f1238 100644 --- a/src/main/java/org/findy/findy_be/place/api/swagger/PlaceAPIPresentation.java +++ b/src/main/java/org/findy/findy_be/marker/api/swagger/MarkerAPIPresentation.java @@ -1,11 +1,11 @@ -package org.findy.findy_be.place.api.swagger; +package org.findy.findy_be.marker.api.swagger; import org.findy.findy_be.common.dto.pagination.request.PagedRequest; import org.findy.findy_be.common.dto.pagination.response.SliceResponse; import org.findy.findy_be.common.meta.CustomApiResponse; import org.findy.findy_be.common.meta.CustomApiResponses; import org.findy.findy_be.common.meta.LoginUser; -import org.findy.findy_be.place.dto.request.RegisterSearchedPlaceRequest; +import org.findy.findy_be.marker.dto.request.RegisterSearchedMarkerRequest; import org.findy.findy_be.place.dto.response.PlaceResponse; import org.findy.findy_be.user.domain.User; import org.springframework.web.bind.annotation.ModelAttribute; @@ -17,11 +17,12 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; -@Tag(name = "Place API", description = "장소 관련 API") -public interface PlaceAPIPresentation { +@Tag(name = "Marker API", description = "마커 관련 API") +public interface MarkerAPIPresentation { - @Operation(summary = "장소 등록", description = "새로운 장소를 등록하는 API", responses = { - @ApiResponse(responseCode = "200", description = "장소 등록 성공"), + @Operation(summary = "마커 등록", description = "새로운 마커" + + "를 등록하는 API", responses = { + @ApiResponse(responseCode = "200", description = "마커 등록 성공"), @ApiResponse(responseCode = "400", description = "유효하지 않은 입력 값") }) @CustomApiResponses({ @@ -29,16 +30,16 @@ public interface PlaceAPIPresentation { @CustomApiResponse(error = "EntityNotFoundException", status = 404, message = "해당 id : 1의 즐겨찾기가 존재하지 않습니다.", description = "장소를 저장할 즐겨찾기를 못 찾는 경우"), @CustomApiResponse(error = "InternalServerError", status = 500, message = "내부 서버 오류가 발생했습니다.", description = "내부 서버 오류") }) - void registerPlace(@LoginUser User user, @PathVariable Long bookmarkId, - @Valid @RequestBody RegisterSearchedPlaceRequest request); + void registerMarker(@LoginUser User user, @PathVariable Long bookmarkId, + @Valid @RequestBody RegisterSearchedMarkerRequest request); - @Operation(summary = "장소 목록 조회", description = "유저의 북마크 장소 목록을 조회하는 API", responses = { - @ApiResponse(responseCode = "200", description = "장소 목록 조회 성공") + @Operation(summary = "마커 목록 조회", description = "유저의 마커 목록을 조회하는 API", responses = { + @ApiResponse(responseCode = "200", description = "마커 조회 성공") }) @CustomApiResponses({ @CustomApiResponse(error = "IllegalArgumentException", status = 400, message = "잘못된 요청입니다.", description = "잘못된 쿼리 파라미터가 포함된 경우"), @CustomApiResponse(error = "InternalServerError", status = 500, message = "내부 서버 오류가 발생했습니다.", description = "서버 내부에서 예기치 않은 오류가 발생한 경우") }) - SliceResponse getPlaces(@LoginUser User user, @PathVariable("bookId") Long bookId, + SliceResponse getMarkers(@LoginUser User user, @PathVariable("bookmarkId") Long bookmarkId, @ModelAttribute PagedRequest request); } diff --git a/src/main/java/org/findy/findy_be/place/application/find/FindAllPagedPlaces.java b/src/main/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkers.java similarity index 73% rename from src/main/java/org/findy/findy_be/place/application/find/FindAllPagedPlaces.java rename to src/main/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkers.java index 6ecee22..3a13ae8 100644 --- a/src/main/java/org/findy/findy_be/place/application/find/FindAllPagedPlaces.java +++ b/src/main/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkers.java @@ -1,8 +1,8 @@ -package org.findy.findy_be.place.application.find; +package org.findy.findy_be.marker.application.find; import org.findy.findy_be.common.dto.pagination.response.SliceResponse; import org.findy.findy_be.place.dto.response.PlaceResponse; -public interface FindAllPagedPlaces { +public interface FindAllPagedMarkers { SliceResponse invoke(final String userId, final Long bookmarkId, final Long cursor, final int size); } diff --git a/src/main/java/org/findy/findy_be/place/application/find/FindAllPagedPlacesService.java b/src/main/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersService.java similarity index 90% rename from src/main/java/org/findy/findy_be/place/application/find/FindAllPagedPlacesService.java rename to src/main/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersService.java index 3aec60c..4196c52 100644 --- a/src/main/java/org/findy/findy_be/place/application/find/FindAllPagedPlacesService.java +++ b/src/main/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersService.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.place.application.find; +package org.findy.findy_be.marker.application.find; import java.util.List; @@ -15,7 +15,7 @@ @Service @RequiredArgsConstructor @Transactional(readOnly = true) -public class FindAllPagedPlacesService implements FindAllPagedPlaces { +public class FindAllPagedMarkersService implements FindAllPagedMarkers { private final PlaceRepository placeRepository; diff --git a/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarker.java b/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarker.java new file mode 100644 index 0000000..9dacb90 --- /dev/null +++ b/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarker.java @@ -0,0 +1,7 @@ +package org.findy.findy_be.marker.application.register; + +import org.findy.findy_be.marker.dto.request.RegisterSearchedMarkerRequest; + +public interface RegisterMarker { + void invoke(final Long bookmarkId, final RegisterSearchedMarkerRequest request, final String userId); +} diff --git a/src/main/java/org/findy/findy_be/place/application/register/RegisterPlaceService.java b/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarkerService.java similarity index 88% rename from src/main/java/org/findy/findy_be/place/application/register/RegisterPlaceService.java rename to src/main/java/org/findy/findy_be/marker/application/register/RegisterMarkerService.java index f9ed3dd..3b063f9 100644 --- a/src/main/java/org/findy/findy_be/place/application/register/RegisterPlaceService.java +++ b/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarkerService.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.place.application.register; +package org.findy.findy_be.marker.application.register; import static org.findy.findy_be.common.exception.ErrorCode.*; @@ -6,9 +6,9 @@ import org.findy.findy_be.bookmark.domain.BookmarkType; import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.marker.application.create.CreateMarker; +import org.findy.findy_be.marker.dto.request.RegisterSearchedMarkerRequest; import org.findy.findy_be.place.application.find.FindPlace; import org.findy.findy_be.place.domain.Place; -import org.findy.findy_be.place.dto.request.RegisterSearchedPlaceRequest; import org.findy.findy_be.place.repository.PlaceRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,7 +21,7 @@ @Service @Transactional @RequiredArgsConstructor -public class RegisterPlaceService implements RegisterPlace { +public class RegisterMarkerService implements RegisterMarker { private final FindPlace findPlace; private final BookmarkRepository bookmarkRepository; @@ -29,7 +29,7 @@ public class RegisterPlaceService implements RegisterPlace { private final PlaceRepository placeRepository; @Override - public void invoke(final Long bookmarkId, final RegisterSearchedPlaceRequest request, final String userId) { + public void invoke(final Long bookmarkId, final RegisterSearchedMarkerRequest request, final String userId) { Bookmark bookmark = bookmarkRepository.findByIdAndUserUserId(bookmarkId, userId) .orElseThrow( () -> new EntityNotFoundException(String.format(NOT_FOUND_BOOKMARK_BY_ID.getMessage(), bookmarkId))); diff --git a/src/main/java/org/findy/findy_be/place/dto/request/RegisterSearchedPlaceRequest.java b/src/main/java/org/findy/findy_be/marker/dto/request/RegisterSearchedMarkerRequest.java similarity index 94% rename from src/main/java/org/findy/findy_be/place/dto/request/RegisterSearchedPlaceRequest.java rename to src/main/java/org/findy/findy_be/marker/dto/request/RegisterSearchedMarkerRequest.java index 7a3811f..e70abe2 100644 --- a/src/main/java/org/findy/findy_be/place/dto/request/RegisterSearchedPlaceRequest.java +++ b/src/main/java/org/findy/findy_be/marker/dto/request/RegisterSearchedMarkerRequest.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.place.dto.request; +package org.findy.findy_be.marker.dto.request; import static org.findy.findy_be.place.utils.CategoryResolver.*; @@ -9,7 +9,7 @@ import jakarta.validation.constraints.NotNull; @Schema(description = "장소 DTO") -public record RegisterSearchedPlaceRequest( +public record RegisterSearchedMarkerRequest( @NotNull(message = "장소명은 비어있을 수 없습니다.") @Schema(description = "장소명", example = "동대문엽기떡볶이 종각점") diff --git a/src/main/java/org/findy/findy_be/place/api/PlaceController.java b/src/main/java/org/findy/findy_be/place/api/PlaceController.java deleted file mode 100644 index b89ae0a..0000000 --- a/src/main/java/org/findy/findy_be/place/api/PlaceController.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.findy.findy_be.place.api; - -import org.findy.findy_be.common.dto.pagination.request.PagedRequest; -import org.findy.findy_be.common.dto.pagination.response.SliceResponse; -import org.findy.findy_be.common.meta.LoginUser; -import org.findy.findy_be.place.api.swagger.PlaceAPIPresentation; -import org.findy.findy_be.place.application.find.FindAllPagedPlaces; -import org.findy.findy_be.place.application.register.RegisterPlace; -import org.findy.findy_be.place.dto.request.RegisterSearchedPlaceRequest; -import org.findy.findy_be.place.dto.response.PlaceResponse; -import org.findy.findy_be.user.domain.User; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -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 jakarta.validation.Valid; -import lombok.RequiredArgsConstructor; - -@RestController -@RequestMapping("/api/places") -@RequiredArgsConstructor -public class PlaceController implements PlaceAPIPresentation { - - private final RegisterPlace registerPlace; - private final FindAllPagedPlaces findAllPagedPlaces; - - @PostMapping("/{bookmarkId}") - public void registerPlace(@LoginUser User user, @PathVariable("bookmarkId") Long bookmarkId, - @Valid @RequestBody RegisterSearchedPlaceRequest request) { - registerPlace.invoke(bookmarkId, request, user.getUserId()); - } - - @GetMapping("/{bookmarkId}") - public SliceResponse getPlaces(@LoginUser User user, @PathVariable("bookmarkId") Long bookmarkId, - @ModelAttribute PagedRequest request) { - return findAllPagedPlaces.invoke(user.getUserId(), bookmarkId, request.cursor(), request.size()); - } -} diff --git a/src/main/java/org/findy/findy_be/place/application/register/RegisterPlace.java b/src/main/java/org/findy/findy_be/place/application/register/RegisterPlace.java deleted file mode 100644 index 2347c30..0000000 --- a/src/main/java/org/findy/findy_be/place/application/register/RegisterPlace.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.findy.findy_be.place.application.register; - -import org.findy.findy_be.place.dto.request.RegisterSearchedPlaceRequest; - -public interface RegisterPlace { - void invoke(final Long bookmarkId, final RegisterSearchedPlaceRequest request, final String userId); -} diff --git a/src/test/java/org/findy/findy_be/place/api/PlaceControllerTest.java b/src/test/java/org/findy/findy_be/marker/api/MarkerControllerTest.java similarity index 91% rename from src/test/java/org/findy/findy_be/place/api/PlaceControllerTest.java rename to src/test/java/org/findy/findy_be/marker/api/MarkerControllerTest.java index af64c9e..fc90eda 100644 --- a/src/test/java/org/findy/findy_be/place/api/PlaceControllerTest.java +++ b/src/test/java/org/findy/findy_be/marker/api/MarkerControllerTest.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.place.api; +package org.findy.findy_be.marker.api; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; @@ -16,11 +16,11 @@ import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.common.IntegrationTest; import org.findy.findy_be.common.dto.pagination.request.PagedRequest; +import org.findy.findy_be.marker.application.register.RegisterMarkerService; import org.findy.findy_be.marker.domain.Marker; +import org.findy.findy_be.marker.dto.request.RegisterSearchedMarkerRequest; import org.findy.findy_be.marker.repository.MarkerRepository; -import org.findy.findy_be.place.application.register.RegisterPlaceService; import org.findy.findy_be.place.domain.Place; -import org.findy.findy_be.place.dto.request.RegisterSearchedPlaceRequest; import org.findy.findy_be.place.repository.PlaceRepository; import org.findy.findy_be.user.domain.RoleType; import org.findy.findy_be.user.domain.User; @@ -36,10 +36,10 @@ import org.springframework.test.web.servlet.ResultActions; @WithMockUser(roles = "USER") -class PlaceControllerTest extends IntegrationTest { +class MarkerControllerTest extends IntegrationTest { @Autowired - private RegisterPlaceService registerPlace; + private RegisterMarkerService registerMarker; @Autowired private UserRepository userRepository; @@ -85,7 +85,7 @@ void setUp() { void 장소_등록_API_성공() throws Exception { // given Long bookmarkId = testBookmark.getId(); - RegisterSearchedPlaceRequest request = new RegisterSearchedPlaceRequest( + RegisterSearchedMarkerRequest request = new RegisterSearchedMarkerRequest( "동대문엽기떡볶이 종각점", "음식점>분식", "설명", @@ -109,7 +109,7 @@ void setUp() { void 장소_등록_API_검증_실패() throws Exception { // given Long bookmarkId = testBookmark.getId(); - RegisterSearchedPlaceRequest invalidRequest = new RegisterSearchedPlaceRequest( + RegisterSearchedMarkerRequest invalidRequest = new RegisterSearchedMarkerRequest( null, "음식점>분식", "설명", @@ -134,7 +134,7 @@ void setUp() { void 장소_등록_API_예외_존재하지_않는_즐겨찾기_ID() throws Exception { // given Long invalidBookmarkId = 999L; - RegisterSearchedPlaceRequest request = new RegisterSearchedPlaceRequest( + RegisterSearchedMarkerRequest request = new RegisterSearchedMarkerRequest( "동대문엽기떡볶이 종각점", "음식점>분식", "설명", @@ -207,7 +207,7 @@ private ResultActions GetBookmarks(final Long bookmarkId, final PagedRequest pag } private ResultActions PostSearchedPlace(final Long bookmarkId, - final RegisterSearchedPlaceRequest request) throws + final RegisterSearchedMarkerRequest request) throws Exception { return mvc.perform(post("/api/places/{bookmarkId}", bookmarkId) .contentType(MediaType.APPLICATION_JSON) @@ -217,7 +217,7 @@ private ResultActions PostSearchedPlace(final Long bookmarkId, private void initPlacesForBookmark(Bookmark bookmark, int count) { List places = IntStream.range(1, count + 1) - .mapToObj(i -> new RegisterSearchedPlaceRequest( + .mapToObj(i -> new RegisterSearchedMarkerRequest( "Test Place " + i, "음식점>분식", "Description " + i, diff --git a/src/test/java/org/findy/findy_be/place/application/find/FindAllPagedPlacesServiceTest.java b/src/test/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersServiceTest.java similarity index 80% rename from src/test/java/org/findy/findy_be/place/application/find/FindAllPagedPlacesServiceTest.java rename to src/test/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersServiceTest.java index 64180d5..be746da 100644 --- a/src/test/java/org/findy/findy_be/place/application/find/FindAllPagedPlacesServiceTest.java +++ b/src/test/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersServiceTest.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.place.application.find; +package org.findy.findy_be.marker.application.find; import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; @@ -28,13 +28,13 @@ import org.springframework.data.domain.Slice; import org.springframework.data.domain.SliceImpl; -class FindAllPagedPlacesServiceTest extends MockTest { +class FindAllPagedMarkersServiceTest extends MockTest { @Mock private PlaceRepository placeRepository; @InjectMocks - private FindAllPagedPlacesService findAllPagedPlacesService; + private FindAllPagedMarkersService findAllPagedMarkersService; private User testUser; private List places; @@ -60,9 +60,9 @@ public void setUp() throws Exception { .collect(Collectors.toList()); } - @DisplayName("[성공 case1(다음페이지 있음)] 유저_북마크의 장소 조회 성공") + @DisplayName("[성공 case1(다음페이지 있음)] 유저 마커 조회 성공") @Test - void 유저_북마크의_장소_조회_case1() { + void 유저_마커_조회_case1() { // given Long bookmarkId = 1L; Pageable pageable = PageRequest.of(0, 3); @@ -74,7 +74,7 @@ public void setUp() throws Exception { .thenReturn(placeSlice); // when - SliceResponse response = findAllPagedPlacesService.invoke(testUser.getUserId(), 1L, 0L, 3); + SliceResponse response = findAllPagedMarkersService.invoke(testUser.getUserId(), 1L, 0L, 3); // then assertThat(response.data().size()).isEqualTo(3); @@ -82,9 +82,9 @@ public void setUp() throws Exception { assertThat(response.nextCursor()).isEqualTo(places.get(2).getId()); } - @DisplayName("[성공 case2(다음페이지 없음)] 유저_북마크의 장소 조회 성공") + @DisplayName("[성공 case2(다음페이지 없음)] 유저 마커 조회 성공") @Test - void 유저_북마크의_장소_조회_성공_case2() { + void 유저_마커_조회_성공_case2() { // given Long bookmarkId = 1L; Pageable pageable = PageRequest.of(0, 3); @@ -96,7 +96,7 @@ public void setUp() throws Exception { .thenReturn(placeSlice); // when - SliceResponse response = findAllPagedPlacesService.invoke(testUser.getUserId(), 1L, 0L, 3); + SliceResponse response = findAllPagedMarkersService.invoke(testUser.getUserId(), 1L, 0L, 3); // then assertThat(response.data().size()).isEqualTo(3); diff --git a/src/test/java/org/findy/findy_be/place/application/register/RegisterPlaceServiceTest.java b/src/test/java/org/findy/findy_be/marker/application/register/RegisterMarkerServiceTest.java similarity index 86% rename from src/test/java/org/findy/findy_be/place/application/register/RegisterPlaceServiceTest.java rename to src/test/java/org/findy/findy_be/marker/application/register/RegisterMarkerServiceTest.java index dc182a5..b53f374 100644 --- a/src/test/java/org/findy/findy_be/place/application/register/RegisterPlaceServiceTest.java +++ b/src/test/java/org/findy/findy_be/marker/application/register/RegisterMarkerServiceTest.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.place.application.register; +package org.findy.findy_be.marker.application.register; import static org.assertj.core.api.Assertions.*; import static org.findy.findy_be.common.exception.ErrorCode.*; @@ -14,9 +14,9 @@ import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.common.MockTest; import org.findy.findy_be.marker.application.create.CreateMarker; +import org.findy.findy_be.marker.dto.request.RegisterSearchedMarkerRequest; import org.findy.findy_be.place.application.find.FindPlace; import org.findy.findy_be.place.domain.Place; -import org.findy.findy_be.place.dto.request.RegisterSearchedPlaceRequest; import org.findy.findy_be.place.repository.PlaceRepository; import org.findy.findy_be.user.domain.RoleType; import org.findy.findy_be.user.domain.User; @@ -27,7 +27,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -class RegisterPlaceServiceTest extends MockTest { +class RegisterMarkerServiceTest extends MockTest { @Mock private FindPlace findPlace; @@ -42,9 +42,9 @@ class RegisterPlaceServiceTest extends MockTest { private BookmarkRepository bookmarkRepository; @InjectMocks - private RegisterPlaceService registerPlaceService; + private RegisterMarkerService registerMarkerService; - private RegisterSearchedPlaceRequest placeRequest; + private RegisterSearchedMarkerRequest placeRequest; private User user; private Bookmark bookmark; private Place place; @@ -63,7 +63,7 @@ void setUp() { LocalDateTime.now(), LocalDateTime.now() ); - placeRequest = new RegisterSearchedPlaceRequest( + placeRequest = new RegisterSearchedMarkerRequest( "동대문엽기떡볶이 종각점", "음식점>분식", "설명", @@ -90,7 +90,7 @@ void setUp() { when(placeRepository.save(any(Place.class))).thenReturn(place); // when - registerPlaceService.invoke(bookmarkId, placeRequest, user.getUserId()); + registerMarkerService.invoke(bookmarkId, placeRequest, user.getUserId()); // then verify(placeRepository, times(1)).save(any(Place.class)); @@ -106,7 +106,7 @@ void setUp() { when(findPlace.invoke(placeRequest.title(), placeRequest.roadAddress())).thenReturn(Optional.of(place)); // when - registerPlaceService.invoke(bookmarkId, placeRequest, user.getUserId()); + registerMarkerService.invoke(bookmarkId, placeRequest, user.getUserId()); // then verify(placeRepository, never()).save(any(Place.class)); @@ -123,7 +123,7 @@ void setUp() { when(bookmark.getBookmarkType()).thenReturn(BookmarkType.YOUTUBE); // when & then - assertThatThrownBy(() -> registerPlaceService.invoke(bookmarkId, placeRequest, user.getUserId())) + assertThatThrownBy(() -> registerMarkerService.invoke(bookmarkId, placeRequest, user.getUserId())) .isInstanceOf(IllegalArgumentException.class) .hasMessage(BAD_REQUEST_YOUTUBE_BOOKMARK_REGISTER_ERROR.getMessage()); } From a54dedd953e3aab34c32a436bcde5a3bdf7a01e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Sun, 17 Nov 2024 00:42:12 +0900 Subject: [PATCH 03/10] refactor: marker refactoring --- .../bookmark/api/BookmarkController.java | 5 ++- .../api/swagger/BookmarkAPIPresentation.java | 4 +- .../RegisterYoutubeBookmarkService.java | 16 ++++---- ...va => RegisterYoutubeBookmarkRequest.java} | 6 +-- .../application/create/BatchCreateMarker.java | 2 +- .../application/create/CreateMarker.java | 2 +- .../create/CreateMarkerService.java | 4 +- .../application}/domain/MajorCategory.java | 2 +- .../application}/domain/MiddleCategory.java | 2 +- .../application}/domain/Place.java | 10 ++--- .../application}/domain/vo/Category.java | 6 +-- .../application}/domain/vo/Coordinate.java | 2 +- .../register/BatchRegisterMarker.java | 10 +++++ .../register/BatchRegisterMarkerService.java} | 16 ++++---- .../register/RegisterMarkerService.java | 2 +- .../findy/findy_be/marker/domain/Marker.java | 14 ++++++- .../dto/request/CategoryRequest.java | 6 +-- .../dto/request/RegisterMarkerRequest.java} | 9 ++-- .../RegisterSearchedMarkerRequest.java | 4 +- .../marker/repository/MarkerRepository.java | 2 +- .../place/application/find/FindPlace.java | 2 +- .../application/find/FindPlaceService.java | 2 +- .../register/BatchRegisterPlace.java | 10 ----- .../place/dto/response/PlaceResponse.java | 4 +- .../place/repository/PlaceRepository.java | 2 +- .../repository/PlaceRepositoryCustom.java | 2 +- .../repository/PlaceRepositoryCustomImpl.java | 2 +- .../place/utils/CategoryResolver.java | 4 +- .../bookmark/api/BookmarkControllerTest.java | 20 ++++----- .../RegisterYoutubeBookmarkServiceTest.java | 22 +++++----- .../BulkInsertRepositoryImplTest.java | 12 +++--- .../marker/api/MarkerControllerTest.java | 4 +- .../create/BatchCreateMarkerServiceTest.java | 2 +- .../create/CreateMarkerServiceTest.java | 6 +-- .../find/FindAllPagedMarkersServiceTest.java | 12 +++--- .../BatchRegisterMarkerServiceTest.java} | 41 +++++++++---------- .../register/RegisterMarkerServiceTest.java | 2 +- .../repository/MarkerRepositoryTest.java | 14 +++---- .../find/FindPlaceServiceTest.java | 14 +++---- .../PlaceRepositoryCustomImplTest.java | 14 +++---- .../place/repository/PlaceRepositoryTest.java | 14 +++---- .../place/utils/CategoryResolverTest.java | 6 +-- 42 files changed, 172 insertions(+), 163 deletions(-) rename src/main/java/org/findy/findy_be/bookmark/dto/request/{YoutubeBookmarkRequest.java => RegisterYoutubeBookmarkRequest.java} (88%) rename src/main/java/org/findy/findy_be/{place => marker/application}/domain/MajorCategory.java (90%) rename src/main/java/org/findy/findy_be/{place => marker/application}/domain/MiddleCategory.java (99%) rename src/main/java/org/findy/findy_be/{place => marker/application}/domain/Place.java (84%) rename src/main/java/org/findy/findy_be/{place => marker/application}/domain/vo/Category.java (78%) rename src/main/java/org/findy/findy_be/{place => marker/application}/domain/vo/Coordinate.java (93%) create mode 100644 src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarker.java rename src/main/java/org/findy/findy_be/{place/application/register/BatchRegisterPlaceService.java => marker/application/register/BatchRegisterMarkerService.java} (80%) rename src/main/java/org/findy/findy_be/{place => marker}/dto/request/CategoryRequest.java (67%) rename src/main/java/org/findy/findy_be/{place/dto/request/RegisterPlaceRequest.java => marker/dto/request/RegisterMarkerRequest.java} (85%) delete mode 100644 src/main/java/org/findy/findy_be/place/application/register/BatchRegisterPlace.java rename src/test/java/org/findy/findy_be/{place/application/register/BatchRegisterPlaceServiceTest.java => marker/application/register/BatchRegisterMarkerServiceTest.java} (69%) diff --git a/src/main/java/org/findy/findy_be/bookmark/api/BookmarkController.java b/src/main/java/org/findy/findy_be/bookmark/api/BookmarkController.java index eaab5af..b5d2157 100644 --- a/src/main/java/org/findy/findy_be/bookmark/api/BookmarkController.java +++ b/src/main/java/org/findy/findy_be/bookmark/api/BookmarkController.java @@ -7,8 +7,8 @@ import org.findy.findy_be.bookmark.application.register.RegisterYoutubeBookmark; import org.findy.findy_be.bookmark.application.update.UpdateBookmark; import org.findy.findy_be.bookmark.dto.request.CreateCustomBookmarkRequest; +import org.findy.findy_be.bookmark.dto.request.RegisterYoutubeBookmarkRequest; import org.findy.findy_be.bookmark.dto.request.UpdateBookmarkRequest; -import org.findy.findy_be.bookmark.dto.request.YoutubeBookmarkRequest; import org.findy.findy_be.bookmark.dto.response.BookmarkResponse; import org.findy.findy_be.common.dto.pagination.request.PagedRequest; import org.findy.findy_be.common.dto.pagination.response.SliceResponse; @@ -39,7 +39,8 @@ public class BookmarkController implements BookmarkAPIPresentation { private final UpdateBookmark updateBookmark; @PostMapping("/youtube") - public void registerYoutubeBookmark(@LoginUser User user, @Valid @RequestBody YoutubeBookmarkRequest request) { + public void registerYoutubeBookmark(@LoginUser User user, + @Valid @RequestBody RegisterYoutubeBookmarkRequest request) { registerYoutubeBookmark.invoke(user, request); } diff --git a/src/main/java/org/findy/findy_be/bookmark/api/swagger/BookmarkAPIPresentation.java b/src/main/java/org/findy/findy_be/bookmark/api/swagger/BookmarkAPIPresentation.java index 66a2c82..213552b 100644 --- a/src/main/java/org/findy/findy_be/bookmark/api/swagger/BookmarkAPIPresentation.java +++ b/src/main/java/org/findy/findy_be/bookmark/api/swagger/BookmarkAPIPresentation.java @@ -1,8 +1,8 @@ package org.findy.findy_be.bookmark.api.swagger; import org.findy.findy_be.bookmark.dto.request.CreateCustomBookmarkRequest; +import org.findy.findy_be.bookmark.dto.request.RegisterYoutubeBookmarkRequest; import org.findy.findy_be.bookmark.dto.request.UpdateBookmarkRequest; -import org.findy.findy_be.bookmark.dto.request.YoutubeBookmarkRequest; import org.findy.findy_be.bookmark.dto.response.BookmarkResponse; import org.findy.findy_be.common.dto.pagination.request.PagedRequest; import org.findy.findy_be.common.dto.pagination.response.SliceResponse; @@ -31,7 +31,7 @@ public interface BookmarkAPIPresentation { @CustomApiResponse(error = "EntityNotFoundException", status = 404, message = "해당 id : {id}의 즐겨찾기가 존재하지 않습니다.", description = "존재하지 않는 즐겨찾기에 접근할 경우"), @CustomApiResponse(error = "InternalServerError", status = 500, message = "내부 서버 오류가 발생했습니다.", description = "서버 내부에서 예기치 않은 오류가 발생한 경우") }) - void registerYoutubeBookmark(@LoginUser User user, @Valid @RequestBody YoutubeBookmarkRequest request); + void registerYoutubeBookmark(@LoginUser User user, @Valid @RequestBody RegisterYoutubeBookmarkRequest request); @Operation(summary = "커스텀 북마크 등록", description = "유저가 커스텀 북마크를 등록하는 API", responses = { @ApiResponse(responseCode = "200", description = "커스텀 북마크 등록 성공"), diff --git a/src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkService.java b/src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkService.java index 8025849..317ea28 100644 --- a/src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkService.java +++ b/src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkService.java @@ -5,11 +5,11 @@ import java.util.List; import org.findy.findy_be.bookmark.domain.Bookmark; -import org.findy.findy_be.bookmark.dto.request.YoutubeBookmarkRequest; +import org.findy.findy_be.bookmark.dto.request.RegisterYoutubeBookmarkRequest; import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.common.exception.custom.ForbiddenAccessException; -import org.findy.findy_be.place.application.register.BatchRegisterPlace; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.application.register.BatchRegisterMarker; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import org.findy.findy_be.user.domain.User; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -24,22 +24,22 @@ public class RegisterYoutubeBookmarkService implements RegisterYoutubeBookmark { private final BookmarkRepository bookmarkRepository; - private final BatchRegisterPlace batchRegisterPlace; + private final BatchRegisterMarker batchRegisterMarker; @Override - public void invoke(final User user, final YoutubeBookmarkRequest request) { - List placeRequests = request.places(); + public void invoke(final User user, final RegisterYoutubeBookmarkRequest request) { + List placeRequests = request.places(); bookmarkRepository.findByUserAndYoutuberId(user, request.youtuberId()).ifPresentOrElse( existingBookmark -> { existingBookmark.updateName(request.youtuberName()); validateBookmarkOwner(user, existingBookmark.getUser()); - batchRegisterPlace.invoke(existingBookmark, placeRequests); + batchRegisterMarker.invoke(existingBookmark, placeRequests); }, () -> { log.info("새로운 북마크에 저장합니다."); Bookmark bookmark = request.toEntity(user); bookmarkRepository.save(bookmark); - batchRegisterPlace.invoke(bookmark, placeRequests); + batchRegisterMarker.invoke(bookmark, placeRequests); } ); } diff --git a/src/main/java/org/findy/findy_be/bookmark/dto/request/YoutubeBookmarkRequest.java b/src/main/java/org/findy/findy_be/bookmark/dto/request/RegisterYoutubeBookmarkRequest.java similarity index 88% rename from src/main/java/org/findy/findy_be/bookmark/dto/request/YoutubeBookmarkRequest.java rename to src/main/java/org/findy/findy_be/bookmark/dto/request/RegisterYoutubeBookmarkRequest.java index 653fcee..4bb6ce9 100644 --- a/src/main/java/org/findy/findy_be/bookmark/dto/request/YoutubeBookmarkRequest.java +++ b/src/main/java/org/findy/findy_be/bookmark/dto/request/RegisterYoutubeBookmarkRequest.java @@ -4,14 +4,14 @@ import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.common.validation.ValidYoutuberId; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import org.findy.findy_be.user.domain.User; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; @Schema(description = "유튜브 즐겨찾기 DTO") -public record YoutubeBookmarkRequest( +public record RegisterYoutubeBookmarkRequest( @ValidYoutuberId(message = "유튜버 ID는 @으로 시작해야합니다.") @Schema(description = "유튜버 ID", example = "@iammingki") @@ -27,7 +27,7 @@ public record YoutubeBookmarkRequest( @Schema(description = "유튜브 링크", example = "https://www.youtube.com/watch?v=hE2wMo5Coco") String youtubeLink, - List places + List places ) { public Bookmark toEntity(User user) { return Bookmark.createYoutubeType(youtuberName, youtuberId, youtuberProfile, youtubeLink, user); diff --git a/src/main/java/org/findy/findy_be/marker/application/create/BatchCreateMarker.java b/src/main/java/org/findy/findy_be/marker/application/create/BatchCreateMarker.java index 65e49aa..7bc5d99 100644 --- a/src/main/java/org/findy/findy_be/marker/application/create/BatchCreateMarker.java +++ b/src/main/java/org/findy/findy_be/marker/application/create/BatchCreateMarker.java @@ -3,7 +3,7 @@ import java.util.List; import org.findy.findy_be.bookmark.domain.Bookmark; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; public interface BatchCreateMarker { void invoke(final Bookmark bookmark, final List places); diff --git a/src/main/java/org/findy/findy_be/marker/application/create/CreateMarker.java b/src/main/java/org/findy/findy_be/marker/application/create/CreateMarker.java index df0b475..6b22374 100644 --- a/src/main/java/org/findy/findy_be/marker/application/create/CreateMarker.java +++ b/src/main/java/org/findy/findy_be/marker/application/create/CreateMarker.java @@ -1,7 +1,7 @@ package org.findy.findy_be.marker.application.create; import org.findy.findy_be.bookmark.domain.Bookmark; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; public interface CreateMarker { void invoke(final Bookmark bookmark, final Place place); diff --git a/src/main/java/org/findy/findy_be/marker/application/create/CreateMarkerService.java b/src/main/java/org/findy/findy_be/marker/application/create/CreateMarkerService.java index 9afb240..ec354ab 100644 --- a/src/main/java/org/findy/findy_be/marker/application/create/CreateMarkerService.java +++ b/src/main/java/org/findy/findy_be/marker/application/create/CreateMarkerService.java @@ -5,7 +5,7 @@ import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.marker.domain.Marker; import org.findy.findy_be.marker.repository.MarkerRepository; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,7 +22,7 @@ public class CreateMarkerService implements CreateMarker { public void invoke(final Bookmark bookmark, final Place place) { Optional existingMarker = markerRepository.findByBookmarkAndPlace(bookmark, place); if (existingMarker.isEmpty()) { - Marker marker = Marker.create(bookmark, place); + Marker marker = Marker.createForCustomBookmark(bookmark, place); markerRepository.save(marker); marker.changeBookmark(bookmark); bookmark.incrementMarkersCount(1); diff --git a/src/main/java/org/findy/findy_be/place/domain/MajorCategory.java b/src/main/java/org/findy/findy_be/marker/application/domain/MajorCategory.java similarity index 90% rename from src/main/java/org/findy/findy_be/place/domain/MajorCategory.java rename to src/main/java/org/findy/findy_be/marker/application/domain/MajorCategory.java index d8d1589..13d6fb0 100644 --- a/src/main/java/org/findy/findy_be/place/domain/MajorCategory.java +++ b/src/main/java/org/findy/findy_be/marker/application/domain/MajorCategory.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.place.domain; +package org.findy.findy_be.marker.application.domain; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; diff --git a/src/main/java/org/findy/findy_be/place/domain/MiddleCategory.java b/src/main/java/org/findy/findy_be/marker/application/domain/MiddleCategory.java similarity index 99% rename from src/main/java/org/findy/findy_be/place/domain/MiddleCategory.java rename to src/main/java/org/findy/findy_be/marker/application/domain/MiddleCategory.java index 01021ee..a044ba7 100644 --- a/src/main/java/org/findy/findy_be/place/domain/MiddleCategory.java +++ b/src/main/java/org/findy/findy_be/marker/application/domain/MiddleCategory.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.place.domain; +package org.findy.findy_be.marker.application.domain; import java.util.Arrays; import java.util.Optional; diff --git a/src/main/java/org/findy/findy_be/place/domain/Place.java b/src/main/java/org/findy/findy_be/marker/application/domain/Place.java similarity index 84% rename from src/main/java/org/findy/findy_be/place/domain/Place.java rename to src/main/java/org/findy/findy_be/marker/application/domain/Place.java index 0f26b4e..656b1d4 100644 --- a/src/main/java/org/findy/findy_be/place/domain/Place.java +++ b/src/main/java/org/findy/findy_be/marker/application/domain/Place.java @@ -1,9 +1,9 @@ -package org.findy.findy_be.place.domain; +package org.findy.findy_be.marker.application.domain; import org.findy.findy_be.common.entity.BaseTimeEntity; -import org.findy.findy_be.place.domain.vo.Category; -import org.findy.findy_be.place.domain.vo.Coordinate; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.application.domain.vo.Category; +import org.findy.findy_be.marker.application.domain.vo.Coordinate; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import jakarta.persistence.Column; import jakarta.persistence.Embedded; @@ -54,7 +54,7 @@ public class Place extends BaseTimeEntity { @Embedded private Category category; - public static Place create(final RegisterPlaceRequest request) { + public static Place create(final RegisterMarkerRequest request) { Coordinate coordinate = Coordinate.of(request.mapX(), request.mapY()); Category category = Category.of(request.category().majorCategory(), request.category().middleCategory()); return Place.builder() diff --git a/src/main/java/org/findy/findy_be/place/domain/vo/Category.java b/src/main/java/org/findy/findy_be/marker/application/domain/vo/Category.java similarity index 78% rename from src/main/java/org/findy/findy_be/place/domain/vo/Category.java rename to src/main/java/org/findy/findy_be/marker/application/domain/vo/Category.java index 5a30bc9..86a61aa 100644 --- a/src/main/java/org/findy/findy_be/place/domain/vo/Category.java +++ b/src/main/java/org/findy/findy_be/marker/application/domain/vo/Category.java @@ -1,7 +1,7 @@ -package org.findy.findy_be.place.domain.vo; +package org.findy.findy_be.marker.application.domain.vo; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.MiddleCategory; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.MiddleCategory; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; diff --git a/src/main/java/org/findy/findy_be/place/domain/vo/Coordinate.java b/src/main/java/org/findy/findy_be/marker/application/domain/vo/Coordinate.java similarity index 93% rename from src/main/java/org/findy/findy_be/place/domain/vo/Coordinate.java rename to src/main/java/org/findy/findy_be/marker/application/domain/vo/Coordinate.java index 479233c..a96df21 100644 --- a/src/main/java/org/findy/findy_be/place/domain/vo/Coordinate.java +++ b/src/main/java/org/findy/findy_be/marker/application/domain/vo/Coordinate.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.place.domain.vo; +package org.findy.findy_be.marker.application.domain.vo; import java.util.Objects; diff --git a/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarker.java b/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarker.java new file mode 100644 index 0000000..28a64d3 --- /dev/null +++ b/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarker.java @@ -0,0 +1,10 @@ +package org.findy.findy_be.marker.application.register; + +import java.util.List; + +import org.findy.findy_be.bookmark.domain.Bookmark; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; + +public interface BatchRegisterMarker { + void invoke(final Bookmark bookmark, final List requests); +} diff --git a/src/main/java/org/findy/findy_be/place/application/register/BatchRegisterPlaceService.java b/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerService.java similarity index 80% rename from src/main/java/org/findy/findy_be/place/application/register/BatchRegisterPlaceService.java rename to src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerService.java index 8096dee..c9fb3d6 100644 --- a/src/main/java/org/findy/findy_be/place/application/register/BatchRegisterPlaceService.java +++ b/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerService.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.place.application.register; +package org.findy.findy_be.marker.application.register; import java.util.ArrayList; import java.util.List; @@ -9,8 +9,8 @@ import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.marker.application.create.BatchCreateMarker; import org.findy.findy_be.place.application.find.FindPlace; -import org.findy.findy_be.place.domain.Place; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import org.findy.findy_be.place.repository.PlaceRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,7 +22,7 @@ @Service @Transactional @RequiredArgsConstructor -public class BatchRegisterPlaceService implements BatchRegisterPlace { +public class BatchRegisterMarkerService implements BatchRegisterMarker { private static final String KEY_DELIMITER = "::"; @@ -31,7 +31,7 @@ public class BatchRegisterPlaceService implements BatchRegisterPlace { private final BatchCreateMarker batchCreateMarker; @Override - public void invoke(final Bookmark bookmark, final List requests) { + public void invoke(final Bookmark bookmark, final List requests) { List existingPlaces = findExistingPlaces(requests); List newPlaces = findNewPlaces(requests, existingPlaces); @@ -41,7 +41,7 @@ public void invoke(final Bookmark bookmark, final List req batchCreateMarker.invoke(bookmark, places); } - private List findExistingPlaces(List requests) { + private List findExistingPlaces(List requests) { return requests.stream() .map(request -> findPlace.invoke(request.title(), request.roadAddress())) .filter(Optional::isPresent) @@ -49,13 +49,13 @@ private List findExistingPlaces(List requests) { .collect(Collectors.toList()); } - private List findNewPlaces(List requests, List existingPlaces) { + private List findNewPlaces(List requests, List existingPlaces) { Set existingPlaceKeys = existingPlaces.stream() .map(place -> generateKey(place.getTitle(), place.getRoadAddress())) .collect(Collectors.toSet()); List newPlaces = new ArrayList<>(); - for (RegisterPlaceRequest request : requests) { + for (RegisterMarkerRequest request : requests) { String requestKey = generateKey(request.title(), request.roadAddress()); if (!existingPlaceKeys.contains(requestKey)) { newPlaces.add(request.toEntity()); diff --git a/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarkerService.java b/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarkerService.java index 3b063f9..23cbfc4 100644 --- a/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarkerService.java +++ b/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarkerService.java @@ -8,7 +8,7 @@ import org.findy.findy_be.marker.application.create.CreateMarker; import org.findy.findy_be.marker.dto.request.RegisterSearchedMarkerRequest; import org.findy.findy_be.place.application.find.FindPlace; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/org/findy/findy_be/marker/domain/Marker.java b/src/main/java/org/findy/findy_be/marker/domain/Marker.java index 75b0993..9a67b09 100644 --- a/src/main/java/org/findy/findy_be/marker/domain/Marker.java +++ b/src/main/java/org/findy/findy_be/marker/domain/Marker.java @@ -2,7 +2,7 @@ import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.common.entity.BaseTimeEntity; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -32,6 +32,8 @@ public class Marker extends BaseTimeEntity { @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "marker_sequence") private Long id; + private String timestamp; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "place_id") private Place place; @@ -45,8 +47,16 @@ public void changeBookmark(Bookmark bookmark) { bookmark.getMarkers().add(this); } - public static Marker create(final Bookmark bookmark, final Place place) { + public static Marker createForCustomBookmark(final Bookmark bookmark, final Place place) { + return Marker.builder() + .place(place) + .bookmark(bookmark) + .build(); + } + + public static Marker createForYoutubeBookmark(final String timestamp, final Bookmark bookmark, final Place place) { return Marker.builder() + .timestamp(timestamp) .place(place) .bookmark(bookmark) .build(); diff --git a/src/main/java/org/findy/findy_be/place/dto/request/CategoryRequest.java b/src/main/java/org/findy/findy_be/marker/dto/request/CategoryRequest.java similarity index 67% rename from src/main/java/org/findy/findy_be/place/dto/request/CategoryRequest.java rename to src/main/java/org/findy/findy_be/marker/dto/request/CategoryRequest.java index fc51048..bb1daed 100644 --- a/src/main/java/org/findy/findy_be/place/dto/request/CategoryRequest.java +++ b/src/main/java/org/findy/findy_be/marker/dto/request/CategoryRequest.java @@ -1,7 +1,7 @@ -package org.findy.findy_be.place.dto.request; +package org.findy.findy_be.marker.dto.request; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.MiddleCategory; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.MiddleCategory; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; diff --git a/src/main/java/org/findy/findy_be/place/dto/request/RegisterPlaceRequest.java b/src/main/java/org/findy/findy_be/marker/dto/request/RegisterMarkerRequest.java similarity index 85% rename from src/main/java/org/findy/findy_be/place/dto/request/RegisterPlaceRequest.java rename to src/main/java/org/findy/findy_be/marker/dto/request/RegisterMarkerRequest.java index 3983ccf..a9705b1 100644 --- a/src/main/java/org/findy/findy_be/place/dto/request/RegisterPlaceRequest.java +++ b/src/main/java/org/findy/findy_be/marker/dto/request/RegisterMarkerRequest.java @@ -1,12 +1,12 @@ -package org.findy.findy_be.place.dto.request; +package org.findy.findy_be.marker.dto.request; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; -@Schema(description = "장소 DTO") -public record RegisterPlaceRequest( +@Schema(description = "마커 등록 요청 DTO") +public record RegisterMarkerRequest( @NotNull(message = "장소명은 비어있을 수 없습니다.") @Schema(description = "장소명", example = "동대문엽기떡볶이 종각점") @@ -39,5 +39,4 @@ public record RegisterPlaceRequest( public Place toEntity() { return Place.create(this); } - } \ No newline at end of file diff --git a/src/main/java/org/findy/findy_be/marker/dto/request/RegisterSearchedMarkerRequest.java b/src/main/java/org/findy/findy_be/marker/dto/request/RegisterSearchedMarkerRequest.java index e70abe2..ffa7289 100644 --- a/src/main/java/org/findy/findy_be/marker/dto/request/RegisterSearchedMarkerRequest.java +++ b/src/main/java/org/findy/findy_be/marker/dto/request/RegisterSearchedMarkerRequest.java @@ -2,8 +2,8 @@ import static org.findy.findy_be.place.utils.CategoryResolver.*; -import org.findy.findy_be.place.domain.Place; -import org.findy.findy_be.place.domain.vo.Coordinate; +import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.marker.application.domain.vo.Coordinate; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; diff --git a/src/main/java/org/findy/findy_be/marker/repository/MarkerRepository.java b/src/main/java/org/findy/findy_be/marker/repository/MarkerRepository.java index 9ef3111..d65b57b 100644 --- a/src/main/java/org/findy/findy_be/marker/repository/MarkerRepository.java +++ b/src/main/java/org/findy/findy_be/marker/repository/MarkerRepository.java @@ -5,7 +5,7 @@ import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.marker.domain.Marker; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/org/findy/findy_be/place/application/find/FindPlace.java b/src/main/java/org/findy/findy_be/place/application/find/FindPlace.java index a964816..a78f080 100644 --- a/src/main/java/org/findy/findy_be/place/application/find/FindPlace.java +++ b/src/main/java/org/findy/findy_be/place/application/find/FindPlace.java @@ -2,7 +2,7 @@ import java.util.Optional; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; public interface FindPlace { Optional invoke(final String title, final String roadAddress); diff --git a/src/main/java/org/findy/findy_be/place/application/find/FindPlaceService.java b/src/main/java/org/findy/findy_be/place/application/find/FindPlaceService.java index e9346fa..8d173d8 100644 --- a/src/main/java/org/findy/findy_be/place/application/find/FindPlaceService.java +++ b/src/main/java/org/findy/findy_be/place/application/find/FindPlaceService.java @@ -2,7 +2,7 @@ import java.util.Optional; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/org/findy/findy_be/place/application/register/BatchRegisterPlace.java b/src/main/java/org/findy/findy_be/place/application/register/BatchRegisterPlace.java deleted file mode 100644 index 6a15142..0000000 --- a/src/main/java/org/findy/findy_be/place/application/register/BatchRegisterPlace.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.findy.findy_be.place.application.register; - -import java.util.List; - -import org.findy.findy_be.bookmark.domain.Bookmark; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; - -public interface BatchRegisterPlace { - void invoke(final Bookmark bookmark, final List requests); -} diff --git a/src/main/java/org/findy/findy_be/place/dto/response/PlaceResponse.java b/src/main/java/org/findy/findy_be/place/dto/response/PlaceResponse.java index a14169f..1774216 100644 --- a/src/main/java/org/findy/findy_be/place/dto/response/PlaceResponse.java +++ b/src/main/java/org/findy/findy_be/place/dto/response/PlaceResponse.java @@ -1,7 +1,7 @@ package org.findy.findy_be.place.dto.response; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.Place; import lombok.Builder; diff --git a/src/main/java/org/findy/findy_be/place/repository/PlaceRepository.java b/src/main/java/org/findy/findy_be/place/repository/PlaceRepository.java index faa0d3a..73f43cc 100644 --- a/src/main/java/org/findy/findy_be/place/repository/PlaceRepository.java +++ b/src/main/java/org/findy/findy_be/place/repository/PlaceRepository.java @@ -2,7 +2,7 @@ import java.util.Optional; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustom.java b/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustom.java index d0676e5..6f20dcf 100644 --- a/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustom.java +++ b/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustom.java @@ -1,6 +1,6 @@ package org.findy.findy_be.place.repository; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; diff --git a/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImpl.java b/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImpl.java index 6c59284..a1f29e2 100644 --- a/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImpl.java +++ b/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImpl.java @@ -4,7 +4,7 @@ import org.findy.findy_be.bookmark.domain.QBookmark; import org.findy.findy_be.marker.domain.QMarker; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import org.findy.findy_be.place.domain.QPlace; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; diff --git a/src/main/java/org/findy/findy_be/place/utils/CategoryResolver.java b/src/main/java/org/findy/findy_be/place/utils/CategoryResolver.java index a32cbaf..ba4b9f6 100644 --- a/src/main/java/org/findy/findy_be/place/utils/CategoryResolver.java +++ b/src/main/java/org/findy/findy_be/place/utils/CategoryResolver.java @@ -2,8 +2,8 @@ import static org.findy.findy_be.common.exception.ErrorCode.*; -import org.findy.findy_be.place.domain.MiddleCategory; -import org.findy.findy_be.place.domain.vo.Category; +import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.marker.application.domain.vo.Category; public class CategoryResolver { diff --git a/src/test/java/org/findy/findy_be/bookmark/api/BookmarkControllerTest.java b/src/test/java/org/findy/findy_be/bookmark/api/BookmarkControllerTest.java index 361e33a..d959f15 100644 --- a/src/test/java/org/findy/findy_be/bookmark/api/BookmarkControllerTest.java +++ b/src/test/java/org/findy/findy_be/bookmark/api/BookmarkControllerTest.java @@ -15,15 +15,15 @@ import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.bookmark.domain.BookmarkType; import org.findy.findy_be.bookmark.dto.request.CreateCustomBookmarkRequest; +import org.findy.findy_be.bookmark.dto.request.RegisterYoutubeBookmarkRequest; import org.findy.findy_be.bookmark.dto.request.UpdateBookmarkRequest; -import org.findy.findy_be.bookmark.dto.request.YoutubeBookmarkRequest; import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.common.IntegrationTest; import org.findy.findy_be.common.dto.pagination.request.PagedRequest; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.MiddleCategory; -import org.findy.findy_be.place.dto.request.CategoryRequest; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.marker.dto.request.CategoryRequest; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import org.findy.findy_be.user.domain.RoleType; import org.findy.findy_be.user.domain.User; import org.findy.findy_be.user.repository.UserRepository; @@ -75,10 +75,10 @@ void setUp() { void 유튜브_북마크_등록_성공() throws Exception { // given CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); - List selectedPlaces = List.of( - new RegisterPlaceRequest("Place1", "Description1", "Address1", "RoadAddress1", categoryRequest, "12345", + List selectedPlaces = List.of( + new RegisterMarkerRequest("Place1", "Description1", "Address1", "RoadAddress1", categoryRequest, "12345", "67890", "02-000-0000")); - YoutubeBookmarkRequest request = new YoutubeBookmarkRequest( + RegisterYoutubeBookmarkRequest request = new RegisterYoutubeBookmarkRequest( "@iammingki", "걍밍경", "https://yt3.googleusercontent.com/ytc/...", "https://www.youtube.com/watch?v=hE2wMo5Coco", selectedPlaces); @@ -94,7 +94,7 @@ void setUp() { @Test void 유튜브_북마크_등록_유효성_검증_실패_유튜버_ID_형식() throws Exception { // given - YoutubeBookmarkRequest invalidRequest = new YoutubeBookmarkRequest( + RegisterYoutubeBookmarkRequest invalidRequest = new RegisterYoutubeBookmarkRequest( "iammingki", "걍밍경", "https://yt3.googleusercontent.com/ytc/...", "https://www.youtube.com/watch?v=hE2wMo5Coco", null); @@ -111,7 +111,7 @@ void setUp() { @Test void 유튜브_북마크_등록_유효성_검증_실패_유튜버_이름_누락() throws Exception { // given - YoutubeBookmarkRequest invalidRequest = new YoutubeBookmarkRequest( + RegisterYoutubeBookmarkRequest invalidRequest = new RegisterYoutubeBookmarkRequest( "@iammingki", null, "https://yt3.googleusercontent.com/ytc/...", "https://www.youtube.com/watch?v=hE2wMo5Coco", null); diff --git a/src/test/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkServiceTest.java b/src/test/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkServiceTest.java index 0607919..f4b2b05 100644 --- a/src/test/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkServiceTest.java +++ b/src/test/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkServiceTest.java @@ -7,14 +7,14 @@ import java.util.Optional; import org.findy.findy_be.bookmark.domain.Bookmark; -import org.findy.findy_be.bookmark.dto.request.YoutubeBookmarkRequest; +import org.findy.findy_be.bookmark.dto.request.RegisterYoutubeBookmarkRequest; import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.common.MockTest; -import org.findy.findy_be.place.application.register.BatchRegisterPlaceService; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.MiddleCategory; -import org.findy.findy_be.place.dto.request.CategoryRequest; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.application.register.BatchRegisterMarkerService; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.marker.dto.request.CategoryRequest; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import org.findy.findy_be.user.domain.User; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -29,14 +29,14 @@ class RegisterYoutubeBookmarkServiceTest extends MockTest { private BookmarkRepository bookmarkRepository; @Mock - private BatchRegisterPlaceService batchRegisterPlace; + private BatchRegisterMarkerService batchRegisterPlace; @InjectMocks private RegisterYoutubeBookmarkService registerYoutubeBookmarkService; private User testUser; - private YoutubeBookmarkRequest request; - private List selectedPlaces; + private RegisterYoutubeBookmarkRequest request; + private List selectedPlaces; @BeforeEach void setUp() { @@ -45,10 +45,10 @@ void setUp() { when(testUser.getUserId()).thenReturn("N49sfgdahdKz_fp-223424er1N3D6kd"); CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); selectedPlaces = List.of( - new RegisterPlaceRequest("Place1", "Description1", "Address1", "RoadAddress1", categoryRequest, "12345", + new RegisterMarkerRequest("Place1", "Description1", "Address1", "RoadAddress1", categoryRequest, "12345", "67890", "02-000-0000")); - request = new YoutubeBookmarkRequest("@iammingki", "걍밍경", "https://yt3.googleusercontent.com/ytc/...", + request = new RegisterYoutubeBookmarkRequest("@iammingki", "걍밍경", "https://yt3.googleusercontent.com/ytc/...", "https://www.youtube.com/watch?v=hE2wMo5Coco", selectedPlaces); } diff --git a/src/test/java/org/findy/findy_be/common/repository/BulkInsertRepositoryImplTest.java b/src/test/java/org/findy/findy_be/common/repository/BulkInsertRepositoryImplTest.java index cce8d32..078677c 100644 --- a/src/test/java/org/findy/findy_be/common/repository/BulkInsertRepositoryImplTest.java +++ b/src/test/java/org/findy/findy_be/common/repository/BulkInsertRepositoryImplTest.java @@ -5,11 +5,11 @@ import java.util.stream.IntStream; import org.findy.findy_be.common.RepositoryTest; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.MiddleCategory; -import org.findy.findy_be.place.domain.Place; -import org.findy.findy_be.place.dto.request.CategoryRequest; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.marker.dto.request.CategoryRequest; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import org.findy.findy_be.place.repository.PlaceRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; @@ -38,7 +38,7 @@ void tearDown() { private List generateTestPlaces(int entityCount) { CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); return IntStream.range(0, entityCount) - .mapToObj(i -> new RegisterPlaceRequest( + .mapToObj(i -> new RegisterMarkerRequest( "Test Place " + i, "Description " + i, "02-1234-5678", diff --git a/src/test/java/org/findy/findy_be/marker/api/MarkerControllerTest.java b/src/test/java/org/findy/findy_be/marker/api/MarkerControllerTest.java index fc90eda..5db9341 100644 --- a/src/test/java/org/findy/findy_be/marker/api/MarkerControllerTest.java +++ b/src/test/java/org/findy/findy_be/marker/api/MarkerControllerTest.java @@ -20,7 +20,7 @@ import org.findy.findy_be.marker.domain.Marker; import org.findy.findy_be.marker.dto.request.RegisterSearchedMarkerRequest; import org.findy.findy_be.marker.repository.MarkerRepository; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.findy.findy_be.user.domain.RoleType; import org.findy.findy_be.user.domain.User; @@ -232,7 +232,7 @@ private void initPlacesForBookmark(Bookmark bookmark, int count) { List placeList = placeRepository.saveAll(places); List markers = placeList.stream() - .map(place -> Marker.create(bookmark, place)) + .map(place -> Marker.createForCustomBookmark(bookmark, place)) .collect(Collectors.toList()); markerRepository.saveAll(markers); diff --git a/src/test/java/org/findy/findy_be/marker/application/create/BatchCreateMarkerServiceTest.java b/src/test/java/org/findy/findy_be/marker/application/create/BatchCreateMarkerServiceTest.java index 7f3fce3..5098cc5 100644 --- a/src/test/java/org/findy/findy_be/marker/application/create/BatchCreateMarkerServiceTest.java +++ b/src/test/java/org/findy/findy_be/marker/application/create/BatchCreateMarkerServiceTest.java @@ -13,7 +13,7 @@ import org.findy.findy_be.common.MockTest; import org.findy.findy_be.marker.domain.Marker; import org.findy.findy_be.marker.repository.MarkerRepository; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/findy/findy_be/marker/application/create/CreateMarkerServiceTest.java b/src/test/java/org/findy/findy_be/marker/application/create/CreateMarkerServiceTest.java index 285887f..132adad 100644 --- a/src/test/java/org/findy/findy_be/marker/application/create/CreateMarkerServiceTest.java +++ b/src/test/java/org/findy/findy_be/marker/application/create/CreateMarkerServiceTest.java @@ -9,7 +9,7 @@ import org.findy.findy_be.common.MockTest; import org.findy.findy_be.marker.domain.Marker; import org.findy.findy_be.marker.repository.MarkerRepository; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -39,7 +39,7 @@ void setUp() { @Test void 마커를_생성하고_저장() { // given - Marker marker = Marker.create(bookmark, place); + Marker marker = Marker.createForCustomBookmark(bookmark, place); when(markerRepository.findByBookmarkAndPlace(bookmark, place)).thenReturn(Optional.empty()); when(markerRepository.save(any(Marker.class))).thenReturn(marker); @@ -54,7 +54,7 @@ void setUp() { @Test void 이미_존재하는_마커가_있을_경우() { // given - Marker existingMarker = Marker.create(bookmark, place); + Marker existingMarker = Marker.createForCustomBookmark(bookmark, place); when(markerRepository.findByBookmarkAndPlace(bookmark, place)).thenReturn(Optional.of(existingMarker)); // when diff --git a/src/test/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersServiceTest.java b/src/test/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersServiceTest.java index be746da..f1b4d09 100644 --- a/src/test/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersServiceTest.java +++ b/src/test/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersServiceTest.java @@ -9,11 +9,11 @@ import org.findy.findy_be.common.MockTest; import org.findy.findy_be.common.dto.pagination.response.SliceResponse; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.MiddleCategory; -import org.findy.findy_be.place.domain.Place; -import org.findy.findy_be.place.dto.request.CategoryRequest; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.marker.dto.request.CategoryRequest; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import org.findy.findy_be.place.dto.response.PlaceResponse; import org.findy.findy_be.place.repository.PlaceRepository; import org.findy.findy_be.user.domain.User; @@ -45,7 +45,7 @@ public void setUp() throws Exception { testUser = mock(User.class); CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); places = IntStream.range(0, 5) - .mapToObj(i -> new RegisterPlaceRequest( + .mapToObj(i -> new RegisterMarkerRequest( "Test Place " + i, "Description " + i, "02-1234-5678", diff --git a/src/test/java/org/findy/findy_be/place/application/register/BatchRegisterPlaceServiceTest.java b/src/test/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerServiceTest.java similarity index 69% rename from src/test/java/org/findy/findy_be/place/application/register/BatchRegisterPlaceServiceTest.java rename to src/test/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerServiceTest.java index 2221924..cbb395c 100644 --- a/src/test/java/org/findy/findy_be/place/application/register/BatchRegisterPlaceServiceTest.java +++ b/src/test/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerServiceTest.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.place.application.register; +package org.findy.findy_be.marker.application.register; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -11,11 +11,11 @@ import org.findy.findy_be.common.MockTest; import org.findy.findy_be.marker.application.create.BatchCreateMarkerService; import org.findy.findy_be.place.application.find.FindPlaceService; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.MiddleCategory; -import org.findy.findy_be.place.domain.Place; -import org.findy.findy_be.place.dto.request.CategoryRequest; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.marker.dto.request.CategoryRequest; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import org.findy.findy_be.place.repository.PlaceRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -24,7 +24,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -class BatchRegisterPlaceServiceTest extends MockTest { +class BatchRegisterMarkerServiceTest extends MockTest { @Mock private FindPlaceService findPlace; @@ -36,11 +36,11 @@ class BatchRegisterPlaceServiceTest extends MockTest { private BatchCreateMarkerService batchCreateMarker; @InjectMocks - private BatchRegisterPlaceService batchRegisterPlaceService; + private BatchRegisterMarkerService batchRegisterMarkerService; private Bookmark testBookmark; - private RegisterPlaceRequest request1; - private RegisterPlaceRequest request2; + private RegisterMarkerRequest request1; + private RegisterMarkerRequest request2; private Place place1; private Place place2; @@ -49,11 +49,10 @@ void setUp() { MockitoAnnotations.openMocks(this); testBookmark = mock(Bookmark.class); CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); - request1 = new RegisterPlaceRequest("Place1", "Description1", "Address1", "RoadAddress1", categoryRequest, - "12345", - "67890", "02-000-0000"); - request2 = new RegisterPlaceRequest("Place2", "Description2", "Address2", "RoadAddress2", categoryRequest, - "54321", "09876", "02-000-0001"); + request1 = new RegisterMarkerRequest("Place1", "Description1", "Address1", "RoadAddress1", categoryRequest, + "12345", "67890", "02-000-0000", "0.04"); + request2 = new RegisterMarkerRequest("Place2", "Description2", "Address2", "RoadAddress2", categoryRequest, + "54321", "09876", "02-000-0001", "0.04"); place1 = mock(Place.class); place2 = mock(Place.class); } @@ -62,14 +61,14 @@ void setUp() { @Test void 새로운_장소_모두_등록_및_마커_생성() { // given - List requests = Arrays.asList(request1, request2); + List requests = Arrays.asList(request1, request2); when(findPlace.invoke(request1.title(), request1.roadAddress())).thenReturn(Optional.empty()); when(findPlace.invoke(request2.title(), request2.roadAddress())).thenReturn(Optional.empty()); when(placeRepository.saveAll(anyList())).thenReturn(Arrays.asList(place1, place2)); // when - batchRegisterPlaceService.invoke(testBookmark, requests); + batchRegisterMarkerService.invoke(testBookmark, requests); // then verify(placeRepository, times(1)).saveAll(anyList()); @@ -80,14 +79,14 @@ void setUp() { @Test void 이미_등록된_장소_새로_등록되지_않음() { // given - List requests = Arrays.asList(request1, request2); + List requests = Arrays.asList(request1, request2); when(findPlace.invoke(request1.title(), request1.roadAddress())).thenReturn(Optional.empty()); when(findPlace.invoke(request2.title(), request2.roadAddress())).thenReturn(Optional.of(place2)); when(placeRepository.saveAll(anyList())).thenReturn(Arrays.asList(place1)); // when - batchRegisterPlaceService.invoke(testBookmark, requests); + batchRegisterMarkerService.invoke(testBookmark, requests); // then verify(placeRepository, times(1)).saveAll(anyList()); @@ -99,13 +98,13 @@ void setUp() { @Test void 단일_장소_등록_및_마커_생성() { // given - List requests = Arrays.asList(request1); + List requests = Arrays.asList(request1); when(findPlace.invoke(request1.title(), request1.roadAddress())).thenReturn(Optional.empty()); when(placeRepository.saveAll(anyList())).thenReturn(Arrays.asList(place1)); // when - batchRegisterPlaceService.invoke(testBookmark, requests); + batchRegisterMarkerService.invoke(testBookmark, requests); // then verify(placeRepository, times(1)).saveAll(anyList()); diff --git a/src/test/java/org/findy/findy_be/marker/application/register/RegisterMarkerServiceTest.java b/src/test/java/org/findy/findy_be/marker/application/register/RegisterMarkerServiceTest.java index b53f374..982ba7a 100644 --- a/src/test/java/org/findy/findy_be/marker/application/register/RegisterMarkerServiceTest.java +++ b/src/test/java/org/findy/findy_be/marker/application/register/RegisterMarkerServiceTest.java @@ -16,7 +16,7 @@ import org.findy.findy_be.marker.application.create.CreateMarker; import org.findy.findy_be.marker.dto.request.RegisterSearchedMarkerRequest; import org.findy.findy_be.place.application.find.FindPlace; -import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.marker.application.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.findy.findy_be.user.domain.RoleType; import org.findy.findy_be.user.domain.User; diff --git a/src/test/java/org/findy/findy_be/marker/repository/MarkerRepositoryTest.java b/src/test/java/org/findy/findy_be/marker/repository/MarkerRepositoryTest.java index f1d3fd2..50c8186 100644 --- a/src/test/java/org/findy/findy_be/marker/repository/MarkerRepositoryTest.java +++ b/src/test/java/org/findy/findy_be/marker/repository/MarkerRepositoryTest.java @@ -11,11 +11,11 @@ import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.common.RepositoryTest; import org.findy.findy_be.marker.domain.Marker; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.MiddleCategory; -import org.findy.findy_be.place.domain.Place; -import org.findy.findy_be.place.dto.request.CategoryRequest; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.marker.dto.request.CategoryRequest; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import org.findy.findy_be.place.repository.PlaceRepository; import org.findy.findy_be.user.domain.RoleType; import org.findy.findy_be.user.domain.User; @@ -51,7 +51,7 @@ void setUp() { LocalDateTime.now(), LocalDateTime.now())); CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); - RegisterPlaceRequest request = new RegisterPlaceRequest( + RegisterMarkerRequest request = new RegisterMarkerRequest( "동대문엽기떡볶이 종각점", "설명", "서울특별시 종로구 공평동 124", @@ -63,7 +63,7 @@ void setUp() { ); testPlace = placeRepository.save(Place.create(request)); testBookmark = bookmarkRepository.save(Bookmark.of("서촌", BookmarkType.CUSTOM, null, null, null, testUser)); - testMarker = markerRepository.save(Marker.create(testBookmark, testPlace)); + testMarker = markerRepository.save(Marker.createForCustomBookmark(testBookmark, testPlace)); testMarker.changeBookmark(testBookmark); } diff --git a/src/test/java/org/findy/findy_be/place/application/find/FindPlaceServiceTest.java b/src/test/java/org/findy/findy_be/place/application/find/FindPlaceServiceTest.java index c987cd3..fce362e 100644 --- a/src/test/java/org/findy/findy_be/place/application/find/FindPlaceServiceTest.java +++ b/src/test/java/org/findy/findy_be/place/application/find/FindPlaceServiceTest.java @@ -6,11 +6,11 @@ import java.util.Optional; import org.findy.findy_be.common.MockTest; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.MiddleCategory; -import org.findy.findy_be.place.domain.Place; -import org.findy.findy_be.place.dto.request.CategoryRequest; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.marker.dto.request.CategoryRequest; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import org.findy.findy_be.place.repository.PlaceRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -27,14 +27,14 @@ class FindPlaceServiceTest extends MockTest { @InjectMocks private FindPlaceService findPlaceService; - private RegisterPlaceRequest placeRequest; + private RegisterMarkerRequest placeRequest; private Place place; @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); - placeRequest = new RegisterPlaceRequest( + placeRequest = new RegisterMarkerRequest( "동대문엽기떡볶이 종각점", "설명", "서울특별시 종로구 공평동 124", diff --git a/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImplTest.java b/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImplTest.java index 8f55720..0d558a7 100644 --- a/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImplTest.java +++ b/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImplTest.java @@ -13,11 +13,11 @@ import org.findy.findy_be.common.RepositoryTest; import org.findy.findy_be.marker.domain.Marker; import org.findy.findy_be.marker.repository.MarkerRepository; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.MiddleCategory; -import org.findy.findy_be.place.domain.Place; -import org.findy.findy_be.place.dto.request.CategoryRequest; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.marker.dto.request.CategoryRequest; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import org.findy.findy_be.user.domain.RoleType; import org.findy.findy_be.user.domain.User; import org.findy.findy_be.user.repository.UserRepository; @@ -100,7 +100,7 @@ void setUp() { private void initPlacesForBookmark(Bookmark bookmark, int count) { List places = IntStream.rangeClosed(1, count) - .mapToObj(i -> Place.create(new RegisterPlaceRequest( + .mapToObj(i -> Place.create(new RegisterMarkerRequest( "Test Place " + i, "Description " + i, "Address " + i, @@ -115,7 +115,7 @@ private void initPlacesForBookmark(Bookmark bookmark, int count) { persistPlaces = placeJpaRepository.saveAll(places); List markers = places.stream() - .map(place -> Marker.create(bookmark, place)) + .map(place -> Marker.createForCustomBookmark(bookmark, place)) .collect(Collectors.toList()); markerRepository.saveAll(markers); diff --git a/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryTest.java b/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryTest.java index 5c8a1ea..1061bd1 100644 --- a/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryTest.java +++ b/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryTest.java @@ -8,11 +8,11 @@ import java.util.stream.IntStream; import org.findy.findy_be.common.RepositoryTest; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.MiddleCategory; -import org.findy.findy_be.place.domain.Place; -import org.findy.findy_be.place.dto.request.CategoryRequest; -import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.marker.dto.request.CategoryRequest; +import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -28,7 +28,7 @@ class PlaceRepositoryTest extends RepositoryTest { void 주어진_상세_정보로_장소_조회() { // given CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); - RegisterPlaceRequest request = new RegisterPlaceRequest( + RegisterMarkerRequest request = new RegisterMarkerRequest( "동대문엽기떡볶이 종각점", "설명", "서울특별시 종로구 공평동 124", @@ -70,7 +70,7 @@ class PlaceRepositoryTest extends RepositoryTest { // given CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); List places = IntStream.range(0, 100) - .mapToObj(i -> Place.create(new RegisterPlaceRequest( + .mapToObj(i -> Place.create(new RegisterMarkerRequest( "Test Place " + i, "Description " + i, "02-1234-5678", diff --git a/src/test/java/org/findy/findy_be/place/utils/CategoryResolverTest.java b/src/test/java/org/findy/findy_be/place/utils/CategoryResolverTest.java index cfad012..18343ae 100644 --- a/src/test/java/org/findy/findy_be/place/utils/CategoryResolverTest.java +++ b/src/test/java/org/findy/findy_be/place/utils/CategoryResolverTest.java @@ -3,9 +3,9 @@ import static org.junit.jupiter.api.Assertions.*; import org.findy.findy_be.common.exception.ErrorCode; -import org.findy.findy_be.place.domain.MajorCategory; -import org.findy.findy_be.place.domain.MiddleCategory; -import org.findy.findy_be.place.domain.vo.Category; +import org.findy.findy_be.marker.application.domain.MajorCategory; +import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.marker.application.domain.vo.Category; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; From f578cb700eb3f6b5bc2dfeb58cf8b4f6aa1ab114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Sun, 17 Nov 2024 13:31:06 +0900 Subject: [PATCH 04/10] feat: marker timestamp --- .../register/RegisterYoutubeBookmark.java | 4 +- .../RegisterYoutubeBookmarkService.java | 34 +++++----- .../findy_be/bookmark/domain/Bookmark.java | 2 +- .../RegisterYoutubeBookmarkRequest.java | 4 +- .../findy_be/common/exception/ErrorCode.java | 3 +- .../application/create/BatchCreateMarker.java | 5 +- .../create/BatchCreateMarkerService.java | 68 +++++++++++-------- .../application/create/CreateMarker.java | 2 +- .../create/CreateMarkerService.java | 2 +- .../register/BatchRegisterMarker.java | 5 +- .../register/BatchRegisterMarkerService.java | 39 ++++------- .../register/PlaceWithTimestamp.java | 9 +++ .../register/RegisterMarkerService.java | 2 +- .../findy/findy_be/marker/domain/Marker.java | 20 +++++- .../marker/dto/request/CategoryRequest.java | 4 +- .../RegisterSearchedMarkerRequest.java | 4 +- ...java => RegisterYouTubeMarkerRequest.java} | 19 ++++-- .../marker/repository/MarkerRepository.java | 2 +- .../place/application/find/FindPlace.java | 2 +- .../application/find/FindPlaceService.java | 2 +- .../domain/MajorCategory.java | 2 +- .../domain/MiddleCategory.java | 2 +- .../application => place}/domain/Place.java | 28 ++++++-- .../domain/vo/Category.java | 6 +- .../domain/vo/Coordinate.java | 2 +- .../place/dto/response/PlaceResponse.java | 4 +- .../place/repository/PlaceRepository.java | 2 +- .../repository/PlaceRepositoryCustom.java | 2 +- .../repository/PlaceRepositoryCustomImpl.java | 2 +- .../place/utils/CategoryResolver.java | 4 +- .../bookmark/api/BookmarkControllerTest.java | 13 ++-- .../RegisterYoutubeBookmarkServiceTest.java | 21 +++--- .../BulkInsertRepositoryImplTest.java | 14 ++-- .../marker/api/MarkerControllerTest.java | 6 +- .../create/BatchCreateMarkerServiceTest.java | 28 +++++++- .../create/CreateMarkerServiceTest.java | 2 +- .../find/FindAllPagedMarkersServiceTest.java | 14 ++-- .../BatchRegisterMarkerServiceTest.java | 37 +++++----- .../register/RegisterMarkerServiceTest.java | 2 +- .../repository/MarkerRepositoryTest.java | 13 ++-- .../find/FindPlaceServiceTest.java | 15 ++-- .../PlaceRepositoryCustomImplTest.java | 15 ++-- .../place/repository/PlaceRepositoryTest.java | 19 +++--- .../place/utils/CategoryResolverTest.java | 6 +- 44 files changed, 294 insertions(+), 197 deletions(-) create mode 100644 src/main/java/org/findy/findy_be/marker/application/register/PlaceWithTimestamp.java rename src/main/java/org/findy/findy_be/marker/dto/request/{RegisterMarkerRequest.java => RegisterYouTubeMarkerRequest.java} (71%) rename src/main/java/org/findy/findy_be/{marker/application => place}/domain/MajorCategory.java (90%) rename src/main/java/org/findy/findy_be/{marker/application => place}/domain/MiddleCategory.java (99%) rename src/main/java/org/findy/findy_be/{marker/application => place}/domain/Place.java (71%) rename src/main/java/org/findy/findy_be/{marker/application => place}/domain/vo/Category.java (78%) rename src/main/java/org/findy/findy_be/{marker/application => place}/domain/vo/Coordinate.java (93%) diff --git a/src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmark.java b/src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmark.java index 8a83f1d..88ce73a 100644 --- a/src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmark.java +++ b/src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmark.java @@ -1,9 +1,9 @@ package org.findy.findy_be.bookmark.application.register; -import org.findy.findy_be.bookmark.dto.request.YoutubeBookmarkRequest; +import org.findy.findy_be.bookmark.dto.request.RegisterYoutubeBookmarkRequest; import org.findy.findy_be.user.domain.User; public interface RegisterYoutubeBookmark { - void invoke(final User user, final YoutubeBookmarkRequest request); + void invoke(final User user, final RegisterYoutubeBookmarkRequest request); } diff --git a/src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkService.java b/src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkService.java index 317ea28..b1124c4 100644 --- a/src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkService.java +++ b/src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkService.java @@ -9,7 +9,7 @@ import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.common.exception.custom.ForbiddenAccessException; import org.findy.findy_be.marker.application.register.BatchRegisterMarker; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; import org.findy.findy_be.user.domain.User; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -28,25 +28,25 @@ public class RegisterYoutubeBookmarkService implements RegisterYoutubeBookmark { @Override public void invoke(final User user, final RegisterYoutubeBookmarkRequest request) { - List placeRequests = request.places(); - bookmarkRepository.findByUserAndYoutuberId(user, request.youtuberId()).ifPresentOrElse( - existingBookmark -> { - existingBookmark.updateName(request.youtuberName()); - validateBookmarkOwner(user, existingBookmark.getUser()); - batchRegisterMarker.invoke(existingBookmark, placeRequests); - }, - () -> { - log.info("새로운 북마크에 저장합니다."); - Bookmark bookmark = request.toEntity(user); - bookmarkRepository.save(bookmark); - batchRegisterMarker.invoke(bookmark, placeRequests); - } - ); + List placeRequests = request.places(); + + bookmarkRepository.findByUserAndYoutuberId(user, request.youtuberId()) + .ifPresentOrElse( + existingBookmark -> { + existingBookmark.updateName(request.youtuberName()); + validateBookmarkOwner(user, existingBookmark.getUser()); + batchRegisterMarker.invoke(existingBookmark, placeRequests); + }, + () -> { + log.info("새로운 북마크에 저장합니다."); + Bookmark newBookmark = bookmarkRepository.save(request.toEntity(user)); + batchRegisterMarker.invoke(newBookmark, placeRequests); + } + ); } private void validateBookmarkOwner(User currentUser, User bookmarkUser) { - String bookmarkUserId = bookmarkUser.getUserId(); - if (!bookmarkUserId.equals(currentUser.getUserId())) { + if (!bookmarkUser.getUserId().equals(currentUser.getUserId())) { throw new ForbiddenAccessException(FORBIDDEN_BOOKMARK_ACCESS.getMessage()); } } diff --git a/src/main/java/org/findy/findy_be/bookmark/domain/Bookmark.java b/src/main/java/org/findy/findy_be/bookmark/domain/Bookmark.java index 3228d4f..f1b931e 100644 --- a/src/main/java/org/findy/findy_be/bookmark/domain/Bookmark.java +++ b/src/main/java/org/findy/findy_be/bookmark/domain/Bookmark.java @@ -57,7 +57,7 @@ public class Bookmark extends BaseTimeEntity { @JoinColumn(name = "user_id") private User user; - @OneToMany(mappedBy = "bookmark", cascade = CascadeType.REMOVE, orphanRemoval = true) + @OneToMany(mappedBy = "bookmark", cascade = CascadeType.ALL, orphanRemoval = true) @Builder.Default private List markers = new ArrayList<>(); diff --git a/src/main/java/org/findy/findy_be/bookmark/dto/request/RegisterYoutubeBookmarkRequest.java b/src/main/java/org/findy/findy_be/bookmark/dto/request/RegisterYoutubeBookmarkRequest.java index 4bb6ce9..251275a 100644 --- a/src/main/java/org/findy/findy_be/bookmark/dto/request/RegisterYoutubeBookmarkRequest.java +++ b/src/main/java/org/findy/findy_be/bookmark/dto/request/RegisterYoutubeBookmarkRequest.java @@ -4,7 +4,7 @@ import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.common.validation.ValidYoutuberId; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; import org.findy.findy_be.user.domain.User; import io.swagger.v3.oas.annotations.media.Schema; @@ -27,7 +27,7 @@ public record RegisterYoutubeBookmarkRequest( @Schema(description = "유튜브 링크", example = "https://www.youtube.com/watch?v=hE2wMo5Coco") String youtubeLink, - List places + List places ) { public Bookmark toEntity(User user) { return Bookmark.createYoutubeType(youtuberName, youtuberId, youtuberProfile, youtubeLink, user); diff --git a/src/main/java/org/findy/findy_be/common/exception/ErrorCode.java b/src/main/java/org/findy/findy_be/common/exception/ErrorCode.java index 38dd073..d20b69d 100644 --- a/src/main/java/org/findy/findy_be/common/exception/ErrorCode.java +++ b/src/main/java/org/findy/findy_be/common/exception/ErrorCode.java @@ -30,7 +30,8 @@ public enum ErrorCode { NOT_FOUND_BOOKMARK_BY_ID(NOT_FOUND, "해당 id : %s의 즐겨찾기가 존재하지 않습니다."), NOT_FOUND_USER(NOT_FOUND, "해당 이메일을 가진 유저가 존재하지 않습니다."), NOT_FOUND_USER_BY_ID(NOT_FOUND, "해당 id : %s를 가진 유저가 존재하지 않습니다."), - BAD_REQUEST_CATEGORY_NOT_FOUND_ERROR(NOT_FOUND, "해당 input : %s을 가진 카테고리가 없습니다."); + BAD_REQUEST_CATEGORY_NOT_FOUND_ERROR(NOT_FOUND, "해당 input : %s을 가진 카테고리가 없습니다."), + NOT_FOUND_PLACE(NOT_FOUND, "장소를 찾을 수 없습니다. 장소멸: %s, 도로명 주소: %s"); // 500 error diff --git a/src/main/java/org/findy/findy_be/marker/application/create/BatchCreateMarker.java b/src/main/java/org/findy/findy_be/marker/application/create/BatchCreateMarker.java index 7bc5d99..d5b733b 100644 --- a/src/main/java/org/findy/findy_be/marker/application/create/BatchCreateMarker.java +++ b/src/main/java/org/findy/findy_be/marker/application/create/BatchCreateMarker.java @@ -3,8 +3,9 @@ import java.util.List; import org.findy.findy_be.bookmark.domain.Bookmark; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; +import org.findy.findy_be.place.domain.Place; public interface BatchCreateMarker { - void invoke(final Bookmark bookmark, final List places); + void invoke(final Bookmark bookmark, final List places, final List requests); } diff --git a/src/main/java/org/findy/findy_be/marker/application/create/BatchCreateMarkerService.java b/src/main/java/org/findy/findy_be/marker/application/create/BatchCreateMarkerService.java index 39d1f5c..e9fbde7 100644 --- a/src/main/java/org/findy/findy_be/marker/application/create/BatchCreateMarkerService.java +++ b/src/main/java/org/findy/findy_be/marker/application/create/BatchCreateMarkerService.java @@ -7,8 +7,8 @@ import java.util.stream.Collectors; import org.findy.findy_be.bookmark.domain.Bookmark; -import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.marker.domain.Marker; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; import org.findy.findy_be.marker.repository.MarkerRepository; import org.findy.findy_be.place.domain.Place; import org.springframework.stereotype.Service; @@ -25,43 +25,55 @@ public class BatchCreateMarkerService implements BatchCreateMarker { private final MarkerRepository markerRepository; - private final BookmarkRepository bookmarkRepository; @Override - public void invoke(final Bookmark bookmark, final List places) { - List existingMarkers = markerRepository.findAllByBookmarkAndPlaces(bookmark, places); + public void invoke(final Bookmark bookmark, final List places, + final List requests) { + Set existingPlaceIds = findExistingPlaceIds(bookmark, places); - Set existingPlaceIds = getExistingPlaceIds(existingMarkers); - List newMarkers = getNewMarkers(bookmark, places, existingPlaceIds); + List newMarkers = createNewMarkers(bookmark, places, requests, existingPlaceIds); - markerRepository.saveAll(newMarkers); - updateMarkersCount(bookmark.getId(), newMarkers); - } - - private static List getNewMarkers(final Bookmark bookmark, final List places, - final Set existingPlaceIds) { - return places.stream() - .filter(place -> !existingPlaceIds.contains(place.getId())) - .map(place -> { - Marker marker = Marker.create(bookmark, place); - marker.changeBookmark(bookmark); - return marker; - }) - .collect(Collectors.toList()); + saveMarkersAndIncrementCount(bookmark, newMarkers); } - private static Set getExistingPlaceIds(final List existingMarkers) { - Set existingPlaceIds; - existingPlaceIds = existingMarkers.stream() + private Set findExistingPlaceIds(Bookmark bookmark, List places) { + return markerRepository.findAllByBookmarkAndPlaces(bookmark, places).stream() .map(marker -> marker.getPlace().getId()) .collect(Collectors.toSet()); - return existingPlaceIds; } - private void updateMarkersCount(final Long bookmarkId, final List newMarkers) { - Bookmark bookmark = bookmarkRepository.findById(bookmarkId) - .orElseThrow(() -> new EntityNotFoundException( - String.format(NOT_FOUND_BOOKMARK_BY_ID.getMessage(), bookmarkId))); + private List createNewMarkers(Bookmark bookmark, List places, + List requests, Set existingPlaceIds) { + return requests.stream() + .filter(request -> !existingPlaceIds.contains( + findPlaceIdByTitleAndRoadAddress(places, request.title(), request.roadAddress()))) + .map(request -> createMarker(bookmark, places, request)) + .toList(); + } + + private Marker createMarker(Bookmark bookmark, List places, RegisterYouTubeMarkerRequest request) { + Place place = findPlaceByTitleAndRoadAddress(places, request.title(), request.roadAddress()); + return Marker.createForYoutubeBookmark(request.timestamp(), bookmark, place); + } + + private void saveMarkersAndIncrementCount(Bookmark bookmark, List newMarkers) { + markerRepository.saveAll(newMarkers); bookmark.incrementMarkersCount(newMarkers.size()); } + + private Place findPlaceByTitleAndRoadAddress(List places, String title, String roadAddress) { + return places.stream() + .filter(place -> place.getTitle().equals(title) && place.getRoadAddress().equals(roadAddress)) + .findFirst() + .orElseThrow( + () -> new EntityNotFoundException(String.format(NOT_FOUND_PLACE.getMessage(), title, roadAddress))); + } + + private Long findPlaceIdByTitleAndRoadAddress(List places, String title, String roadAddress) { + return places.stream() + .filter(place -> place.getTitle().equals(title) && place.getRoadAddress().equals(roadAddress)) + .map(Place::getId) + .findFirst() + .orElse(null); + } } diff --git a/src/main/java/org/findy/findy_be/marker/application/create/CreateMarker.java b/src/main/java/org/findy/findy_be/marker/application/create/CreateMarker.java index 6b22374..df0b475 100644 --- a/src/main/java/org/findy/findy_be/marker/application/create/CreateMarker.java +++ b/src/main/java/org/findy/findy_be/marker/application/create/CreateMarker.java @@ -1,7 +1,7 @@ package org.findy.findy_be.marker.application.create; import org.findy.findy_be.bookmark.domain.Bookmark; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; public interface CreateMarker { void invoke(final Bookmark bookmark, final Place place); diff --git a/src/main/java/org/findy/findy_be/marker/application/create/CreateMarkerService.java b/src/main/java/org/findy/findy_be/marker/application/create/CreateMarkerService.java index ec354ab..f2f48f1 100644 --- a/src/main/java/org/findy/findy_be/marker/application/create/CreateMarkerService.java +++ b/src/main/java/org/findy/findy_be/marker/application/create/CreateMarkerService.java @@ -5,7 +5,7 @@ import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.marker.domain.Marker; import org.findy.findy_be.marker.repository.MarkerRepository; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarker.java b/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarker.java index 28a64d3..481b27c 100644 --- a/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarker.java +++ b/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarker.java @@ -3,8 +3,9 @@ import java.util.List; import org.findy.findy_be.bookmark.domain.Bookmark; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; public interface BatchRegisterMarker { - void invoke(final Bookmark bookmark, final List requests); + + void invoke(final Bookmark bookmark, final List requests); } diff --git a/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerService.java b/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerService.java index c9fb3d6..2d34197 100644 --- a/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerService.java +++ b/src/main/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerService.java @@ -1,6 +1,7 @@ package org.findy.findy_be.marker.application.register; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.Set; @@ -8,9 +9,9 @@ import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.marker.application.create.BatchCreateMarker; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; import org.findy.findy_be.place.application.find.FindPlace; -import org.findy.findy_be.marker.application.domain.Place; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -24,24 +25,22 @@ @RequiredArgsConstructor public class BatchRegisterMarkerService implements BatchRegisterMarker { - private static final String KEY_DELIMITER = "::"; - private final FindPlace findPlace; private final PlaceRepository placeRepository; private final BatchCreateMarker batchCreateMarker; @Override - public void invoke(final Bookmark bookmark, final List requests) { + public void invoke(final Bookmark bookmark, final List requests) { List existingPlaces = findExistingPlaces(requests); List newPlaces = findNewPlaces(requests, existingPlaces); List persistedPlaces = placeRepository.saveAll(newPlaces); - List places = combineAllPlaces(existingPlaces, persistedPlaces); - batchCreateMarker.invoke(bookmark, places); + List allPlaces = combineAllPlaces(existingPlaces, persistedPlaces); + batchCreateMarker.invoke(bookmark, allPlaces, requests); } - private List findExistingPlaces(List requests) { + private List findExistingPlaces(List requests) { return requests.stream() .map(request -> findPlace.invoke(request.title(), request.roadAddress())) .filter(Optional::isPresent) @@ -49,19 +48,13 @@ private List findExistingPlaces(List requests) { .collect(Collectors.toList()); } - private List findNewPlaces(List requests, List existingPlaces) { - Set existingPlaceKeys = existingPlaces.stream() - .map(place -> generateKey(place.getTitle(), place.getRoadAddress())) - .collect(Collectors.toSet()); + private List findNewPlaces(List requests, List existingPlaces) { + Set existingPlaceSet = new HashSet<>(existingPlaces); - List newPlaces = new ArrayList<>(); - for (RegisterMarkerRequest request : requests) { - String requestKey = generateKey(request.title(), request.roadAddress()); - if (!existingPlaceKeys.contains(requestKey)) { - newPlaces.add(request.toEntity()); - } - } - return newPlaces; + return requests.stream() + .map(RegisterYouTubeMarkerRequest::toPlaceEntity) + .filter(place -> !existingPlaceSet.contains(place)) + .toList(); } private List combineAllPlaces(List existingPlaces, List persistedNewPlaces) { @@ -69,8 +62,4 @@ private List combineAllPlaces(List existingPlaces, List per allPlaces.addAll(persistedNewPlaces); return allPlaces; } - - private String generateKey(String title, String roadAddress) { - return title + KEY_DELIMITER + roadAddress; - } -} +} \ No newline at end of file diff --git a/src/main/java/org/findy/findy_be/marker/application/register/PlaceWithTimestamp.java b/src/main/java/org/findy/findy_be/marker/application/register/PlaceWithTimestamp.java new file mode 100644 index 0000000..8f106e2 --- /dev/null +++ b/src/main/java/org/findy/findy_be/marker/application/register/PlaceWithTimestamp.java @@ -0,0 +1,9 @@ +package org.findy.findy_be.marker.application.register; + +import org.findy.findy_be.place.domain.Place; + +public record PlaceWithTimestamp( + Place place, + String timestamp +) { +} diff --git a/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarkerService.java b/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarkerService.java index 23cbfc4..3b063f9 100644 --- a/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarkerService.java +++ b/src/main/java/org/findy/findy_be/marker/application/register/RegisterMarkerService.java @@ -8,7 +8,7 @@ import org.findy.findy_be.marker.application.create.CreateMarker; import org.findy.findy_be.marker.dto.request.RegisterSearchedMarkerRequest; import org.findy.findy_be.place.application.find.FindPlace; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/org/findy/findy_be/marker/domain/Marker.java b/src/main/java/org/findy/findy_be/marker/domain/Marker.java index 9a67b09..9d02663 100644 --- a/src/main/java/org/findy/findy_be/marker/domain/Marker.java +++ b/src/main/java/org/findy/findy_be/marker/domain/Marker.java @@ -1,8 +1,10 @@ package org.findy.findy_be.marker.domain; +import java.util.Objects; + import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.common.entity.BaseTimeEntity; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -61,4 +63,20 @@ public static Marker createForYoutubeBookmark(final String timestamp, final Book .bookmark(bookmark) .build(); } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Marker marker = (Marker)o; + return Objects.equals(id, marker.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } + } diff --git a/src/main/java/org/findy/findy_be/marker/dto/request/CategoryRequest.java b/src/main/java/org/findy/findy_be/marker/dto/request/CategoryRequest.java index bb1daed..b74dc46 100644 --- a/src/main/java/org/findy/findy_be/marker/dto/request/CategoryRequest.java +++ b/src/main/java/org/findy/findy_be/marker/dto/request/CategoryRequest.java @@ -1,7 +1,7 @@ package org.findy.findy_be.marker.dto.request; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; diff --git a/src/main/java/org/findy/findy_be/marker/dto/request/RegisterSearchedMarkerRequest.java b/src/main/java/org/findy/findy_be/marker/dto/request/RegisterSearchedMarkerRequest.java index ffa7289..e70abe2 100644 --- a/src/main/java/org/findy/findy_be/marker/dto/request/RegisterSearchedMarkerRequest.java +++ b/src/main/java/org/findy/findy_be/marker/dto/request/RegisterSearchedMarkerRequest.java @@ -2,8 +2,8 @@ import static org.findy.findy_be.place.utils.CategoryResolver.*; -import org.findy.findy_be.marker.application.domain.Place; -import org.findy.findy_be.marker.application.domain.vo.Coordinate; +import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.place.domain.vo.Coordinate; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; diff --git a/src/main/java/org/findy/findy_be/marker/dto/request/RegisterMarkerRequest.java b/src/main/java/org/findy/findy_be/marker/dto/request/RegisterYouTubeMarkerRequest.java similarity index 71% rename from src/main/java/org/findy/findy_be/marker/dto/request/RegisterMarkerRequest.java rename to src/main/java/org/findy/findy_be/marker/dto/request/RegisterYouTubeMarkerRequest.java index a9705b1..c04a4c5 100644 --- a/src/main/java/org/findy/findy_be/marker/dto/request/RegisterMarkerRequest.java +++ b/src/main/java/org/findy/findy_be/marker/dto/request/RegisterYouTubeMarkerRequest.java @@ -1,12 +1,14 @@ package org.findy.findy_be.marker.dto.request; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.bookmark.domain.Bookmark; +import org.findy.findy_be.marker.domain.Marker; +import org.findy.findy_be.place.domain.Place; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; @Schema(description = "마커 등록 요청 DTO") -public record RegisterMarkerRequest( +public record RegisterYouTubeMarkerRequest( @NotNull(message = "장소명은 비어있을 수 없습니다.") @Schema(description = "장소명", example = "동대문엽기떡볶이 종각점") @@ -34,9 +36,18 @@ public record RegisterMarkerRequest( String mapY, @Schema(description = "전화번호", example = "02-000-000") - String telephone + String telephone, + + @Schema(description = "타임 스탬프", example = "0.04") + String timestamp ) { - public Place toEntity() { + + public Place toPlaceEntity() { return Place.create(this); } + + public Marker toMarkerEntity(Bookmark bookmark) { + Place place = toPlaceEntity(); + return Marker.createForYoutubeBookmark(timestamp, bookmark, place); + } } \ No newline at end of file diff --git a/src/main/java/org/findy/findy_be/marker/repository/MarkerRepository.java b/src/main/java/org/findy/findy_be/marker/repository/MarkerRepository.java index d65b57b..9ef3111 100644 --- a/src/main/java/org/findy/findy_be/marker/repository/MarkerRepository.java +++ b/src/main/java/org/findy/findy_be/marker/repository/MarkerRepository.java @@ -5,7 +5,7 @@ import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.marker.domain.Marker; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/org/findy/findy_be/place/application/find/FindPlace.java b/src/main/java/org/findy/findy_be/place/application/find/FindPlace.java index a78f080..a964816 100644 --- a/src/main/java/org/findy/findy_be/place/application/find/FindPlace.java +++ b/src/main/java/org/findy/findy_be/place/application/find/FindPlace.java @@ -2,7 +2,7 @@ import java.util.Optional; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; public interface FindPlace { Optional invoke(final String title, final String roadAddress); diff --git a/src/main/java/org/findy/findy_be/place/application/find/FindPlaceService.java b/src/main/java/org/findy/findy_be/place/application/find/FindPlaceService.java index 8d173d8..e9346fa 100644 --- a/src/main/java/org/findy/findy_be/place/application/find/FindPlaceService.java +++ b/src/main/java/org/findy/findy_be/place/application/find/FindPlaceService.java @@ -2,7 +2,7 @@ import java.util.Optional; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/org/findy/findy_be/marker/application/domain/MajorCategory.java b/src/main/java/org/findy/findy_be/place/domain/MajorCategory.java similarity index 90% rename from src/main/java/org/findy/findy_be/marker/application/domain/MajorCategory.java rename to src/main/java/org/findy/findy_be/place/domain/MajorCategory.java index 13d6fb0..d8d1589 100644 --- a/src/main/java/org/findy/findy_be/marker/application/domain/MajorCategory.java +++ b/src/main/java/org/findy/findy_be/place/domain/MajorCategory.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.marker.application.domain; +package org.findy.findy_be.place.domain; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; diff --git a/src/main/java/org/findy/findy_be/marker/application/domain/MiddleCategory.java b/src/main/java/org/findy/findy_be/place/domain/MiddleCategory.java similarity index 99% rename from src/main/java/org/findy/findy_be/marker/application/domain/MiddleCategory.java rename to src/main/java/org/findy/findy_be/place/domain/MiddleCategory.java index a044ba7..01021ee 100644 --- a/src/main/java/org/findy/findy_be/marker/application/domain/MiddleCategory.java +++ b/src/main/java/org/findy/findy_be/place/domain/MiddleCategory.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.marker.application.domain; +package org.findy.findy_be.place.domain; import java.util.Arrays; import java.util.Optional; diff --git a/src/main/java/org/findy/findy_be/marker/application/domain/Place.java b/src/main/java/org/findy/findy_be/place/domain/Place.java similarity index 71% rename from src/main/java/org/findy/findy_be/marker/application/domain/Place.java rename to src/main/java/org/findy/findy_be/place/domain/Place.java index 656b1d4..78d75eb 100644 --- a/src/main/java/org/findy/findy_be/marker/application/domain/Place.java +++ b/src/main/java/org/findy/findy_be/place/domain/Place.java @@ -1,9 +1,11 @@ -package org.findy.findy_be.marker.application.domain; +package org.findy.findy_be.place.domain; + +import java.util.Objects; import org.findy.findy_be.common.entity.BaseTimeEntity; -import org.findy.findy_be.marker.application.domain.vo.Category; -import org.findy.findy_be.marker.application.domain.vo.Coordinate; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; +import org.findy.findy_be.place.domain.vo.Category; +import org.findy.findy_be.place.domain.vo.Coordinate; import jakarta.persistence.Column; import jakarta.persistence.Embedded; @@ -54,7 +56,7 @@ public class Place extends BaseTimeEntity { @Embedded private Category category; - public static Place create(final RegisterMarkerRequest request) { + public static Place create(final RegisterYouTubeMarkerRequest request) { Coordinate coordinate = Coordinate.of(request.mapX(), request.mapY()); Category category = Category.of(request.category().majorCategory(), request.category().middleCategory()); return Place.builder() @@ -67,4 +69,20 @@ public static Place create(final RegisterMarkerRequest request) { .title(request.title()) .build(); } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Place place = (Place)o; + return Objects.equals(title, place.title) && + Objects.equals(roadAddress, place.roadAddress); + } + + @Override + public int hashCode() { + return Objects.hash(title, roadAddress); + } } diff --git a/src/main/java/org/findy/findy_be/marker/application/domain/vo/Category.java b/src/main/java/org/findy/findy_be/place/domain/vo/Category.java similarity index 78% rename from src/main/java/org/findy/findy_be/marker/application/domain/vo/Category.java rename to src/main/java/org/findy/findy_be/place/domain/vo/Category.java index 86a61aa..5a30bc9 100644 --- a/src/main/java/org/findy/findy_be/marker/application/domain/vo/Category.java +++ b/src/main/java/org/findy/findy_be/place/domain/vo/Category.java @@ -1,7 +1,7 @@ -package org.findy.findy_be.marker.application.domain.vo; +package org.findy.findy_be.place.domain.vo; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.MiddleCategory; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; diff --git a/src/main/java/org/findy/findy_be/marker/application/domain/vo/Coordinate.java b/src/main/java/org/findy/findy_be/place/domain/vo/Coordinate.java similarity index 93% rename from src/main/java/org/findy/findy_be/marker/application/domain/vo/Coordinate.java rename to src/main/java/org/findy/findy_be/place/domain/vo/Coordinate.java index a96df21..479233c 100644 --- a/src/main/java/org/findy/findy_be/marker/application/domain/vo/Coordinate.java +++ b/src/main/java/org/findy/findy_be/place/domain/vo/Coordinate.java @@ -1,4 +1,4 @@ -package org.findy.findy_be.marker.application.domain.vo; +package org.findy.findy_be.place.domain.vo; import java.util.Objects; diff --git a/src/main/java/org/findy/findy_be/place/dto/response/PlaceResponse.java b/src/main/java/org/findy/findy_be/place/dto/response/PlaceResponse.java index 1774216..a14169f 100644 --- a/src/main/java/org/findy/findy_be/place/dto/response/PlaceResponse.java +++ b/src/main/java/org/findy/findy_be/place/dto/response/PlaceResponse.java @@ -1,7 +1,7 @@ package org.findy.findy_be.place.dto.response; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.Place; import lombok.Builder; diff --git a/src/main/java/org/findy/findy_be/place/repository/PlaceRepository.java b/src/main/java/org/findy/findy_be/place/repository/PlaceRepository.java index 73f43cc..faa0d3a 100644 --- a/src/main/java/org/findy/findy_be/place/repository/PlaceRepository.java +++ b/src/main/java/org/findy/findy_be/place/repository/PlaceRepository.java @@ -2,7 +2,7 @@ import java.util.Optional; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; diff --git a/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustom.java b/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustom.java index 6f20dcf..d0676e5 100644 --- a/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustom.java +++ b/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustom.java @@ -1,6 +1,6 @@ package org.findy.findy_be.place.repository; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; diff --git a/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImpl.java b/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImpl.java index a1f29e2..6c59284 100644 --- a/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImpl.java +++ b/src/main/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImpl.java @@ -4,7 +4,7 @@ import org.findy.findy_be.bookmark.domain.QBookmark; import org.findy.findy_be.marker.domain.QMarker; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.place.domain.QPlace; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; diff --git a/src/main/java/org/findy/findy_be/place/utils/CategoryResolver.java b/src/main/java/org/findy/findy_be/place/utils/CategoryResolver.java index ba4b9f6..a32cbaf 100644 --- a/src/main/java/org/findy/findy_be/place/utils/CategoryResolver.java +++ b/src/main/java/org/findy/findy_be/place/utils/CategoryResolver.java @@ -2,8 +2,8 @@ import static org.findy.findy_be.common.exception.ErrorCode.*; -import org.findy.findy_be.marker.application.domain.MiddleCategory; -import org.findy.findy_be.marker.application.domain.vo.Category; +import org.findy.findy_be.place.domain.MiddleCategory; +import org.findy.findy_be.place.domain.vo.Category; public class CategoryResolver { diff --git a/src/test/java/org/findy/findy_be/bookmark/api/BookmarkControllerTest.java b/src/test/java/org/findy/findy_be/bookmark/api/BookmarkControllerTest.java index d959f15..a3a21ac 100644 --- a/src/test/java/org/findy/findy_be/bookmark/api/BookmarkControllerTest.java +++ b/src/test/java/org/findy/findy_be/bookmark/api/BookmarkControllerTest.java @@ -20,10 +20,10 @@ import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.common.IntegrationTest; import org.findy.findy_be.common.dto.pagination.request.PagedRequest; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.MiddleCategory; import org.findy.findy_be.marker.dto.request.CategoryRequest; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; import org.findy.findy_be.user.domain.RoleType; import org.findy.findy_be.user.domain.User; import org.findy.findy_be.user.repository.UserRepository; @@ -75,9 +75,10 @@ void setUp() { void 유튜브_북마크_등록_성공() throws Exception { // given CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); - List selectedPlaces = List.of( - new RegisterMarkerRequest("Place1", "Description1", "Address1", "RoadAddress1", categoryRequest, "12345", - "67890", "02-000-0000")); + List selectedPlaces = List.of( + new RegisterYouTubeMarkerRequest("Place1", "Description1", "Address1", "RoadAddress1", categoryRequest, + "12345", + "67890", "02-000-0000", "0.04")); RegisterYoutubeBookmarkRequest request = new RegisterYoutubeBookmarkRequest( "@iammingki", "걍밍경", "https://yt3.googleusercontent.com/ytc/...", "https://www.youtube.com/watch?v=hE2wMo5Coco", selectedPlaces); diff --git a/src/test/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkServiceTest.java b/src/test/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkServiceTest.java index f4b2b05..61000a5 100644 --- a/src/test/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkServiceTest.java +++ b/src/test/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkServiceTest.java @@ -11,10 +11,10 @@ import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.common.MockTest; import org.findy.findy_be.marker.application.register.BatchRegisterMarkerService; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.MiddleCategory; import org.findy.findy_be.marker.dto.request.CategoryRequest; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; import org.findy.findy_be.user.domain.User; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -36,20 +36,25 @@ class RegisterYoutubeBookmarkServiceTest extends MockTest { private User testUser; private RegisterYoutubeBookmarkRequest request; - private List selectedPlaces; + private List selectedPlaces; @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); testUser = mock(User.class); when(testUser.getUserId()).thenReturn("N49sfgdahdKz_fp-223424er1N3D6kd"); + CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); selectedPlaces = List.of( - new RegisterMarkerRequest("Place1", "Description1", "Address1", "RoadAddress1", categoryRequest, "12345", - "67890", "02-000-0000")); - - request = new RegisterYoutubeBookmarkRequest("@iammingki", "걍밍경", "https://yt3.googleusercontent.com/ytc/...", + new RegisterYouTubeMarkerRequest("Place1", "Description1", "Address1", "RoadAddress1", categoryRequest, + "12345", "67890", "02-000-0000", "0.04") + ); + request = new RegisterYoutubeBookmarkRequest("@iammingki", "걍밍경", + "https://yt3.googleusercontent.com/ytc/...", "https://www.youtube.com/watch?v=hE2wMo5Coco", selectedPlaces); + + Bookmark newBookmark = mock(Bookmark.class); + when(bookmarkRepository.save(any(Bookmark.class))).thenReturn(newBookmark); } @DisplayName("[성공] 새로운 유튜브 북마크 생성") diff --git a/src/test/java/org/findy/findy_be/common/repository/BulkInsertRepositoryImplTest.java b/src/test/java/org/findy/findy_be/common/repository/BulkInsertRepositoryImplTest.java index 078677c..41ffed3 100644 --- a/src/test/java/org/findy/findy_be/common/repository/BulkInsertRepositoryImplTest.java +++ b/src/test/java/org/findy/findy_be/common/repository/BulkInsertRepositoryImplTest.java @@ -5,11 +5,11 @@ import java.util.stream.IntStream; import org.findy.findy_be.common.RepositoryTest; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.MiddleCategory; -import org.findy.findy_be.marker.application.domain.Place; import org.findy.findy_be.marker.dto.request.CategoryRequest; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; @@ -38,7 +38,7 @@ void tearDown() { private List generateTestPlaces(int entityCount) { CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); return IntStream.range(0, entityCount) - .mapToObj(i -> new RegisterMarkerRequest( + .mapToObj(i -> new RegisterYouTubeMarkerRequest( "Test Place " + i, "Description " + i, "02-1234-5678", @@ -46,8 +46,8 @@ private List generateTestPlaces(int entityCount) { categoryRequest, "1269827323", "375719345", - "02-000-000" - + "02-000-000", + "0.04" )) .map(Place::create) .collect(Collectors.toList()); diff --git a/src/test/java/org/findy/findy_be/marker/api/MarkerControllerTest.java b/src/test/java/org/findy/findy_be/marker/api/MarkerControllerTest.java index 5db9341..d17b76e 100644 --- a/src/test/java/org/findy/findy_be/marker/api/MarkerControllerTest.java +++ b/src/test/java/org/findy/findy_be/marker/api/MarkerControllerTest.java @@ -20,7 +20,7 @@ import org.findy.findy_be.marker.domain.Marker; import org.findy.findy_be.marker.dto.request.RegisterSearchedMarkerRequest; import org.findy.findy_be.marker.repository.MarkerRepository; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.findy.findy_be.user.domain.RoleType; import org.findy.findy_be.user.domain.User; @@ -199,7 +199,7 @@ void setUp() { } private ResultActions GetBookmarks(final Long bookmarkId, final PagedRequest pagedRequest) throws Exception { - return mvc.perform((get("/api/places/{bookmarkId}", bookmarkId) + return mvc.perform((get("/api/markers/{bookmarkId}", bookmarkId) .param("cursor", pagedRequest.cursor() == null ? "" : pagedRequest.cursor().toString()) .param("size", String.valueOf(pagedRequest.size())) .contentType(MediaType.APPLICATION_JSON))) @@ -209,7 +209,7 @@ private ResultActions GetBookmarks(final Long bookmarkId, final PagedRequest pag private ResultActions PostSearchedPlace(final Long bookmarkId, final RegisterSearchedMarkerRequest request) throws Exception { - return mvc.perform(post("/api/places/{bookmarkId}", bookmarkId) + return mvc.perform(post("/api/markers/{bookmarkId}", bookmarkId) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(request))) .andDo(print()); diff --git a/src/test/java/org/findy/findy_be/marker/application/create/BatchCreateMarkerServiceTest.java b/src/test/java/org/findy/findy_be/marker/application/create/BatchCreateMarkerServiceTest.java index 5098cc5..369e471 100644 --- a/src/test/java/org/findy/findy_be/marker/application/create/BatchCreateMarkerServiceTest.java +++ b/src/test/java/org/findy/findy_be/marker/application/create/BatchCreateMarkerServiceTest.java @@ -12,8 +12,12 @@ import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.common.MockTest; import org.findy.findy_be.marker.domain.Marker; +import org.findy.findy_be.marker.dto.request.CategoryRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; import org.findy.findy_be.marker.repository.MarkerRepository; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; +import org.findy.findy_be.place.domain.Place; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -35,13 +39,31 @@ class BatchCreateMarkerServiceTest extends MockTest { private Bookmark testBookmark; private Place place1; private Place place2; + private List requests; @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); testBookmark = mock(Bookmark.class); + place1 = mock(Place.class); + when(place1.getTitle()).thenReturn("Place1"); + when(place1.getRoadAddress()).thenReturn("RoadAddress1"); + place2 = mock(Place.class); + when(place2.getTitle()).thenReturn("Place2"); + when(place2.getRoadAddress()).thenReturn("RoadAddress2"); + + CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); + RegisterYouTubeMarkerRequest request1 = new RegisterYouTubeMarkerRequest( + "Place1", "Description1", "Address1", "RoadAddress1", categoryRequest, + "12345", "67890", "02-000-0000", "0.04" + ); + RegisterYouTubeMarkerRequest request2 = new RegisterYouTubeMarkerRequest( + "Place2", "Description2", "Address2", "RoadAddress2", categoryRequest, + "54321", "09876", "02-000-0001", "0.04" + ); + requests = Arrays.asList(request1, request2); } @DisplayName("[성공] 새로운 장소에 대한 마커 생성되고 마킹된 장소 수가 업데이트") @@ -55,7 +77,7 @@ void setUp() { .thenReturn(List.of()); // when - batchCreateMarkerService.invoke(testBookmark, places); + batchCreateMarkerService.invoke(testBookmark, places, requests); // then verify(markerRepository, times(1)).saveAll(anyList()); @@ -75,7 +97,7 @@ void setUp() { .thenReturn(List.of(existingMarker)); // when - batchCreateMarkerService.invoke(testBookmark, places); + batchCreateMarkerService.invoke(testBookmark, places, requests); // then verify(markerRepository, times(1)).saveAll(anyList()); diff --git a/src/test/java/org/findy/findy_be/marker/application/create/CreateMarkerServiceTest.java b/src/test/java/org/findy/findy_be/marker/application/create/CreateMarkerServiceTest.java index 132adad..b7516a5 100644 --- a/src/test/java/org/findy/findy_be/marker/application/create/CreateMarkerServiceTest.java +++ b/src/test/java/org/findy/findy_be/marker/application/create/CreateMarkerServiceTest.java @@ -9,7 +9,7 @@ import org.findy.findy_be.common.MockTest; import org.findy.findy_be.marker.domain.Marker; import org.findy.findy_be.marker.repository.MarkerRepository; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersServiceTest.java b/src/test/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersServiceTest.java index f1b4d09..4a4ab6b 100644 --- a/src/test/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersServiceTest.java +++ b/src/test/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersServiceTest.java @@ -9,11 +9,11 @@ import org.findy.findy_be.common.MockTest; import org.findy.findy_be.common.dto.pagination.response.SliceResponse; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.MiddleCategory; -import org.findy.findy_be.marker.application.domain.Place; import org.findy.findy_be.marker.dto.request.CategoryRequest; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.place.dto.response.PlaceResponse; import org.findy.findy_be.place.repository.PlaceRepository; import org.findy.findy_be.user.domain.User; @@ -45,7 +45,7 @@ public void setUp() throws Exception { testUser = mock(User.class); CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); places = IntStream.range(0, 5) - .mapToObj(i -> new RegisterMarkerRequest( + .mapToObj(i -> new RegisterYouTubeMarkerRequest( "Test Place " + i, "Description " + i, "02-1234-5678", @@ -53,8 +53,8 @@ public void setUp() throws Exception { categoryRequest, "1269827323", "375719345", - "02-000-000" - + "02-000-000", + "0.04" )) .map(Place::create) .collect(Collectors.toList()); diff --git a/src/test/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerServiceTest.java b/src/test/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerServiceTest.java index cbb395c..a0b6c31 100644 --- a/src/test/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerServiceTest.java +++ b/src/test/java/org/findy/findy_be/marker/application/register/BatchRegisterMarkerServiceTest.java @@ -10,12 +10,12 @@ import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.common.MockTest; import org.findy.findy_be.marker.application.create.BatchCreateMarkerService; -import org.findy.findy_be.place.application.find.FindPlaceService; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.MiddleCategory; -import org.findy.findy_be.marker.application.domain.Place; import org.findy.findy_be.marker.dto.request.CategoryRequest; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; +import org.findy.findy_be.place.application.find.FindPlaceService; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -39,8 +39,8 @@ class BatchRegisterMarkerServiceTest extends MockTest { private BatchRegisterMarkerService batchRegisterMarkerService; private Bookmark testBookmark; - private RegisterMarkerRequest request1; - private RegisterMarkerRequest request2; + private RegisterYouTubeMarkerRequest request1; + private RegisterYouTubeMarkerRequest request2; private Place place1; private Place place2; @@ -49,9 +49,11 @@ void setUp() { MockitoAnnotations.openMocks(this); testBookmark = mock(Bookmark.class); CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); - request1 = new RegisterMarkerRequest("Place1", "Description1", "Address1", "RoadAddress1", categoryRequest, + request1 = new RegisterYouTubeMarkerRequest("Place1", "Description1", "Address1", "RoadAddress1", + categoryRequest, "12345", "67890", "02-000-0000", "0.04"); - request2 = new RegisterMarkerRequest("Place2", "Description2", "Address2", "RoadAddress2", categoryRequest, + request2 = new RegisterYouTubeMarkerRequest("Place2", "Description2", "Address2", "RoadAddress2", + categoryRequest, "54321", "09876", "02-000-0001", "0.04"); place1 = mock(Place.class); place2 = mock(Place.class); @@ -61,7 +63,7 @@ void setUp() { @Test void 새로운_장소_모두_등록_및_마커_생성() { // given - List requests = Arrays.asList(request1, request2); + List requests = Arrays.asList(request1, request2); when(findPlace.invoke(request1.title(), request1.roadAddress())).thenReturn(Optional.empty()); when(findPlace.invoke(request2.title(), request2.roadAddress())).thenReturn(Optional.empty()); @@ -72,14 +74,14 @@ void setUp() { // then verify(placeRepository, times(1)).saveAll(anyList()); - verify(batchCreateMarker, times(1)).invoke(testBookmark, Arrays.asList(place1, place2)); + verify(batchCreateMarker, times(1)).invoke(testBookmark, Arrays.asList(place1, place2), requests); } @DisplayName("[성공 case2] 일부 장소는 이미 등록되어 새로 등록되지 않음") @Test void 이미_등록된_장소_새로_등록되지_않음() { // given - List requests = Arrays.asList(request1, request2); + List requests = Arrays.asList(request1, request2); when(findPlace.invoke(request1.title(), request1.roadAddress())).thenReturn(Optional.empty()); when(findPlace.invoke(request2.title(), request2.roadAddress())).thenReturn(Optional.of(place2)); @@ -90,15 +92,18 @@ void setUp() { // then verify(placeRepository, times(1)).saveAll(anyList()); - verify(batchCreateMarker, times(1)).invoke(eq(testBookmark), - argThat(list -> list.contains(place1) && list.contains(place2))); + verify(batchCreateMarker, times(1)).invoke( + eq(testBookmark), + argThat(list -> list.contains(place1) && list.contains(place2)), + eq(requests) + ); } @DisplayName("[성공 case3] 단일 장소가 등록되고 마커가 생성됨") @Test void 단일_장소_등록_및_마커_생성() { // given - List requests = Arrays.asList(request1); + List requests = Arrays.asList(request1); when(findPlace.invoke(request1.title(), request1.roadAddress())).thenReturn(Optional.empty()); when(placeRepository.saveAll(anyList())).thenReturn(Arrays.asList(place1)); @@ -108,6 +113,6 @@ void setUp() { // then verify(placeRepository, times(1)).saveAll(anyList()); - verify(batchCreateMarker, times(1)).invoke(testBookmark, Arrays.asList(place1)); + verify(batchCreateMarker, times(1)).invoke(testBookmark, Arrays.asList(place1), requests); } } diff --git a/src/test/java/org/findy/findy_be/marker/application/register/RegisterMarkerServiceTest.java b/src/test/java/org/findy/findy_be/marker/application/register/RegisterMarkerServiceTest.java index 982ba7a..b53f374 100644 --- a/src/test/java/org/findy/findy_be/marker/application/register/RegisterMarkerServiceTest.java +++ b/src/test/java/org/findy/findy_be/marker/application/register/RegisterMarkerServiceTest.java @@ -16,7 +16,7 @@ import org.findy.findy_be.marker.application.create.CreateMarker; import org.findy.findy_be.marker.dto.request.RegisterSearchedMarkerRequest; import org.findy.findy_be.place.application.find.FindPlace; -import org.findy.findy_be.marker.application.domain.Place; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.findy.findy_be.user.domain.RoleType; import org.findy.findy_be.user.domain.User; diff --git a/src/test/java/org/findy/findy_be/marker/repository/MarkerRepositoryTest.java b/src/test/java/org/findy/findy_be/marker/repository/MarkerRepositoryTest.java index 50c8186..927f030 100644 --- a/src/test/java/org/findy/findy_be/marker/repository/MarkerRepositoryTest.java +++ b/src/test/java/org/findy/findy_be/marker/repository/MarkerRepositoryTest.java @@ -11,11 +11,11 @@ import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.common.RepositoryTest; import org.findy.findy_be.marker.domain.Marker; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.MiddleCategory; -import org.findy.findy_be.marker.application.domain.Place; import org.findy.findy_be.marker.dto.request.CategoryRequest; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.findy.findy_be.user.domain.RoleType; import org.findy.findy_be.user.domain.User; @@ -51,7 +51,7 @@ void setUp() { LocalDateTime.now(), LocalDateTime.now())); CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); - RegisterMarkerRequest request = new RegisterMarkerRequest( + RegisterYouTubeMarkerRequest request = new RegisterYouTubeMarkerRequest( "동대문엽기떡볶이 종각점", "설명", "서울특별시 종로구 공평동 124", @@ -59,7 +59,8 @@ void setUp() { categoryRequest, "1269827323", "375719345", - "02-000-000" + "02-000-000", + "0.04" ); testPlace = placeRepository.save(Place.create(request)); testBookmark = bookmarkRepository.save(Bookmark.of("서촌", BookmarkType.CUSTOM, null, null, null, testUser)); diff --git a/src/test/java/org/findy/findy_be/place/application/find/FindPlaceServiceTest.java b/src/test/java/org/findy/findy_be/place/application/find/FindPlaceServiceTest.java index fce362e..cc1a2b7 100644 --- a/src/test/java/org/findy/findy_be/place/application/find/FindPlaceServiceTest.java +++ b/src/test/java/org/findy/findy_be/place/application/find/FindPlaceServiceTest.java @@ -6,11 +6,11 @@ import java.util.Optional; import org.findy.findy_be.common.MockTest; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.MiddleCategory; -import org.findy.findy_be.marker.application.domain.Place; import org.findy.findy_be.marker.dto.request.CategoryRequest; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.place.repository.PlaceRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -27,14 +27,14 @@ class FindPlaceServiceTest extends MockTest { @InjectMocks private FindPlaceService findPlaceService; - private RegisterMarkerRequest placeRequest; + private RegisterYouTubeMarkerRequest placeRequest; private Place place; @BeforeEach void setUp() { MockitoAnnotations.openMocks(this); CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); - placeRequest = new RegisterMarkerRequest( + placeRequest = new RegisterYouTubeMarkerRequest( "동대문엽기떡볶이 종각점", "설명", "서울특별시 종로구 공평동 124", @@ -42,7 +42,8 @@ void setUp() { categoryRequest, "1269827323", "375719345", - "02-000-000" + "02-000-000", + "0.04" ); place = mock(Place.class); } diff --git a/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImplTest.java b/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImplTest.java index 0d558a7..d180ab3 100644 --- a/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImplTest.java +++ b/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryCustomImplTest.java @@ -12,12 +12,12 @@ import org.findy.findy_be.bookmark.repository.BookmarkRepository; import org.findy.findy_be.common.RepositoryTest; import org.findy.findy_be.marker.domain.Marker; -import org.findy.findy_be.marker.repository.MarkerRepository; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.MiddleCategory; -import org.findy.findy_be.marker.application.domain.Place; import org.findy.findy_be.marker.dto.request.CategoryRequest; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; +import org.findy.findy_be.marker.repository.MarkerRepository; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.user.domain.RoleType; import org.findy.findy_be.user.domain.User; import org.findy.findy_be.user.repository.UserRepository; @@ -100,7 +100,7 @@ void setUp() { private void initPlacesForBookmark(Bookmark bookmark, int count) { List places = IntStream.rangeClosed(1, count) - .mapToObj(i -> Place.create(new RegisterMarkerRequest( + .mapToObj(i -> Place.create(new RegisterYouTubeMarkerRequest( "Test Place " + i, "Description " + i, "Address " + i, @@ -108,7 +108,8 @@ private void initPlacesForBookmark(Bookmark bookmark, int count) { new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN), "1269827323", "375719345", - "02-000-000" + i + "02-000-000" + i, + "0.04" ))) .collect(Collectors.toList()); diff --git a/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryTest.java b/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryTest.java index 1061bd1..dc0fdc0 100644 --- a/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryTest.java +++ b/src/test/java/org/findy/findy_be/place/repository/PlaceRepositoryTest.java @@ -8,11 +8,11 @@ import java.util.stream.IntStream; import org.findy.findy_be.common.RepositoryTest; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.MiddleCategory; -import org.findy.findy_be.marker.application.domain.Place; import org.findy.findy_be.marker.dto.request.CategoryRequest; -import org.findy.findy_be.marker.dto.request.RegisterMarkerRequest; +import org.findy.findy_be.marker.dto.request.RegisterYouTubeMarkerRequest; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; +import org.findy.findy_be.place.domain.Place; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -28,7 +28,7 @@ class PlaceRepositoryTest extends RepositoryTest { void 주어진_상세_정보로_장소_조회() { // given CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); - RegisterMarkerRequest request = new RegisterMarkerRequest( + RegisterYouTubeMarkerRequest request = new RegisterYouTubeMarkerRequest( "동대문엽기떡볶이 종각점", "설명", "서울특별시 종로구 공평동 124", @@ -36,7 +36,8 @@ class PlaceRepositoryTest extends RepositoryTest { categoryRequest, "1269827323", "375719345", - "02-000-000" + "02-000-000", + "0.04" ); Place savedPlace = placeRepository.save(Place.create(request)); @@ -70,7 +71,7 @@ class PlaceRepositoryTest extends RepositoryTest { // given CategoryRequest categoryRequest = new CategoryRequest(MajorCategory.RESTAURANT, MiddleCategory.KOREAN); List places = IntStream.range(0, 100) - .mapToObj(i -> Place.create(new RegisterMarkerRequest( + .mapToObj(i -> Place.create(new RegisterYouTubeMarkerRequest( "Test Place " + i, "Description " + i, "02-1234-5678", @@ -78,8 +79,8 @@ class PlaceRepositoryTest extends RepositoryTest { categoryRequest, "1269827323", "375719345", - "02-000-000" - + "02-000-000", + "0.04" ) )).collect(Collectors.toList()); diff --git a/src/test/java/org/findy/findy_be/place/utils/CategoryResolverTest.java b/src/test/java/org/findy/findy_be/place/utils/CategoryResolverTest.java index 18343ae..cfad012 100644 --- a/src/test/java/org/findy/findy_be/place/utils/CategoryResolverTest.java +++ b/src/test/java/org/findy/findy_be/place/utils/CategoryResolverTest.java @@ -3,9 +3,9 @@ import static org.junit.jupiter.api.Assertions.*; import org.findy.findy_be.common.exception.ErrorCode; -import org.findy.findy_be.marker.application.domain.MajorCategory; -import org.findy.findy_be.marker.application.domain.MiddleCategory; -import org.findy.findy_be.marker.application.domain.vo.Category; +import org.findy.findy_be.place.domain.MajorCategory; +import org.findy.findy_be.place.domain.MiddleCategory; +import org.findy.findy_be.place.domain.vo.Category; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; From 5c30227e45188cda24400bed0697a9e9af4c63dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Sun, 17 Nov 2024 13:45:19 +0900 Subject: [PATCH 05/10] =?UTF-8?q?refactor:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20label=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../find/FindAllPagedMarkersService.java | 4 +++- .../marker/dto/request/CategoryRequest.java | 4 ++-- .../findy_be/place/domain/MajorCategory.java | 18 ++++++++++++++++++ .../findy_be/place/domain/MiddleCategory.java | 16 ++++++++++++++++ .../place/dto/response/PlaceResponse.java | 6 +++--- src/main/resources/application-local.yml | 2 +- 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersService.java b/src/main/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersService.java index 4196c52..a8b7d07 100644 --- a/src/main/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersService.java +++ b/src/main/java/org/findy/findy_be/marker/application/find/FindAllPagedMarkersService.java @@ -3,10 +3,12 @@ import java.util.List; import org.findy.findy_be.common.dto.pagination.response.SliceResponse; +import org.findy.findy_be.place.domain.Place; import org.findy.findy_be.place.dto.response.PlaceResponse; import org.findy.findy_be.place.repository.PlaceRepository; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,7 +24,7 @@ public class FindAllPagedMarkersService implements FindAllPagedMarkers { public SliceResponse invoke(final String userId, final Long bookmarkId, final Long cursor, final int size) { Pageable pageable = PageRequest.of(0, size); - var placeSlice = placeRepository.findPlacesByUserIdAndBookmarkId(userId, bookmarkId, pageable, cursor); + Slice placeSlice = placeRepository.findPlacesByUserIdAndBookmarkId(userId, bookmarkId, pageable, cursor); List data = placeSlice.stream() .map(PlaceResponse::from) diff --git a/src/main/java/org/findy/findy_be/marker/dto/request/CategoryRequest.java b/src/main/java/org/findy/findy_be/marker/dto/request/CategoryRequest.java index b74dc46..35f215c 100644 --- a/src/main/java/org/findy/findy_be/marker/dto/request/CategoryRequest.java +++ b/src/main/java/org/findy/findy_be/marker/dto/request/CategoryRequest.java @@ -8,10 +8,10 @@ public record CategoryRequest( @NotNull(message = "대분류는 비어있을 수 없습니다.") - @Schema(description = "대분류", example = "RESTAURANT") + @Schema(description = "대분류", example = "음식점") MajorCategory majorCategory, - @Schema(description = "중분류", example = "KOREAN") + @Schema(description = "중분류", example = "한식") MiddleCategory middleCategory ) { } diff --git a/src/main/java/org/findy/findy_be/place/domain/MajorCategory.java b/src/main/java/org/findy/findy_be/place/domain/MajorCategory.java index d8d1589..9fb443d 100644 --- a/src/main/java/org/findy/findy_be/place/domain/MajorCategory.java +++ b/src/main/java/org/findy/findy_be/place/domain/MajorCategory.java @@ -1,5 +1,8 @@ package org.findy.findy_be.place.domain; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -19,4 +22,19 @@ public enum MajorCategory { OTHER("기타"); private final String label; + + @JsonValue + public String getLabel() { + return label; + } + + @JsonCreator + public static MajorCategory fromLabel(String label) { + for (MajorCategory category : values()) { + if (category.label.equals(label)) { + return category; + } + } + throw new IllegalArgumentException("잘못된 대분류입니다. 대분류: " + label); + } } \ No newline at end of file diff --git a/src/main/java/org/findy/findy_be/place/domain/MiddleCategory.java b/src/main/java/org/findy/findy_be/place/domain/MiddleCategory.java index 01021ee..f29afdb 100644 --- a/src/main/java/org/findy/findy_be/place/domain/MiddleCategory.java +++ b/src/main/java/org/findy/findy_be/place/domain/MiddleCategory.java @@ -3,6 +3,9 @@ import java.util.Arrays; import java.util.Optional; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -203,4 +206,17 @@ public static Optional findByLabel(String label) { public boolean matchesMajorCategoryLabel(String label) { return this.majorCategory.getLabel().equals(label); } + + @JsonValue + public String getLabel() { + return label; + } + + @JsonCreator + public static MiddleCategory fromLabel(String label) { + return Arrays.stream(MiddleCategory.values()) + .filter(category -> category.getLabel().equals(label)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("잘못된 중분류입니다. 중분류:" + label)); + } } \ No newline at end of file diff --git a/src/main/java/org/findy/findy_be/place/dto/response/PlaceResponse.java b/src/main/java/org/findy/findy_be/place/dto/response/PlaceResponse.java index a14169f..16726d5 100644 --- a/src/main/java/org/findy/findy_be/place/dto/response/PlaceResponse.java +++ b/src/main/java/org/findy/findy_be/place/dto/response/PlaceResponse.java @@ -1,7 +1,7 @@ package org.findy.findy_be.place.dto.response; -import org.findy.findy_be.place.domain.MajorCategory; import org.findy.findy_be.place.domain.Place; +import org.findy.findy_be.place.domain.vo.Category; import lombok.Builder; @@ -10,14 +10,14 @@ public record PlaceResponse( Long placeId, String title, String address, - MajorCategory majorCategory + Category category ) { public static PlaceResponse from(final Place place) { return PlaceResponse.builder() .placeId(place.getId()) .title(place.getTitle()) .address(place.getAddress()) - .majorCategory(place.getCategory().getMajorCategory()) + .category(place.getCategory()) .build(); } } diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 559bd1e..7a70417 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -12,7 +12,7 @@ spring: jpa: open-in-view: true hibernate: - ddl-auto: create + ddl-auto: validate show-sql: true properties: hibernate: From 3a06fdc9915153a67c60851bb35eb386d1a2a123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Sun, 17 Nov 2024 13:45:31 +0900 Subject: [PATCH 06/10] =?UTF-8?q?test:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20label=20=EB=B0=98=ED=99=98=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../place/domain/MajorCategoryTest.java | 47 ++++++++++++ .../place/domain/MiddleCategoryTest.java | 75 +++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 src/test/java/org/findy/findy_be/place/domain/MajorCategoryTest.java create mode 100644 src/test/java/org/findy/findy_be/place/domain/MiddleCategoryTest.java diff --git a/src/test/java/org/findy/findy_be/place/domain/MajorCategoryTest.java b/src/test/java/org/findy/findy_be/place/domain/MajorCategoryTest.java new file mode 100644 index 0000000..c2ada90 --- /dev/null +++ b/src/test/java/org/findy/findy_be/place/domain/MajorCategoryTest.java @@ -0,0 +1,47 @@ +package org.findy.findy_be.place.domain; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class MajorCategoryTest { + + @DisplayName("[성공] 문자열로 대분류를 Enum으로 변환") + @Test + void fromLabel_성공() { + // given + String label = "음식점"; + + // when + MajorCategory category = MajorCategory.fromLabel(label); + + // then + assertThat(category).isEqualTo(MajorCategory.RESTAURANT); + } + + @DisplayName("[실패] 존재하지 않는 문자열로 Enum 변환 시 예외 발생") + @Test + void fromLabel_실패_예외발생() { + // given + String invalidLabel = "잘못된값"; + + // when & then + assertThatThrownBy(() -> MajorCategory.fromLabel(invalidLabel)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("잘못된 대분류입니다. 대분류: " + invalidLabel); + } + + @DisplayName("[성공] Enum을 문자열로 변환") + @Test + void getLabel_성공() { + // given + MajorCategory category = MajorCategory.RESTAURANT; + + // when + String label = category.getLabel(); + + // then + assertThat(label).isEqualTo("음식점"); + } +} diff --git a/src/test/java/org/findy/findy_be/place/domain/MiddleCategoryTest.java b/src/test/java/org/findy/findy_be/place/domain/MiddleCategoryTest.java new file mode 100644 index 0000000..42e6e1d --- /dev/null +++ b/src/test/java/org/findy/findy_be/place/domain/MiddleCategoryTest.java @@ -0,0 +1,75 @@ +package org.findy.findy_be.place.domain; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class MiddleCategoryTest { + + @DisplayName("[성공] 중분류 라벨로 Enum을 찾을 수 있음") + @Test + void fromLabel_성공() { + // given + String label = "한식"; + + // when + MiddleCategory category = MiddleCategory.fromLabel(label); + + // then + assertThat(category).isEqualTo(MiddleCategory.KOREAN); + } + + @DisplayName("[실패] 존재하지 않는 라벨로 Enum 찾기 시 예외 발생") + @Test + void fromLabel_실패_예외발생() { + // given + String invalidLabel = "없는중분류"; + + // when & then + assertThatThrownBy(() -> MiddleCategory.fromLabel(invalidLabel)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("잘못된 중분류입니다. 중분류:" + invalidLabel); + } + + @DisplayName("[성공] Enum 값을 라벨로 변환") + @Test + void getLabel_성공() { + // given + MiddleCategory category = MiddleCategory.KOREAN; + + // when + String label = category.getLabel(); + + // then + assertThat(label).isEqualTo("한식"); + } + + @DisplayName("[성공] 중분류의 MajorCategory 라벨과 일치하는지 확인") + @Test + void matchesMajorCategoryLabel_성공() { + // given + MiddleCategory category = MiddleCategory.KOREAN; + String majorLabel = "음식점"; + + // when + boolean matches = category.matchesMajorCategoryLabel(majorLabel); + + // then + assertThat(matches).isTrue(); + } + + @DisplayName("[실패] 중분류의 MajorCategory 라벨이 일치하지 않음") + @Test + void matchesMajorCategoryLabel_실패() { + // given + MiddleCategory category = MiddleCategory.KOREAN; + String incorrectMajorLabel = "카페,디저트"; + + // when + boolean matches = category.matchesMajorCategoryLabel(incorrectMajorLabel); + + // then + assertThat(matches).isFalse(); + } +} From 5b946a689b04397bbdaf1626fd7e7822f52f26fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Sun, 17 Nov 2024 13:51:14 +0900 Subject: [PATCH 07/10] refactor: marker refactoring --- .../marker/dto/request/RegisterYouTubeMarkerRequest.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/org/findy/findy_be/marker/dto/request/RegisterYouTubeMarkerRequest.java b/src/main/java/org/findy/findy_be/marker/dto/request/RegisterYouTubeMarkerRequest.java index c04a4c5..baeea46 100644 --- a/src/main/java/org/findy/findy_be/marker/dto/request/RegisterYouTubeMarkerRequest.java +++ b/src/main/java/org/findy/findy_be/marker/dto/request/RegisterYouTubeMarkerRequest.java @@ -1,7 +1,5 @@ package org.findy.findy_be.marker.dto.request; -import org.findy.findy_be.bookmark.domain.Bookmark; -import org.findy.findy_be.marker.domain.Marker; import org.findy.findy_be.place.domain.Place; import io.swagger.v3.oas.annotations.media.Schema; @@ -45,9 +43,4 @@ public record RegisterYouTubeMarkerRequest( public Place toPlaceEntity() { return Place.create(this); } - - public Marker toMarkerEntity(Bookmark bookmark) { - Place place = toPlaceEntity(); - return Marker.createForYoutubeBookmark(timestamp, bookmark, place); - } } \ No newline at end of file From 6562301f2381d38ed2278f64d89574bdac72b438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Sun, 17 Nov 2024 14:07:13 +0900 Subject: [PATCH 08/10] refactor: marker refactoring --- .../marker/application/register/PlaceWithTimestamp.java | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 src/main/java/org/findy/findy_be/marker/application/register/PlaceWithTimestamp.java diff --git a/src/main/java/org/findy/findy_be/marker/application/register/PlaceWithTimestamp.java b/src/main/java/org/findy/findy_be/marker/application/register/PlaceWithTimestamp.java deleted file mode 100644 index 8f106e2..0000000 --- a/src/main/java/org/findy/findy_be/marker/application/register/PlaceWithTimestamp.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.findy.findy_be.marker.application.register; - -import org.findy.findy_be.place.domain.Place; - -public record PlaceWithTimestamp( - Place place, - String timestamp -) { -} From 2461913d42ba58277b1b265400d72fc14f7685d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Sun, 17 Nov 2024 14:10:15 +0900 Subject: [PATCH 09/10] refactor: marker refactoring --- .../findy/findy_be/marker/domain/Marker.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/main/java/org/findy/findy_be/marker/domain/Marker.java b/src/main/java/org/findy/findy_be/marker/domain/Marker.java index 9d02663..0b47b6b 100644 --- a/src/main/java/org/findy/findy_be/marker/domain/Marker.java +++ b/src/main/java/org/findy/findy_be/marker/domain/Marker.java @@ -1,7 +1,5 @@ package org.findy.findy_be.marker.domain; -import java.util.Objects; - import org.findy.findy_be.bookmark.domain.Bookmark; import org.findy.findy_be.common.entity.BaseTimeEntity; import org.findy.findy_be.place.domain.Place; @@ -63,20 +61,4 @@ public static Marker createForYoutubeBookmark(final String timestamp, final Book .bookmark(bookmark) .build(); } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - Marker marker = (Marker)o; - return Objects.equals(id, marker.id); - } - - @Override - public int hashCode() { - return Objects.hash(id); - } - } From 08d97fc99dd25ada690d3346e3918880cace3a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Sun, 17 Nov 2024 14:10:20 +0900 Subject: [PATCH 10/10] refactor: place refactoring --- src/main/java/org/findy/findy_be/place/domain/Place.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/org/findy/findy_be/place/domain/Place.java b/src/main/java/org/findy/findy_be/place/domain/Place.java index 78d75eb..517daab 100644 --- a/src/main/java/org/findy/findy_be/place/domain/Place.java +++ b/src/main/java/org/findy/findy_be/place/domain/Place.java @@ -77,12 +77,21 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; Place place = (Place)o; + + if (id != null && id.equals(place.id)) { + return true; + } + return Objects.equals(title, place.title) && Objects.equals(roadAddress, place.roadAddress); } @Override public int hashCode() { + if (id != null) { + return Objects.hash(id); + } + return Objects.hash(title, roadAddress); } }