From 7c303364f89e791bc69c7c9d9fffa661137f401d Mon Sep 17 00:00:00 2001 From: Lemonade255 Date: Mon, 20 Nov 2023 18:04:21 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat(BE):=20=EC=9C=84=EC=B9=98=20=EA=B8=B0?= =?UTF-8?q?=EC=A4=80=EC=9C=BC=EB=A1=9C=20=EB=A7=A4=EC=B9=AD=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20BUS-229-place-latitude-longitude=20#221?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/in/rest/MatchingController.java | 56 +++++++++++++++---- .../out/persistence/MatchingEntity.java | 6 ++ .../MatchingPersistenceAdapter.java | 5 ++ .../port/in/FindMatchingUsecase.java | 1 + .../port/out/FindMatchingPort.java | 1 + .../example/api/matching/domain/Matching.java | 2 + .../api/matching/dto/FindMatchingDto.java | 7 +++ .../api/matching/dto/SaveMatchingDto.java | 7 +++ .../repository/MatchingRepository.java | 1 + .../api/matching/service/MatchingService.java | 5 ++ 10 files changed, 80 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java index 9a1131f..5f7241b 100644 --- a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java +++ b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java @@ -11,7 +11,6 @@ import com.example.api.common.utils.AuthenticationUtils; import com.example.api.matching.adapter.out.persistence.MatchingMapperInterface; import com.example.api.matching.application.port.in.*; -import com.example.api.matching.domain.MatchingApplication; import com.example.api.matching.dto.*; import com.example.api.matching.type.MatchingTypeEnum; import com.example.api.member.application.port.in.AddMemberChatRoomUsecase; @@ -117,9 +116,7 @@ public void createMatchingApplication(@Valid @RequestBody SaveMatchingApplicatio throw new CustomException(ErrorCodeEnum.MATCHING_NOT_FOUND); } - MatchingApplication matchingApplication = matchingApplicationUsecase.createMatchingApplicationData(securityUser.getUserId(), matchingApplicationDto); - //ChatRoom chatRoom = createChatRoomUsecase.createMatchingChatRoom(matchingApplication); - //return addMemberChatRoomUsecase.setupMatchingChatRoom(matchingApplication, chatRoom); + matchingApplicationUsecase.createMatchingApplicationData(securityUser.getUserId(), matchingApplicationDto); } /** @@ -136,7 +133,11 @@ public List getAll() { } return findMatchingUsecase.getAll(); } - + + /** + * 식사 매칭 목록 조회 + * @return dining matching list + */ @Operation(summary = "Get all dining matching", description = "모든 식사 매칭 목록을 조회한다.") @GetMapping("/diningmatching") public List getDiningMatchingList() { @@ -186,16 +187,36 @@ public AccommodationMatchingDto getMatchingById(@PathVariable Long matchingId) { return matchingDto; } - @Operation(summary = "Get matching", description = "자기 자신의 매칭을 조회한다.") + /** + * 로그인한 사용자가 작성한 매칭 조회 + * @return own matching + */ + @Operation(summary = "Get own matching", description = "자기 자신의 매칭을 조회한다.") @GetMapping("/matching/my-matching") public List getMyMatching() { SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); if (securityUser == null) { - log.error("MatchingController::getMatchingById: Login is needed"); + log.error("MatchingController::getMyMatching: Login is needed"); throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); } return findMatchingUsecase.getMatchingByWriterId(securityUser.getUserId()); -// return findMatchingUsecase.getMatchingById(matchingId); + } + + /** + * 선택한 위치와 가까운 매칭 조회 + * @param latitude (위도) + * @param longitude (경도) + * @return near matching list + */ + @Operation(summary = "Get matching by place coordinate", description = "선택한 위치와 가까운 여행지의 매칭 목록을 조회한다.") + @GetMapping("/matching/nearfrom") + public List getNearMatching(Double latitude, Double longitude) { + SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); + if (securityUser == null) { + log.error("MatchingController::getNearMatching: Login is needed"); + throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); + } + return findMatchingUsecase.getNearMatching(latitude, longitude); } /** @@ -262,7 +283,11 @@ public int getLikeCount(@PathVariable Long matchingId) { } return likeUsecase.getLikeCount(matchingId); } - + + /** + * 추천 숙소 리스트 조회 + * @return recommended accommodation list + */ @Operation(summary = "Get recommended accommodation list", description = "추천 숙소 리스트를 반환한다.") @GetMapping("/accommodation/recommended") public List getRecommendedAccommodationList() { @@ -290,7 +315,12 @@ public FindMatchingDto updateMatching(@PathVariable Long matchingId, @RequestBod } return saveMatchingUsecase.updateMatching(matchingId, matchingDto); } - + + /** + * 숙소 정보 수정 + * @param matchingId (ID) + * @param accommodationDto (데이터) + */ @Operation(summary = "Update accommodation", description = "숙소 정보를 수정한다.") @PutMapping("/matching/{matchingId}/accommodation") public void updateAccommodation(@PathVariable Long matchingId, @RequestBody AccommodationDto accommodationDto) { @@ -374,7 +404,11 @@ public void deleteMatching(@PathVariable Long matchingId) { } deleteMatchingUsecase.deleteMatching(matchingId); } - + + /** + * 숙소 정보 초기화 + * @param matchingId (ID) + */ @Operation(summary = "Reset accommodation", description = "숙소 정보를 초기화한다.") @DeleteMapping("/matching/{matchingId}/accommodation") public void deleteAccommodation(@PathVariable Long matchingId) { diff --git a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingEntity.java b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingEntity.java index 59dcadc..171ae64 100644 --- a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingEntity.java +++ b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingEntity.java @@ -38,6 +38,12 @@ public class MatchingEntity extends BaseEntity { @Column(nullable = false, length = 3000) private String place; + @Column + private Double latitude; + + @Column + private Double longitude; + @Column(nullable = false, length = 6000) private String content; diff --git a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingPersistenceAdapter.java b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingPersistenceAdapter.java index f7dbef6..1e3bea4 100644 --- a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingPersistenceAdapter.java +++ b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingPersistenceAdapter.java @@ -47,6 +47,11 @@ public List getByWriterId(UUID userId) { return matchingRepository.getByWriterId(userId); } + @Override + public List getByPlaceCoordinate(Double latitude, Double longitude) { + return matchingRepository.getByLatitudeGreaterThanEqualAndLatitudeLessThanEqualAndLongitudeGreaterThanEqualAndLongitudeLessThanEqual(latitude - 0.02, latitude + 0.02, longitude - 0.025, longitude + 0.025); + } + @Override public List getByIsActive(Boolean isActive) { return matchingRepository.getByIsActive(isActive); diff --git a/src/main/java/com/example/api/matching/application/port/in/FindMatchingUsecase.java b/src/main/java/com/example/api/matching/application/port/in/FindMatchingUsecase.java index a129721..88bcf79 100644 --- a/src/main/java/com/example/api/matching/application/port/in/FindMatchingUsecase.java +++ b/src/main/java/com/example/api/matching/application/port/in/FindMatchingUsecase.java @@ -10,6 +10,7 @@ public interface FindMatchingUsecase { List getDiningMatchingList(); FindMatchingDto getMatchingById(Long matchingId); List getMatchingByWriterId(UUID userId); + List getNearMatching(Double latitude, Double longitude); List getMatchingByIsActive(Boolean isActive); List getRecommendedMatchingList(UUID userId); } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/application/port/out/FindMatchingPort.java b/src/main/java/com/example/api/matching/application/port/out/FindMatchingPort.java index 19d8122..851f377 100644 --- a/src/main/java/com/example/api/matching/application/port/out/FindMatchingPort.java +++ b/src/main/java/com/example/api/matching/application/port/out/FindMatchingPort.java @@ -11,5 +11,6 @@ public interface FindMatchingPort { List getDiningMatchingList(); Optional getByMatchingId(Long matchingId); List getByWriterId(UUID userId); + List getByPlaceCoordinate(Double latitude, Double longitude); List getByIsActive(Boolean isActive); } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/domain/Matching.java b/src/main/java/com/example/api/matching/domain/Matching.java index 1cd09b6..5f05e70 100644 --- a/src/main/java/com/example/api/matching/domain/Matching.java +++ b/src/main/java/com/example/api/matching/domain/Matching.java @@ -18,6 +18,8 @@ public class Matching { private MatchingTypeEnum type; private String title; private String place; + private Double latitude; + private Double longitude; private String content; private LocalDateTime startDate; private LocalDateTime endDate; diff --git a/src/main/java/com/example/api/matching/dto/FindMatchingDto.java b/src/main/java/com/example/api/matching/dto/FindMatchingDto.java index d8479fc..820488c 100644 --- a/src/main/java/com/example/api/matching/dto/FindMatchingDto.java +++ b/src/main/java/com/example/api/matching/dto/FindMatchingDto.java @@ -4,6 +4,7 @@ import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.*; import java.time.LocalDateTime; @@ -33,6 +34,12 @@ public class FindMatchingDto { @NotBlank private String place; + + @Size(min = -90, max = 90) + private Double latitude; + + @Size(min = -180, max = 180) + private Double longitude; @NotBlank private String content; diff --git a/src/main/java/com/example/api/matching/dto/SaveMatchingDto.java b/src/main/java/com/example/api/matching/dto/SaveMatchingDto.java index f743328..bcfd120 100644 --- a/src/main/java/com/example/api/matching/dto/SaveMatchingDto.java +++ b/src/main/java/com/example/api/matching/dto/SaveMatchingDto.java @@ -4,6 +4,7 @@ import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; import lombok.*; import java.time.LocalDateTime; @@ -27,6 +28,12 @@ public class SaveMatchingDto { @NotBlank(message = "Place is empty") private String place; + @Size(min = -90, max = 90) + private Double latitude; + + @Size(min = -180, max = 180) + private Double longitude; + @NotNull private String content; diff --git a/src/main/java/com/example/api/matching/repository/MatchingRepository.java b/src/main/java/com/example/api/matching/repository/MatchingRepository.java index 291e55c..b77a5ae 100644 --- a/src/main/java/com/example/api/matching/repository/MatchingRepository.java +++ b/src/main/java/com/example/api/matching/repository/MatchingRepository.java @@ -12,6 +12,7 @@ public interface MatchingRepository extends JpaRepository List getAllBy(); Optional getByMatchingId(Long matchingId); List getByWriterId(UUID userId); + List getByLatitudeGreaterThanEqualAndLatitudeLessThanEqualAndLongitudeGreaterThanEqualAndLongitudeLessThanEqual(Double minLatitude, Double maxLatitude, Double minLongitude, Double maxLongitude); List getByType(MatchingTypeEnum type); List getByIsActive(Boolean isActive); void deleteAllBy(); diff --git a/src/main/java/com/example/api/matching/service/MatchingService.java b/src/main/java/com/example/api/matching/service/MatchingService.java index 19ea2e4..168c681 100644 --- a/src/main/java/com/example/api/matching/service/MatchingService.java +++ b/src/main/java/com/example/api/matching/service/MatchingService.java @@ -84,6 +84,11 @@ public FindMatchingDto getMatchingById(Long matchingId) { public List getMatchingByWriterId(UUID userId) { return this.setCurrentMember(findMatchingPort.getByWriterId(userId)); } + + @Override + public List getNearMatching(Double latitude, Double longitude) { + return this.setCurrentMember(findMatchingPort.getByPlaceCoordinate(latitude, longitude)); + } @Override public List getMatchingByIsActive(Boolean isActive) { From 287ccfff31efd8a0dfb56aed2a5ffffd4f4f8881 Mon Sep 17 00:00:00 2001 From: Lemonade255 Date: Mon, 20 Nov 2023 18:18:01 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat(BE):=20=EC=9C=84=EC=B9=98=20=EA=B8=B0?= =?UTF-8?q?=EC=A4=80=EC=9C=BC=EB=A1=9C=20=EB=A7=A4=EC=B9=AD=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20BUS-229-place-latitude-longitude=20#221?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/matching/adapter/in/rest/MatchingController.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java index 5f7241b..f5d47b9 100644 --- a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java +++ b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java @@ -8,6 +8,7 @@ import com.example.api.common.exception.CustomException; import com.example.api.common.type.ApplicationStateEnum; import com.example.api.common.type.ErrorCodeEnum; +import com.example.api.common.type.Pair; import com.example.api.common.utils.AuthenticationUtils; import com.example.api.matching.adapter.out.persistence.MatchingMapperInterface; import com.example.api.matching.application.port.in.*; @@ -204,19 +205,18 @@ public List getMyMatching() { /** * 선택한 위치와 가까운 매칭 조회 - * @param latitude (위도) - * @param longitude (경도) + * @param coordination (위치) * @return near matching list */ @Operation(summary = "Get matching by place coordinate", description = "선택한 위치와 가까운 여행지의 매칭 목록을 조회한다.") @GetMapping("/matching/nearfrom") - public List getNearMatching(Double latitude, Double longitude) { + public List getNearMatching(@RequestBody Pair coordination) { SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); if (securityUser == null) { log.error("MatchingController::getNearMatching: Login is needed"); throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); } - return findMatchingUsecase.getNearMatching(latitude, longitude); + return findMatchingUsecase.getNearMatching(coordination.getFirst(), coordination.getSecond()); } /** From e13cee125d39040160ec44517b30a05bc9deff91 Mon Sep 17 00:00:00 2001 From: Lemonade255 Date: Mon, 20 Nov 2023 20:01:07 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat(BE):=20=EB=94=94=ED=8F=B4=ED=8A=B8=20?= =?UTF-8?q?=EC=9C=84=EC=B9=98=20=EC=B6=94=EA=B0=80=20BUS-229-place-latitud?= =?UTF-8?q?e-longitude=20#221?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/matching/adapter/in/rest/MatchingController.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java index f5d47b9..5341379 100644 --- a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java +++ b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java @@ -210,13 +210,17 @@ public List getMyMatching() { */ @Operation(summary = "Get matching by place coordinate", description = "선택한 위치와 가까운 여행지의 매칭 목록을 조회한다.") @GetMapping("/matching/nearfrom") - public List getNearMatching(@RequestBody Pair coordination) { + public List getNearMatching(@RequestBody(required = false) Pair coordination) { SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); if (securityUser == null) { log.error("MatchingController::getNearMatching: Login is needed"); throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); } - return findMatchingUsecase.getNearMatching(coordination.getFirst(), coordination.getSecond()); + Pair coordinationData = coordination; + if (coordinationData == null) { + coordinationData = new Pair<>(37.5544, 126.9707); // 서울역 + } + return findMatchingUsecase.getNearMatching(coordinationData.getFirst(), coordinationData.getSecond()); } /**