From cb97af4608a3802c586d940f2e5da78475d6dfc8 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Thu, 14 Sep 2023 15:20:49 +0900 Subject: [PATCH 01/31] =?UTF-8?q?feat:=20cafe=20coordinate=20=EC=BB=AC?= =?UTF-8?q?=EB=9F=BC=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/migration/V20230914151731__add_point_column.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 server/src/main/resources/db/migration/V20230914151731__add_point_column.sql diff --git a/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql b/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql new file mode 100644 index 00000000..fc2a9701 --- /dev/null +++ b/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql @@ -0,0 +1,2 @@ +ALTER TABLE `yozm-cafe`.cafe + ADD COLUMN coordinate POINT NOT NULL DEFAULT (ST_GeomFromText('POINT(37.546912668813 127.0411420343)', 4326)); From 534098e38c6dbeae46fa89aea6f12b264377e569 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Thu, 14 Sep 2023 17:30:22 +0900 Subject: [PATCH 02/31] =?UTF-8?q?chore:=20=EB=B9=8C=EB=93=9C=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20&=20application.properties?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/build.gradle | 1 + server/src/main/resources/application.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/server/build.gradle b/server/build.gradle index f448c1fc..30621a4f 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -19,6 +19,7 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation group: 'org.hibernate', name: 'hibernate-spatial', version: '6.2.5.Final' testImplementation 'org.springframework.boot:spring-boot-starter-test' //DB diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties index 4f2abf99..674da02c 100644 --- a/server/src/main/resources/application.properties +++ b/server/src/main/resources/application.properties @@ -2,7 +2,7 @@ spring.datasource.url=jdbc:mysql://localhost:20000/yozm-cafe?useSSL=false&allowP spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect +spring.jpa.database-platform=org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect spring.jpa.hibernate.ddl-auto=validate spring.auth.key=testtesttesttesttesttesttesttesttesttesttesttesttesttesttest spring.auth.accessTokenExpired=360000 From 64bb3c8e6ca27a0f46c64176696026e5fe1cf1f0 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Thu, 14 Sep 2023 20:22:36 +0900 Subject: [PATCH 03/31] =?UTF-8?q?chore:=20coordinate=20table=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/migration/V20230914151731__add_point_column.sql | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql b/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql index fc2a9701..ac2dd80a 100644 --- a/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql +++ b/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql @@ -1,2 +1,8 @@ -ALTER TABLE `yozm-cafe`.cafe - ADD COLUMN coordinate POINT NOT NULL DEFAULT (ST_GeomFromText('POINT(37.546912668813 127.0411420343)', 4326)); +CREATE TABLE cafe_coordinates +( + id BIGINT NOT NULL AUTO_INCREMENT, + coordinate POINT NOT NULL, + cafe_id BIGINT NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (cafe_id) REFERENCES cafe (id) +); From cd4ea539039e1c54c01a353796c2f2fac7972306 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Thu, 14 Sep 2023 20:54:12 +0900 Subject: [PATCH 04/31] =?UTF-8?q?feat:=20CafeCoordinate=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yozmcafe/domain/cafe/CafeCoordinate.java | 55 +++++++++++++++++++ .../domain/cafe/CafeCoordinateRepository.java | 7 +++ .../domain/cafe/CafeCoordinateTest.java | 37 +++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinate.java create mode 100644 server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinateRepository.java create mode 100644 server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinate.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinate.java new file mode 100644 index 00000000..54153fc5 --- /dev/null +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinate.java @@ -0,0 +1,55 @@ +package com.project.yozmcafe.domain.cafe; + +import static jakarta.persistence.GenerationType.IDENTITY; + +import org.locationtech.jts.geom.Point; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.OneToOne; + +@Entity(name = "cafe_coordinates") +public class CafeCoordinate { + + @Id + @GeneratedValue(strategy = IDENTITY) + private Long id; + private Point coordinate; + + @OneToOne + private Cafe cafe; + + public CafeCoordinate() { + } + + public CafeCoordinate(final Long id, final Point coordinate, final Cafe cafe) { + this.id = id; + this.coordinate = coordinate; + this.cafe = cafe; + } + + public CafeCoordinate(final Point coordinate, final Cafe cafe) { + this(null, coordinate, cafe); + } + + public double getLatitude() { + return coordinate.getX(); + } + + public double getLongitude() { + return coordinate.getY(); + } + + public Long getId() { + return id; + } + + public Point getCoordinate() { + return coordinate; + } + + public Cafe getCafe() { + return cafe; + } +} diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinateRepository.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinateRepository.java new file mode 100644 index 00000000..3028bb03 --- /dev/null +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinateRepository.java @@ -0,0 +1,7 @@ +package com.project.yozmcafe.domain.cafe; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CafeCoordinateRepository extends JpaRepository { + +} diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java new file mode 100644 index 00000000..509e9092 --- /dev/null +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java @@ -0,0 +1,37 @@ +package com.project.yozmcafe.domain.cafe; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.SoftAssertions.assertSoftly; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.Point; + +import com.project.yozmcafe.fixture.Fixture; + +class CafeCoordinateTest { + + @Test + @DisplayName("위도와 경도를 반환한다.") + void getLatitudeAndLongitude() { + //given + final double latitude = 20.0; + final double longitude = 10.0; + final GeometryFactory geometryFactory = new GeometryFactory(); + final Point point = geometryFactory.createPoint(new Coordinate(latitude, longitude)); + final Cafe cafe = Fixture.getCafe("카페", "성수동", 0); + final CafeCoordinate cafeCoordinate = new CafeCoordinate(point, cafe); + + //when + final double resultLatitude = cafeCoordinate.getLatitude(); + final double resultLongitude = cafeCoordinate.getLongitude(); + + //then + assertSoftly(softAssertions -> { + assertThat(resultLatitude).isEqualTo(latitude); + assertThat(resultLongitude).isEqualTo(longitude); + }); + } +} From 61472c8a3d2ce1bff44f4cd2d26042cd53d776d4 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Thu, 14 Sep 2023 21:31:42 +0900 Subject: [PATCH 05/31] =?UTF-8?q?feat:=20PointGenerator=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yozmcafe/domain/cafe/PointGenerator.java | 20 +++++++++++ .../domain/cafe/CafeCoordinateTest.java | 5 +-- .../domain/cafe/PointGeneratorTest.java | 33 +++++++++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java create mode 100644 server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java new file mode 100644 index 00000000..d823838f --- /dev/null +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java @@ -0,0 +1,20 @@ +package com.project.yozmcafe.domain.cafe; + +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.Point; + +public class PointGenerator { + + private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(); + private static final int SRID = 4326; + + private PointGenerator() { + } + + public static Point generateWithCoordinate(final double latitude, final double longitude) { + final Point point = GEOMETRY_FACTORY.createPoint(new Coordinate(latitude, longitude)); + point.setSRID(SRID); + return point; + } +} diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java index 509e9092..0a6dcdd6 100644 --- a/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java @@ -5,8 +5,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.locationtech.jts.geom.Coordinate; -import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Point; import com.project.yozmcafe.fixture.Fixture; @@ -19,8 +17,7 @@ void getLatitudeAndLongitude() { //given final double latitude = 20.0; final double longitude = 10.0; - final GeometryFactory geometryFactory = new GeometryFactory(); - final Point point = geometryFactory.createPoint(new Coordinate(latitude, longitude)); + final Point point = PointGenerator.generateWithCoordinate(latitude, longitude); final Cafe cafe = Fixture.getCafe("카페", "성수동", 0); final CafeCoordinate cafeCoordinate = new CafeCoordinate(point, cafe); diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java new file mode 100644 index 00000000..a93d66ca --- /dev/null +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java @@ -0,0 +1,33 @@ +package com.project.yozmcafe.domain.cafe; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.assertj.core.api.SoftAssertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.locationtech.jts.geom.Point; + +class PointGeneratorTest { + + @Test + @DisplayName("포인트 생성 테스트") + void generate() { + //given + final double latitude = 20; + final double longitude = 10; + final Point point = PointGenerator.generateWithCoordinate(latitude, longitude); + + //when + final int srid = point.getSRID(); + final double resultLatitude = point.getX(); + final double resultLongitude = point.getY(); + + //then + SoftAssertions.assertSoftly(softAssertions -> { + assertThat(srid).isEqualTo(4326); + assertThat(resultLatitude).isEqualTo(latitude); + assertThat(resultLongitude).isEqualTo(longitude); + }); + } + +} From 80eae2eacfb5b4472580f22bf0e43776fdcb4113 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Thu, 14 Sep 2023 21:44:57 +0900 Subject: [PATCH 06/31] =?UTF-8?q?feat:=20CafeAdminService#=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC=ED=95=98=EB=8A=94=20=EC=B9=B4=ED=8E=98=EC=97=90=20?= =?UTF-8?q?=EC=A2=8C=ED=91=9C=EB=A5=BC=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/cafe/CafeCoordinateRequest.java | 15 ++++++ .../yozmcafe/domain/cafe/CafeCoordinate.java | 3 +- .../yozmcafe/service/CafeAdminService.java | 43 +++++++++++----- .../service/CafeAdminServiceTest.java | 49 ++++++++++++++----- 4 files changed, 85 insertions(+), 25 deletions(-) create mode 100644 server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.java diff --git a/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.java b/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.java new file mode 100644 index 00000000..dbde015d --- /dev/null +++ b/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.java @@ -0,0 +1,15 @@ +package com.project.yozmcafe.controller.dto.cafe; + +import org.locationtech.jts.geom.Point; + +import com.project.yozmcafe.domain.cafe.Cafe; +import com.project.yozmcafe.domain.cafe.CafeCoordinate; +import com.project.yozmcafe.domain.cafe.PointGenerator; + +public record CafeCoordinateRequest(double latitude, double longitude) { + + public CafeCoordinate toCafeCoordinateWithCafe(final Cafe cafe) { + final Point point = PointGenerator.generateWithCoordinate(latitude, longitude); + return new CafeCoordinate(point, cafe); + } +} diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinate.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinate.java index 54153fc5..519f6e29 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinate.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinate.java @@ -5,6 +5,7 @@ import org.locationtech.jts.geom.Point; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.OneToOne; @@ -17,7 +18,7 @@ public class CafeCoordinate { private Long id; private Point coordinate; - @OneToOne + @OneToOne(fetch = FetchType.LAZY) private Cafe cafe; public CafeCoordinate() { diff --git a/server/src/main/java/com/project/yozmcafe/service/CafeAdminService.java b/server/src/main/java/com/project/yozmcafe/service/CafeAdminService.java index 0e607a67..38617d47 100644 --- a/server/src/main/java/com/project/yozmcafe/service/CafeAdminService.java +++ b/server/src/main/java/com/project/yozmcafe/service/CafeAdminService.java @@ -1,34 +1,43 @@ package com.project.yozmcafe.service; +import static com.project.yozmcafe.exception.ErrorCode.NOT_EXISTED_CAFE; + +import java.util.List; +import java.util.stream.Stream; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import com.project.yozmcafe.controller.dto.cafe.CafeCoordinateRequest; import com.project.yozmcafe.controller.dto.cafe.CafeRequest; import com.project.yozmcafe.controller.dto.cafe.CafeResponse; import com.project.yozmcafe.controller.dto.cafe.CafeUpdateRequest; import com.project.yozmcafe.domain.cafe.Cafe; +import com.project.yozmcafe.domain.cafe.CafeCoordinate; +import com.project.yozmcafe.domain.cafe.CafeCoordinateRepository; import com.project.yozmcafe.domain.cafe.CafeRepository; import com.project.yozmcafe.domain.cafe.Images; import com.project.yozmcafe.exception.BadRequestException; + import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import jakarta.persistence.Query; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.stream.Stream; - -import static com.project.yozmcafe.exception.ErrorCode.NOT_EXISTED_CAFE; @Service @Transactional(readOnly = true) public class CafeAdminService { private final CafeRepository cafeRepository; + private final CafeCoordinateRepository cafeCoordinateRepository; @PersistenceContext private final EntityManager entityManager; - public CafeAdminService(final CafeRepository cafeRepository, final EntityManager entityManager) { + public CafeAdminService(final CafeRepository cafeRepository, + final CafeCoordinateRepository cafeCoordinateRepository, + final EntityManager entityManager) { this.cafeRepository = cafeRepository; + this.cafeCoordinateRepository = cafeCoordinateRepository; this.entityManager = entityManager; } @@ -40,13 +49,13 @@ public Long save(final CafeRequest cafeRequest, List imageNames) { @Transactional public void update(final long cafeId, final CafeUpdateRequest request, List images) { - final Cafe cafe = getOrThrow(cafeId); + final Cafe cafe = getCafeOrThrow(cafeId); final Cafe requestedCafe = request.toCafeWithId(cafeId, images); cafe.update(requestedCafe); } - private Cafe getOrThrow(final long cafeId) { + private Cafe getCafeOrThrow(final long cafeId) { return cafeRepository.findById(cafeId) .orElseThrow(() -> new BadRequestException(NOT_EXISTED_CAFE)); } @@ -58,7 +67,7 @@ public List findAll() { } public CafeResponse findById(final long cafeId) { - final Cafe cafe = getOrThrow(cafeId); + final Cafe cafe = getCafeOrThrow(cafeId); return CafeResponse.fromUnLoggedInUser(cafe); } @@ -75,7 +84,15 @@ public void delete(final long cafeId) { } public List findImagesByCafeId(final Long cafeId) { - final Images images = getOrThrow(cafeId).getImages(); + final Images images = getCafeOrThrow(cafeId).getImages(); return images.getUrls(); } + + @Transactional + public Long saveCafeCoordinate(final Long cafeId, final CafeCoordinateRequest cafeCoordinateRequest) { + final Cafe cafe = getCafeOrThrow(cafeId); + final CafeCoordinate cafeCoordinate = cafeCoordinateRequest.toCafeCoordinateWithCafe(cafe); + cafeCoordinateRepository.save(cafeCoordinate); + return cafeCoordinate.getId(); + } } diff --git a/server/src/test/java/com/project/yozmcafe/service/CafeAdminServiceTest.java b/server/src/test/java/com/project/yozmcafe/service/CafeAdminServiceTest.java index 744a360c..872c5a24 100644 --- a/server/src/test/java/com/project/yozmcafe/service/CafeAdminServiceTest.java +++ b/server/src/test/java/com/project/yozmcafe/service/CafeAdminServiceTest.java @@ -1,28 +1,33 @@ package com.project.yozmcafe.service; +import static com.project.yozmcafe.exception.ErrorCode.NOT_EXISTED_CAFE; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.SoftAssertions.assertSoftly; + +import java.time.LocalTime; +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + import com.project.yozmcafe.BaseTest; import com.project.yozmcafe.controller.dto.cafe.AvailableTimeRequest; +import com.project.yozmcafe.controller.dto.cafe.CafeCoordinateRequest; import com.project.yozmcafe.controller.dto.cafe.CafeRequest; import com.project.yozmcafe.controller.dto.cafe.CafeResponse; import com.project.yozmcafe.controller.dto.cafe.CafeUpdateRequest; import com.project.yozmcafe.controller.dto.cafe.DetailRequest; import com.project.yozmcafe.domain.cafe.Cafe; +import com.project.yozmcafe.domain.cafe.CafeCoordinate; +import com.project.yozmcafe.domain.cafe.CafeCoordinateRepository; import com.project.yozmcafe.domain.cafe.CafeRepository; import com.project.yozmcafe.domain.cafe.Detail; import com.project.yozmcafe.domain.cafe.Images; import com.project.yozmcafe.domain.cafe.available.Days; import com.project.yozmcafe.exception.BadRequestException; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -import java.time.LocalTime; -import java.util.List; - -import static com.project.yozmcafe.exception.ErrorCode.NOT_EXISTED_CAFE; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; class CafeAdminServiceTest extends BaseTest { @@ -30,6 +35,8 @@ class CafeAdminServiceTest extends BaseTest { private CafeAdminService cafeAdminService; @Autowired private CafeRepository cafeRepository; + @Autowired + private CafeCoordinateRepository cafeCoordinateRepository; @Test @DisplayName("카페 생성 테스트") @@ -181,6 +188,26 @@ void findImagesByCafeId() { assertThat(imagesByCafeId).containsExactly("image"); } + @Test + @DisplayName("카페 좌표 정보를 저장한다.") + void saveCafeCoordinate() { + //given + final Cafe cafe = saveCafe(); + final double latitude = 20; + final double longitude = 10; + final CafeCoordinateRequest cafeCoordinateRequest = new CafeCoordinateRequest(latitude, longitude); + final Long savedId = cafeAdminService.saveCafeCoordinate(cafe.getId(), cafeCoordinateRequest); + + //when + final CafeCoordinate cafeCoordinate = cafeCoordinateRepository.findById(savedId).get(); + + //then + assertSoftly(softAssertions -> { + assertThat(cafeCoordinate.getLatitude()).isEqualTo(latitude); + assertThat(cafeCoordinate.getLongitude()).isEqualTo(longitude); + }); + } + private Cafe saveCafe() { return cafeRepository.save(new Cafe("연어카페", "주소", new Images(List.of("image")), detail().toDetail())); } From ab2e217d7cbdc39144ab6e47f2ec7959e776f7a9 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Thu, 14 Sep 2023 22:23:32 +0900 Subject: [PATCH 07/31] =?UTF-8?q?feat:=20CafeAdminController#=EC=B9=B4?= =?UTF-8?q?=ED=8E=98=EC=97=90=20=EC=A2=8C=ED=91=9C=EB=A5=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CafeAdminController.java | 9 +++ .../controller/CafeAdminControllerTest.java | 65 +++++++++++++------ 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/server/src/main/java/com/project/yozmcafe/controller/CafeAdminController.java b/server/src/main/java/com/project/yozmcafe/controller/CafeAdminController.java index 33939de2..8ca1931e 100644 --- a/server/src/main/java/com/project/yozmcafe/controller/CafeAdminController.java +++ b/server/src/main/java/com/project/yozmcafe/controller/CafeAdminController.java @@ -13,10 +13,12 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; +import com.project.yozmcafe.controller.dto.cafe.CafeCoordinateRequest; import com.project.yozmcafe.controller.dto.cafe.CafeRequest; import com.project.yozmcafe.controller.dto.cafe.CafeResponse; import com.project.yozmcafe.controller.dto.cafe.CafeUpdateRequest; @@ -108,4 +110,11 @@ public ResponseEntity saveMenuBoards(@PathVariable("cafeId") final Long return ResponseEntity.created(URI.create("/admin/cafes/" + cafeId)).build(); } + + @PostMapping("/{cafeId}/coordinate") + public ResponseEntity saveCoordinate(@PathVariable("cafeId") final Long cafeId, + @RequestBody final CafeCoordinateRequest cafeCoordinateRequest) { + cafeAdminService.saveCafeCoordinate(cafeId, cafeCoordinateRequest); + return ResponseEntity.created(URI.create("/admin/cafes/" + cafeId)).build(); + } } diff --git a/server/src/test/java/com/project/yozmcafe/controller/CafeAdminControllerTest.java b/server/src/test/java/com/project/yozmcafe/controller/CafeAdminControllerTest.java index 2b43538a..085c9424 100644 --- a/server/src/test/java/com/project/yozmcafe/controller/CafeAdminControllerTest.java +++ b/server/src/test/java/com/project/yozmcafe/controller/CafeAdminControllerTest.java @@ -1,23 +1,5 @@ package com.project.yozmcafe.controller; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.project.yozmcafe.controller.dto.cafe.AvailableTimeRequest; -import com.project.yozmcafe.controller.dto.cafe.CafeRequest; -import com.project.yozmcafe.controller.dto.cafe.CafeUpdateRequest; -import com.project.yozmcafe.controller.dto.cafe.DetailRequest; -import com.project.yozmcafe.domain.S3Client; -import com.project.yozmcafe.domain.cafe.available.Days; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.HttpStatus; -import org.springframework.mock.web.MockMultipartFile; - -import java.io.File; -import java.time.LocalTime; -import java.util.List; - import static com.epages.restdocs.apispec.RestAssuredRestDocumentationWrapper.document; import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; @@ -30,13 +12,33 @@ import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; import static org.springframework.restdocs.headers.HeaderDocumentation.responseHeaders; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; import static org.springframework.restdocs.payload.PayloadDocumentation.requestPartBody; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; -class CafeAdminControllerTest extends BaseControllerTest { +import java.io.File; +import java.time.LocalTime; +import java.util.List; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.HttpStatus; +import org.springframework.mock.web.MockMultipartFile; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.project.yozmcafe.controller.dto.cafe.AvailableTimeRequest; +import com.project.yozmcafe.controller.dto.cafe.CafeCoordinateRequest; +import com.project.yozmcafe.controller.dto.cafe.CafeRequest; +import com.project.yozmcafe.controller.dto.cafe.CafeUpdateRequest; +import com.project.yozmcafe.controller.dto.cafe.DetailRequest; +import com.project.yozmcafe.domain.S3Client; +import com.project.yozmcafe.domain.cafe.available.Days; + +class CafeAdminControllerTest extends BaseControllerTest { @Autowired private ObjectMapper mapper; @@ -174,6 +176,31 @@ void findById() { .statusCode(is(HttpStatus.OK.value())); } + @Test + @DisplayName("좌표 정보를 저장한다.") + void saveCoordinate() { + //given + final String location = saveCafe(); + + //when, then + given(spec).log().all() + .contentType(JSON) + .filter(document("어드민 API/좌표 정보 저장", + pathParameters(parameterWithName("cafeId").description("죄표를 추가할 카페 ID")), + requestFields( + fieldWithPath("latitude").description("위도"), + fieldWithPath("longitude").description("경도") + ), + responseHeaders(headerWithName("Location").description("카페 저장 위치")) + )) + .when() + .body(new CafeCoordinateRequest(20, 10)) + .post("/admin/cafes/{cafeId}/coordinate", location) + .then() + .statusCode(is(HttpStatus.CREATED.value())) + .header("Location", notNullValue()); + } + private String saveCafe() { doNothing().when(s3Client).upload(any(MockMultipartFile.class)); final String cafeRequest = makeCafeRequest(); From d72d17b9b8b99e02519ac40f4105dd3f28b99e9c Mon Sep 17 00:00:00 2001 From: dev_kong Date: Fri, 15 Sep 2023 14:24:27 +0900 Subject: [PATCH 08/31] =?UTF-8?q?chore:=20coordinate=20column=EC=97=90=20S?= =?UTF-8?q?RID=20=EA=B0=92=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/migration/V20230914151731__add_point_column.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql b/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql index ac2dd80a..465ea980 100644 --- a/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql +++ b/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql @@ -1,7 +1,7 @@ CREATE TABLE cafe_coordinates ( id BIGINT NOT NULL AUTO_INCREMENT, - coordinate POINT NOT NULL, + coordinate POINT NOT NULL SRID 4326, cafe_id BIGINT NOT NULL, PRIMARY KEY (id), FOREIGN KEY (cafe_id) REFERENCES cafe (id) From 219f1fa240dcedd1398bfb0207deaae6a3b078db Mon Sep 17 00:00:00 2001 From: dev_kong Date: Fri, 15 Sep 2023 19:21:00 +0900 Subject: [PATCH 09/31] =?UTF-8?q?fix:=20=EC=9C=84=EB=8F=84=20=EA=B2=BD?= =?UTF-8?q?=EB=8F=84=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=88=9C?= =?UTF-8?q?=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/yozmcafe/domain/cafe/PointGenerator.java | 2 +- .../domain/cafe/{ => coordinate}/CafeCoordinate.java | 9 ++++++--- .../project/yozmcafe/domain/cafe/PointGeneratorTest.java | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) rename server/src/main/java/com/project/yozmcafe/domain/cafe/{ => coordinate}/CafeCoordinate.java (92%) diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java index d823838f..c2f29f97 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java @@ -13,7 +13,7 @@ private PointGenerator() { } public static Point generateWithCoordinate(final double latitude, final double longitude) { - final Point point = GEOMETRY_FACTORY.createPoint(new Coordinate(latitude, longitude)); + final Point point = GEOMETRY_FACTORY.createPoint(new Coordinate(longitude, latitude)); point.setSRID(SRID); return point; } diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinate.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.java similarity index 92% rename from server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinate.java rename to server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.java index 519f6e29..5fb84d15 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinate.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.java @@ -1,9 +1,11 @@ -package com.project.yozmcafe.domain.cafe; +package com.project.yozmcafe.domain.cafe.coordinate; import static jakarta.persistence.GenerationType.IDENTITY; import org.locationtech.jts.geom.Point; +import com.project.yozmcafe.domain.cafe.Cafe; + import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; @@ -16,6 +18,7 @@ public class CafeCoordinate { @Id @GeneratedValue(strategy = IDENTITY) private Long id; + private Point coordinate; @OneToOne(fetch = FetchType.LAZY) @@ -35,11 +38,11 @@ public CafeCoordinate(final Point coordinate, final Cafe cafe) { } public double getLatitude() { - return coordinate.getX(); + return coordinate.getY(); } public double getLongitude() { - return coordinate.getY(); + return coordinate.getX(); } public Long getId() { diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java index a93d66ca..ac0933ac 100644 --- a/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java @@ -19,8 +19,8 @@ void generate() { //when final int srid = point.getSRID(); - final double resultLatitude = point.getX(); - final double resultLongitude = point.getY(); + final double resultLatitude = point.getY(); + final double resultLongitude = point.getX(); //then SoftAssertions.assertSoftly(softAssertions -> { From 5312ecd4de8f3e45688ed8346a110b17ab078597 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Fri, 15 Sep 2023 19:25:25 +0900 Subject: [PATCH 10/31] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=EB=B0=9B?= =?UTF-8?q?=EC=9D=80=20=EC=9C=84=EB=8F=84=20=EA=B2=BD=EB=8F=84=EB=A1=9C=20?= =?UTF-8?q?=EB=B6=80=ED=84=B0=20=EB=B0=98=EA=B2=BD=EC=95=88=EC=97=90=20?= =?UTF-8?q?=ED=8F=AC=ED=95=A8=EB=90=9C=20=EB=AA=A8=EB=93=A0=20=EC=B9=B4?= =?UTF-8?q?=ED=8E=98=EB=A5=BC=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/cafe/CafeCoordinateRequest.java | 2 +- .../domain/cafe/CafeCoordinateRepository.java | 7 --- .../coordinate/CafeCoordinateRepository.java | 23 ++++++++++ .../cafe/coordinate/dto/CafePinDto.java | 13 ++++++ .../yozmcafe/service/CafeAdminService.java | 4 +- .../domain/cafe/CafeCoordinateTest.java | 1 + .../CafeCoordinateRepositoryTest.java | 46 +++++++++++++++++++ .../service/CafeAdminServiceTest.java | 4 +- 8 files changed, 88 insertions(+), 12 deletions(-) delete mode 100644 server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinateRepository.java create mode 100644 server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java create mode 100644 server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/dto/CafePinDto.java create mode 100644 server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java diff --git a/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.java b/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.java index dbde015d..117f1345 100644 --- a/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.java +++ b/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.java @@ -3,8 +3,8 @@ import org.locationtech.jts.geom.Point; import com.project.yozmcafe.domain.cafe.Cafe; -import com.project.yozmcafe.domain.cafe.CafeCoordinate; import com.project.yozmcafe.domain.cafe.PointGenerator; +import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinate; public record CafeCoordinateRequest(double latitude, double longitude) { diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinateRepository.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinateRepository.java deleted file mode 100644 index 3028bb03..00000000 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/CafeCoordinateRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.project.yozmcafe.domain.cafe; - -import org.springframework.data.jpa.repository.JpaRepository; - -public interface CafeCoordinateRepository extends JpaRepository { - -} diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java new file mode 100644 index 00000000..064ce673 --- /dev/null +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java @@ -0,0 +1,23 @@ +package com.project.yozmcafe.domain.cafe.coordinate; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import com.project.yozmcafe.domain.cafe.coordinate.dto.CafePinDto; + +public interface CafeCoordinateRepository extends JpaRepository { + + @Query(nativeQuery = true, + value = """ + SELECT c.id, c.name, c.address, ST_X(co.coordinate) AS latitude, ST_Y(co.coordinate) AS longitude + FROM cafe_coordinates co + JOIN cafe AS c + ON co.cafe_id = c.id + WHERE ST_CONTAINS(ST_Buffer(ST_GeomFromText(:point, 4326), :radius), co.coordinate); + """) + List findCafePinsFromCoordinate(@Param("point") final String point, + @Param("radius") final double radius); +} diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/dto/CafePinDto.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/dto/CafePinDto.java new file mode 100644 index 00000000..a2a1d0f2 --- /dev/null +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/dto/CafePinDto.java @@ -0,0 +1,13 @@ +package com.project.yozmcafe.domain.cafe.coordinate.dto; + +public interface CafePinDto { + Long getId(); + + String getName(); + + String getAddress(); + + double getLatitude(); + + double getLongitude(); +} diff --git a/server/src/main/java/com/project/yozmcafe/service/CafeAdminService.java b/server/src/main/java/com/project/yozmcafe/service/CafeAdminService.java index 38617d47..5c8baeff 100644 --- a/server/src/main/java/com/project/yozmcafe/service/CafeAdminService.java +++ b/server/src/main/java/com/project/yozmcafe/service/CafeAdminService.java @@ -14,10 +14,10 @@ import com.project.yozmcafe.controller.dto.cafe.CafeResponse; import com.project.yozmcafe.controller.dto.cafe.CafeUpdateRequest; import com.project.yozmcafe.domain.cafe.Cafe; -import com.project.yozmcafe.domain.cafe.CafeCoordinate; -import com.project.yozmcafe.domain.cafe.CafeCoordinateRepository; import com.project.yozmcafe.domain.cafe.CafeRepository; import com.project.yozmcafe.domain.cafe.Images; +import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinate; +import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinateRepository; import com.project.yozmcafe.exception.BadRequestException; import jakarta.persistence.EntityManager; diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java index 0a6dcdd6..c398de87 100644 --- a/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test; import org.locationtech.jts.geom.Point; +import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinate; import com.project.yozmcafe.fixture.Fixture; class CafeCoordinateTest { diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java new file mode 100644 index 00000000..d708bdf3 --- /dev/null +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java @@ -0,0 +1,46 @@ +package com.project.yozmcafe.domain.cafe.coordinate; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import com.project.yozmcafe.BaseTest; +import com.project.yozmcafe.domain.cafe.Cafe; +import com.project.yozmcafe.domain.cafe.CafeRepository; +import com.project.yozmcafe.domain.cafe.PointGenerator; +import com.project.yozmcafe.domain.cafe.coordinate.dto.CafePinDto; +import com.project.yozmcafe.fixture.Fixture; + +class CafeCoordinateRepositoryTest extends BaseTest { + + @Autowired + private CafeCoordinateRepository cafeCoordinateRepository; + + @Autowired + private CafeRepository cafeRepository; + + @Test + @DisplayName("반경내의 카페 정보를 모두 반환한다.") + void findCafePinsFromCoordinate() { + //given + final Cafe cafe1 = cafeRepository.save(Fixture.getCafe("cafe1", "주소1", 0)); + final Cafe cafe2 = cafeRepository.save(Fixture.getCafe("cafe2", "주소2", 0)); + + final CafeCoordinate coordinate1 = new CafeCoordinate(PointGenerator.generateWithCoordinate(20, 10), cafe1); + cafeCoordinateRepository.save(coordinate1); + + final CafeCoordinate coordinate2 = new CafeCoordinate(PointGenerator.generateWithCoordinate(60, 50), cafe2); + cafeCoordinateRepository.save(coordinate2); + + //when + final List cafePins = cafeCoordinateRepository.findCafePinsFromCoordinate( + "POINT(20.00001 10.00001)", 500); + + //then + assertThat(cafePins).hasSize(1); + } +} diff --git a/server/src/test/java/com/project/yozmcafe/service/CafeAdminServiceTest.java b/server/src/test/java/com/project/yozmcafe/service/CafeAdminServiceTest.java index 872c5a24..7d0084d8 100644 --- a/server/src/test/java/com/project/yozmcafe/service/CafeAdminServiceTest.java +++ b/server/src/test/java/com/project/yozmcafe/service/CafeAdminServiceTest.java @@ -21,12 +21,12 @@ import com.project.yozmcafe.controller.dto.cafe.CafeUpdateRequest; import com.project.yozmcafe.controller.dto.cafe.DetailRequest; import com.project.yozmcafe.domain.cafe.Cafe; -import com.project.yozmcafe.domain.cafe.CafeCoordinate; -import com.project.yozmcafe.domain.cafe.CafeCoordinateRepository; import com.project.yozmcafe.domain.cafe.CafeRepository; import com.project.yozmcafe.domain.cafe.Detail; import com.project.yozmcafe.domain.cafe.Images; import com.project.yozmcafe.domain.cafe.available.Days; +import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinate; +import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinateRepository; import com.project.yozmcafe.exception.BadRequestException; class CafeAdminServiceTest extends BaseTest { From 48ba832ea76d6a4fcb273a117adcad19c2e315ca Mon Sep 17 00:00:00 2001 From: dev_kong Date: Fri, 15 Sep 2023 19:58:23 +0900 Subject: [PATCH 11/31] =?UTF-8?q?feat:=20=EC=9C=84=EB=8F=84=20=EA=B2=BD?= =?UTF-8?q?=EB=8F=84=20=EB=8D=B8=ED=83=80=EA=B0=92=EC=9D=84=20=ED=86=B5?= =?UTF-8?q?=ED=95=B4=20=EA=B0=80=EC=9E=A5=20=EC=9E=91=EC=9D=80=20=EB=B0=98?= =?UTF-8?q?=EA=B2=BD=EC=9D=98=20=ED=81=AC=EA=B8=B0=EB=A5=BC=20=EA=B5=AC?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cafe/coordinate/RadiusCalculator.java | 17 +++++++++++++ .../cafe/coordinate/RadiusCalculatorTest.java | 24 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculator.java create mode 100644 server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculatorTest.java diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculator.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculator.java new file mode 100644 index 00000000..a443a30a --- /dev/null +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculator.java @@ -0,0 +1,17 @@ +package com.project.yozmcafe.domain.cafe.coordinate; + +public class RadiusCalculator { + private static final int METER_PER_DEGREE = 111_000; + + private RadiusCalculator() { + } + + public static double calculate(final double latitude, final double latitudeDelta, final double longitudeDelta) { + double radianLatitude = Math.toRadians(latitude); + + double metersLatitude = latitudeDelta * METER_PER_DEGREE; + double metersLongitude = Math.cos(radianLatitude) * longitudeDelta * METER_PER_DEGREE; + + return Math.min(metersLatitude, metersLongitude); + } +} diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculatorTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculatorTest.java new file mode 100644 index 00000000..721b4655 --- /dev/null +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculatorTest.java @@ -0,0 +1,24 @@ +package com.project.yozmcafe.domain.cafe.coordinate; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +class RadiusCalculatorTest { + + @Test + @DisplayName("radius를 계산하여 반환한다") + void calculate() { + //given + final double latitude = 20; + final double latitudeDelta = 0.001; + final double longitudeDelta = 10; + + //when + final double radius = RadiusCalculator.calculate(latitude, latitudeDelta, longitudeDelta); + + //then + assertThat(radius).isEqualTo(111); + } +} From 8a4773ff5264576c8a41262ec91623e8ba9b8550 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Fri, 15 Sep 2023 21:39:35 +0900 Subject: [PATCH 12/31] =?UTF-8?q?feat:=20=EC=9C=84=EB=8F=84=20=EA=B2=BD?= =?UTF-8?q?=EB=8F=84=EB=A5=BC=20=ED=86=B5=ED=95=B4=20=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A7=81=ED=98=95=EC=8B=9D=EC=9D=98=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=EB=A5=BC=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yozmcafe/domain/cafe/PointGenerator.java | 11 +++++++++++ .../yozmcafe/domain/cafe/PointGeneratorTest.java | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java index c2f29f97..f05b7a46 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java @@ -8,6 +8,8 @@ public class PointGenerator { private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(); private static final int SRID = 4326; + private static final String STRING_POINT_FORMAT = "POINT(%s)"; + private static final String STRING_POINT_DELIMITER = " "; private PointGenerator() { } @@ -17,4 +19,13 @@ public static Point generateWithCoordinate(final double latitude, final double l point.setSRID(SRID); return point; } + + public static String generateStringPoint(final double latitude, final double longitude) { + final String coordinate = String.join( + STRING_POINT_DELIMITER, + String.valueOf(latitude), + String.valueOf(longitude) + ); + return String.format(STRING_POINT_FORMAT, coordinate); + } } diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java index ac0933ac..8f95b48a 100644 --- a/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java @@ -30,4 +30,17 @@ void generate() { }); } + @Test + @DisplayName("스트링 포인트 생성") + void generateStringPoint() { + //given + final double latitude = 20; + final double longitude = 10; + + //when + final String point = PointGenerator.generateStringPoint(latitude, longitude); + + //then + assertThat(point).isEqualTo("POINT(20.0 10.0)"); + } } From 6c858178ca43ee9a28a081b7ddd1e45fc8a83da1 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Fri, 15 Sep 2023 21:52:54 +0900 Subject: [PATCH 13/31] =?UTF-8?q?feat:=20=EA=B8=B0=EC=A4=80=20=EC=A2=8C?= =?UTF-8?q?=ED=91=9C=EC=99=80,=20=EB=8D=B8=ED=83=80=20=EC=A2=8C=ED=91=9C?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=9B=EC=95=84=20=EB=B0=98=EA=B2=BD=EC=95=88?= =?UTF-8?q?=EC=97=90=20=ED=8F=AC=ED=95=A8=EB=90=9C=20=EC=B9=B4=ED=8E=98?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/cafe/CafeLocationResponse.java | 16 +++++ .../yozmcafe/service/LocationService.java | 36 +++++++++++ .../yozmcafe/service/LocationServiceTest.java | 60 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationResponse.java create mode 100644 server/src/main/java/com/project/yozmcafe/service/LocationService.java create mode 100644 server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java diff --git a/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationResponse.java b/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationResponse.java new file mode 100644 index 00000000..4dbdfd06 --- /dev/null +++ b/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationResponse.java @@ -0,0 +1,16 @@ +package com.project.yozmcafe.controller.dto.cafe; + +import com.project.yozmcafe.domain.cafe.coordinate.dto.CafePinDto; + +public record CafeLocationResponse(Long id, String name, String address, double latitude, double longitude) { + + public static CafeLocationResponse from(final CafePinDto cafePinDto) { + return new CafeLocationResponse( + cafePinDto.getId(), + cafePinDto.getName(), + cafePinDto.getName(), + cafePinDto.getLatitude(), + cafePinDto.getLongitude() + ); + } +} diff --git a/server/src/main/java/com/project/yozmcafe/service/LocationService.java b/server/src/main/java/com/project/yozmcafe/service/LocationService.java new file mode 100644 index 00000000..b394e7c2 --- /dev/null +++ b/server/src/main/java/com/project/yozmcafe/service/LocationService.java @@ -0,0 +1,36 @@ +package com.project.yozmcafe.service; + +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.project.yozmcafe.controller.dto.cafe.CafeLocationResponse; +import com.project.yozmcafe.domain.cafe.PointGenerator; +import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinateRepository; +import com.project.yozmcafe.domain.cafe.coordinate.RadiusCalculator; +import com.project.yozmcafe.domain.cafe.coordinate.dto.CafePinDto; + +@Service +@Transactional(readOnly = true) +public class LocationService { + + private final CafeCoordinateRepository cafeCoordinateRepository; + + public LocationService(final CafeCoordinateRepository cafeCoordinateRepository) { + this.cafeCoordinateRepository = cafeCoordinateRepository; + } + + public List findCafesFromLocations(final double latitude, + final double longitude, + final double latitudeDelta, + final double longitudeDelta) { + final String point = PointGenerator.generateStringPoint(latitude, longitude); + final double radius = RadiusCalculator.calculate(latitude, latitudeDelta, longitudeDelta); + final List cafeLocationDtos = cafeCoordinateRepository.findCafePinsFromCoordinate(point, + radius); + return cafeLocationDtos.stream() + .map(CafeLocationResponse::from) + .toList(); + } +} diff --git a/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java b/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java new file mode 100644 index 00000000..f6a611c2 --- /dev/null +++ b/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java @@ -0,0 +1,60 @@ +package com.project.yozmcafe.service; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.SoftAssertions.assertSoftly; + +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import com.project.yozmcafe.BaseTest; +import com.project.yozmcafe.controller.dto.cafe.CafeLocationResponse; +import com.project.yozmcafe.domain.cafe.Cafe; +import com.project.yozmcafe.domain.cafe.CafeRepository; +import com.project.yozmcafe.domain.cafe.PointGenerator; +import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinate; +import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinateRepository; +import com.project.yozmcafe.fixture.Fixture; + +class LocationServiceTest extends BaseTest { + + @Autowired + private LocationService locationService; + + @Autowired + private CafeCoordinateRepository cafeCoordinateRepository; + + @Autowired + private CafeRepository cafeRepository; + + @Test + @DisplayName("기준 좌표와, 델타 좌표를 받아 반경안에 포함된 카페를 반환한다.") + void findCafesFromLocations() { + //given + final Cafe cafe1 = cafeRepository.save(Fixture.getCafe("cafe1", "주소1", 0)); + final Cafe cafe2 = cafeRepository.save(Fixture.getCafe("cafe2", "주소2", 0)); + + final CafeCoordinate coordinate1 = new CafeCoordinate(PointGenerator.generateWithCoordinate(20, 10), cafe1); + cafeCoordinateRepository.save(coordinate1); + + final CafeCoordinate coordinate2 = new CafeCoordinate(PointGenerator.generateWithCoordinate(60, 50), cafe2); + cafeCoordinateRepository.save(coordinate2); + + //when + final List results = locationService.findCafesFromLocations( + 20.00001, + 10.00001, + 0.004504504505, + 1); + + //then + assertSoftly(softAssertions -> { + assertThat(results).hasSize(1); + assertThat(results.get(0).id()).isEqualTo(cafe1.getId()); + assertThat(results.get(0).latitude()).isEqualTo(20); + assertThat(results.get(0).longitude()).isEqualTo(10); + }); + } +} From 80c755a4603328823fdcf2472499cdb655d6d23f Mon Sep 17 00:00:00 2001 From: dev_kong Date: Sat, 16 Sep 2023 02:23:19 +0900 Subject: [PATCH 14/31] =?UTF-8?q?feat:=20=EC=A7=80=EB=8F=84=EC=97=90=20?= =?UTF-8?q?=ED=91=9C=EC=8B=9C=20=EB=90=A0=20=EC=88=98=20=EC=9E=88=EB=8A=94?= =?UTF-8?q?=20=EC=B9=B4=ED=8E=98=EB=93=A4=EC=9D=84=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=ED=95=98=EB=8A=94=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LocationController.java | 38 +++++ .../controller/LocationControllerTest.java | 148 ++++++++++++++++++ 2 files changed, 186 insertions(+) create mode 100644 server/src/main/java/com/project/yozmcafe/controller/LocationController.java create mode 100644 server/src/test/java/com/project/yozmcafe/controller/LocationControllerTest.java diff --git a/server/src/main/java/com/project/yozmcafe/controller/LocationController.java b/server/src/main/java/com/project/yozmcafe/controller/LocationController.java new file mode 100644 index 00000000..e13e749c --- /dev/null +++ b/server/src/main/java/com/project/yozmcafe/controller/LocationController.java @@ -0,0 +1,38 @@ +package com.project.yozmcafe.controller; + +import java.util.List; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.project.yozmcafe.controller.dto.cafe.CafeLocationResponse; +import com.project.yozmcafe.service.LocationService; + +@RestController +@RequestMapping("/cafes/location") +public class LocationController { + + private final LocationService locationService; + + public LocationController(final LocationService locationService) { + this.locationService = locationService; + } + + @GetMapping + public ResponseEntity> findCafesFromLocation( + @RequestParam("latitude") final double latitude, + @RequestParam("longitude") final double longitude, + @RequestParam("latitudeDelta") final double latitudeDelta, + @RequestParam("longitudeDelta") final double longitudeDelta) { + final List cafesFromLocations = locationService.findCafesFromLocations( + latitude, + longitude, + latitudeDelta, + longitudeDelta + ); + return ResponseEntity.ok(cafesFromLocations); + } +} diff --git a/server/src/test/java/com/project/yozmcafe/controller/LocationControllerTest.java b/server/src/test/java/com/project/yozmcafe/controller/LocationControllerTest.java new file mode 100644 index 00000000..6650081d --- /dev/null +++ b/server/src/test/java/com/project/yozmcafe/controller/LocationControllerTest.java @@ -0,0 +1,148 @@ +package com.project.yozmcafe.controller; + +import static com.epages.restdocs.apispec.RestAssuredRestDocumentationWrapper.document; +import static io.restassured.RestAssured.given; +import static io.restassured.http.ContentType.JSON; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +import static org.springframework.restdocs.request.RequestDocumentation.queryParameters; + +import java.io.File; +import java.time.LocalTime; +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.SpyBean; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.project.yozmcafe.controller.dto.cafe.AvailableTimeRequest; +import com.project.yozmcafe.controller.dto.cafe.CafeCoordinateRequest; +import com.project.yozmcafe.controller.dto.cafe.CafeLocationResponse; +import com.project.yozmcafe.controller.dto.cafe.CafeRequest; +import com.project.yozmcafe.controller.dto.cafe.DetailRequest; +import com.project.yozmcafe.domain.S3Client; +import com.project.yozmcafe.domain.cafe.CafeRepository; +import com.project.yozmcafe.domain.cafe.available.Days; + +import io.restassured.response.Response; + +class LocationControllerTest extends BaseControllerTest { + + @Autowired + private ObjectMapper mapper; + @SpyBean + private S3Client s3Client; + @Autowired + CafeRepository cafeRepository; + + private File image = new File("src/test/resources/image.png"); + + @Test + @DisplayName("입력받은 좌표와 델타 좌표로 범위내에 있는 모든 카페를 반환한다.") + void findCafesFromLocation() { + //given + doNothing().when(s3Client).upload(any()); + final String cafeId1 = saveCafe("폴로카페", "영도"); + final String cafeId2 = saveCafe("솔스카페", "기장"); + final String cafeId3 = saveCafe("오션카페", "인천"); + final String cafeId4 = saveCafe("도치카페", "서울역"); + final String cafeId5 = saveCafe("연어카페", "부산"); + final String cafeId6 = saveCafe("고니카페", "강동"); + final String cafeId7 = saveCafe("아인카페", "아르헨티나"); + saveLocation(cafeId1, 20.001, 10); + saveLocation(cafeId2, 20.002, 10); + saveLocation(cafeId3, 20.003, 10); + saveLocation(cafeId4, 20.004, 10); + saveLocation(cafeId5, 20.005, 10); + saveLocation(cafeId6, 20.006, 10); + saveLocation(cafeId7, 20.007, 10); + + //when + final Response response = given(spec) + .log().all() + .filter(document("Location/지도 범위 내 모든 카페 조회", + queryParameters( + parameterWithName("latitude").description("기준 위도"), + parameterWithName("longitude").description("기준 경도"), + parameterWithName("latitudeDelta").description("기준 위도로부터 지도 내 최고 위도까지의 차"), + parameterWithName("longitudeDelta").description("기준 경도로부터 지도 내 최고 경도까지의 차") + ), + responseFields( + fieldWithPath("[].id").description("카페 Id"), + fieldWithPath("[].name").description("카페 이름"), + fieldWithPath("[].address").description("카페 주소"), + fieldWithPath("[].latitude").description("카페의 위도"), + fieldWithPath("[].longitude").description("카페의 경도") + ))) + .when() + .get("/cafes/location?latitude=20&longitude=10&latitudeDelta=0.004504504505&longitudeDelta=1"); + + final List results = response.then().log().all() + .extract().jsonPath().getList(".", CafeLocationResponse.class); + + //then + assertSoftly(softAssertions -> { + assertThat(response.statusCode()).isEqualTo(200); + assertThat(results).hasSize(4); + }); + } + + private void saveLocation(final String cafeId, final double latitude, final double longitude) { + given() + .contentType(JSON) + .body(new CafeCoordinateRequest(latitude, longitude)) + .when() + .post("/admin/cafes/{cafeId}/coordinate", cafeId); + } + + private String saveCafe(final String name, final String address) { + final String cafeRequest = makeCafeRequest(name, address); + final String location = given().log().all() + .contentType("multipart/form-data;charset=UTF-8") + .multiPart("request", cafeRequest, "application/json") + .multiPart("images", image, "image/png") + .when() + .post("/admin/cafes") + .then() + .extract().header("Location"); + + String[] split = location.split("/"); + + return split[split.length - 1]; + } + + private String makeCafeRequest(final String name, final String address) { + try { + return mapper.writeValueAsString(new CafeRequest(name, address, detail())); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private DetailRequest detail() { + final AvailableTimeRequest time1 = new AvailableTimeRequest(Days.MONDAY, LocalTime.now(), LocalTime.now(), + true); + final AvailableTimeRequest time2 = new AvailableTimeRequest(Days.TUESDAY, LocalTime.now(), LocalTime.now(), + true); + final AvailableTimeRequest time3 = new AvailableTimeRequest(Days.WEDNESDAY, LocalTime.now(), LocalTime.now(), + true); + final AvailableTimeRequest time4 = new AvailableTimeRequest(Days.THURSDAY, LocalTime.now(), LocalTime.now(), + true); + final AvailableTimeRequest time5 = new AvailableTimeRequest(Days.FRIDAY, LocalTime.now(), LocalTime.now(), + true); + final AvailableTimeRequest time6 = new AvailableTimeRequest(Days.SATURDAY, LocalTime.now(), LocalTime.now(), + true); + final AvailableTimeRequest time7 = new AvailableTimeRequest(Days.SUNDAY, LocalTime.now(), LocalTime.now(), + true); + + return new DetailRequest(List.of(time1, time2, time3, time4, time5, time6, time7), + "지도 url", "존맛탱구리", "01032472601"); + } +} From 90f3c49272d0ccbfac7ef8673de9b7b939cb2bc3 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Sat, 16 Sep 2023 19:10:37 +0900 Subject: [PATCH 15/31] =?UTF-8?q?chore:=20index=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/migration/V20230914151731__add_point_column.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql b/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql index 465ea980..07a688cc 100644 --- a/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql +++ b/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql @@ -6,3 +6,5 @@ CREATE TABLE cafe_coordinates PRIMARY KEY (id), FOREIGN KEY (cafe_id) REFERENCES cafe (id) ); + +CREATE SPATIAL INDEX idx_coordinates ON cafe_coordinates (coordinate); From 6673f30baec175d84c384218d5971de53d54d819 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Wed, 20 Sep 2023 20:53:31 +0900 Subject: [PATCH 16/31] =?UTF-8?q?chore:=20properties=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?&=20hibernate-spatial=20gradle=EB=82=B4=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/build.gradle | 2 +- server/src/main/resources/application.properties | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/server/build.gradle b/server/build.gradle index 30621a4f..79a2f5f8 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -19,13 +19,13 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' - implementation group: 'org.hibernate', name: 'hibernate-spatial', version: '6.2.5.Final' testImplementation 'org.springframework.boot:spring-boot-starter-test' //DB runtimeOnly 'com.mysql:mysql-connector-j' testImplementation "org.testcontainers:junit-jupiter:1.19.0" testImplementation 'org.testcontainers:mysql' + implementation group: 'org.hibernate', name: 'hibernate-spatial', version: '6.2.5.Final' //JWT implementation 'io.jsonwebtoken:jjwt-api:0.11.5' diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties index 674da02c..e484a103 100644 --- a/server/src/main/resources/application.properties +++ b/server/src/main/resources/application.properties @@ -2,7 +2,6 @@ spring.datasource.url=jdbc:mysql://localhost:20000/yozm-cafe?useSSL=false&allowP spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.jpa.database-platform=org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect spring.jpa.hibernate.ddl-auto=validate spring.auth.key=testtesttesttesttesttesttesttesttesttesttesttesttesttesttest spring.auth.accessTokenExpired=360000 From e8da93bc3faa92f029e570fc61feafa0252222f8 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Wed, 20 Sep 2023 20:55:25 +0900 Subject: [PATCH 17/31] =?UTF-8?q?chore:=20cafe=5Fcoordinates=20->=20cafe?= =?UTF-8?q?=5Fcoordinate=20=ED=85=8C=EC=9D=B4=EB=B8=94=20=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.java | 2 +- .../db/migration/V20230914151731__add_point_column.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.java index 5fb84d15..613f6c0d 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.java @@ -12,7 +12,7 @@ import jakarta.persistence.Id; import jakarta.persistence.OneToOne; -@Entity(name = "cafe_coordinates") +@Entity(name = "cafe_coordinate") public class CafeCoordinate { @Id diff --git a/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql b/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql index 07a688cc..00c07f45 100644 --- a/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql +++ b/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql @@ -1,4 +1,4 @@ -CREATE TABLE cafe_coordinates +CREATE TABLE cafe_coordinate ( id BIGINT NOT NULL AUTO_INCREMENT, coordinate POINT NOT NULL SRID 4326, From 0ffc53595c08e1d2ae265abe522a46962aa54b06 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Wed, 20 Sep 2023 20:56:21 +0900 Subject: [PATCH 18/31] =?UTF-8?q?refactor:=20`@ElementCollection`=20fetch?= =?UTF-8?q?=20=EC=98=B5=EC=85=98=20=EC=A0=9C=EA=B1=B0(default=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/project/yozmcafe/domain/cafe/Images.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/Images.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/Images.java index 3519b825..0b901af3 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/Images.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/Images.java @@ -1,18 +1,17 @@ package com.project.yozmcafe.domain.cafe; +import java.util.List; + import jakarta.persistence.CollectionTable; import jakarta.persistence.ElementCollection; import jakarta.persistence.Embeddable; -import jakarta.persistence.FetchType; - -import java.util.List; @Embeddable public class Images { private static final int REPRESENTATIVE_INDEX = 0; - @ElementCollection(fetch = FetchType.LAZY) + @ElementCollection @CollectionTable(name = "image") private List urls; From aae9b1573334d60964b23f5a9d662113dcc0436e Mon Sep 17 00:00:00 2001 From: dev_kong Date: Wed, 20 Sep 2023 21:04:36 +0900 Subject: [PATCH 19/31] =?UTF-8?q?chore:=20SRID=20=EC=84=A4=EB=AA=85=20?= =?UTF-8?q?=EC=A3=BC=EC=84=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/yozmcafe/domain/cafe/PointGenerator.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java index f05b7a46..4a0a4be8 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java @@ -7,6 +7,11 @@ public class PointGenerator { private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(); + /** + * SRID(Spatial Reference Identifier)는 고유한 공간 좌표 식별자입니다. + *

+ * 그 중, 4326은 WGS84 경위도 좌표계를 의미합니다. GPS 기술에서도 사용되는 좌표계로 범용적으로 가장 널리 사용되는 좌표계입니다. + */ private static final int SRID = 4326; private static final String STRING_POINT_FORMAT = "POINT(%s)"; private static final String STRING_POINT_DELIMITER = " "; From fab67efe2cb51d25cf3c6b663e40c4415e40288d Mon Sep 17 00:00:00 2001 From: dev_kong Date: Wed, 20 Sep 2023 21:17:42 +0900 Subject: [PATCH 20/31] =?UTF-8?q?fix:=20CafeLocationResponse=20=EC=97=90?= =?UTF-8?q?=20name=20=EC=A4=91=EB=B3=B5=EC=9C=BC=EB=A1=9C=20=EB=93=A4?= =?UTF-8?q?=EC=96=B4=EA=B0=84=20=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yozmcafe/controller/dto/cafe/CafeLocationResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationResponse.java b/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationResponse.java index 4dbdfd06..60ce4a31 100644 --- a/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationResponse.java +++ b/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationResponse.java @@ -8,7 +8,7 @@ public static CafeLocationResponse from(final CafePinDto cafePinDto) { return new CafeLocationResponse( cafePinDto.getId(), cafePinDto.getName(), - cafePinDto.getName(), + cafePinDto.getAddress(), cafePinDto.getLatitude(), cafePinDto.getLongitude() ); From 7713312669f2a1fd310ee90b1e3493fcd4f4210e Mon Sep 17 00:00:00 2001 From: dev_kong Date: Wed, 20 Sep 2023 21:19:32 +0900 Subject: [PATCH 21/31] =?UTF-8?q?chore:=20coordinate=20=EC=9D=B8=EB=8D=B1?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1=20=EC=BF=BC=EB=A6=AC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/migration/V20230914151731__add_point_column.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql b/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql index 00c07f45..8f51704d 100644 --- a/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql +++ b/server/src/main/resources/db/migration/V20230914151731__add_point_column.sql @@ -7,4 +7,4 @@ CREATE TABLE cafe_coordinate FOREIGN KEY (cafe_id) REFERENCES cafe (id) ); -CREATE SPATIAL INDEX idx_coordinates ON cafe_coordinates (coordinate); +CREATE SPATIAL INDEX idx_coordinates ON cafe_coordinate (coordinate); From cb5074f3ec535756ea884d7d5001f2c435c5e62e Mon Sep 17 00:00:00 2001 From: dev_kong Date: Wed, 20 Sep 2023 21:30:00 +0900 Subject: [PATCH 22/31] =?UTF-8?q?fix:=20native=EC=BF=BC=EB=A6=AC=20table?= =?UTF-8?q?=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 --- .../domain/cafe/coordinate/CafeCoordinateRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java index 064ce673..67ef3038 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java @@ -13,7 +13,7 @@ public interface CafeCoordinateRepository extends JpaRepository Date: Wed, 20 Sep 2023 22:10:34 +0900 Subject: [PATCH 23/31] =?UTF-8?q?refactor:=20`@QueryParam`=20dto=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yozmcafe/controller/LocationController.java | 13 +++---------- .../controller/dto/cafe/CafeLocationRequest.java | 4 ++++ .../project/yozmcafe/service/LocationService.java | 15 +++++++++------ .../yozmcafe/service/LocationServiceTest.java | 13 ++++++++++--- 4 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationRequest.java diff --git a/server/src/main/java/com/project/yozmcafe/controller/LocationController.java b/server/src/main/java/com/project/yozmcafe/controller/LocationController.java index e13e749c..8239100c 100644 --- a/server/src/main/java/com/project/yozmcafe/controller/LocationController.java +++ b/server/src/main/java/com/project/yozmcafe/controller/LocationController.java @@ -5,9 +5,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.project.yozmcafe.controller.dto.cafe.CafeLocationRequest; import com.project.yozmcafe.controller.dto.cafe.CafeLocationResponse; import com.project.yozmcafe.service.LocationService; @@ -23,16 +23,9 @@ public LocationController(final LocationService locationService) { @GetMapping public ResponseEntity> findCafesFromLocation( - @RequestParam("latitude") final double latitude, - @RequestParam("longitude") final double longitude, - @RequestParam("latitudeDelta") final double latitudeDelta, - @RequestParam("longitudeDelta") final double longitudeDelta) { + final CafeLocationRequest cafeLocationRequest) { final List cafesFromLocations = locationService.findCafesFromLocations( - latitude, - longitude, - latitudeDelta, - longitudeDelta - ); + cafeLocationRequest); return ResponseEntity.ok(cafesFromLocations); } } diff --git a/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationRequest.java b/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationRequest.java new file mode 100644 index 00000000..7f6d6b9e --- /dev/null +++ b/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeLocationRequest.java @@ -0,0 +1,4 @@ +package com.project.yozmcafe.controller.dto.cafe; + +public record CafeLocationRequest(double latitude, double longitude, double latitudeDelta, double longitudeDelta) { +} diff --git a/server/src/main/java/com/project/yozmcafe/service/LocationService.java b/server/src/main/java/com/project/yozmcafe/service/LocationService.java index b394e7c2..dd78087a 100644 --- a/server/src/main/java/com/project/yozmcafe/service/LocationService.java +++ b/server/src/main/java/com/project/yozmcafe/service/LocationService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.project.yozmcafe.controller.dto.cafe.CafeLocationRequest; import com.project.yozmcafe.controller.dto.cafe.CafeLocationResponse; import com.project.yozmcafe.domain.cafe.PointGenerator; import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinateRepository; @@ -21,14 +22,16 @@ public LocationService(final CafeCoordinateRepository cafeCoordinateRepository) this.cafeCoordinateRepository = cafeCoordinateRepository; } - public List findCafesFromLocations(final double latitude, - final double longitude, - final double latitudeDelta, - final double longitudeDelta) { + public List findCafesFromLocations(final CafeLocationRequest cafeLocationRequest) { + final double latitude = cafeLocationRequest.latitude(); + final double longitude = cafeLocationRequest.longitude(); + final double latitudeDelta = cafeLocationRequest.latitudeDelta(); + final double longitudeDelta = cafeLocationRequest.longitudeDelta(); + final String point = PointGenerator.generateStringPoint(latitude, longitude); final double radius = RadiusCalculator.calculate(latitude, latitudeDelta, longitudeDelta); - final List cafeLocationDtos = cafeCoordinateRepository.findCafePinsFromCoordinate(point, - radius); + final List cafeLocationDtos = cafeCoordinateRepository.findCafePinsFromCoordinate(point, radius); + return cafeLocationDtos.stream() .map(CafeLocationResponse::from) .toList(); diff --git a/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java b/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java index f6a611c2..c70131e9 100644 --- a/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java +++ b/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import com.project.yozmcafe.BaseTest; +import com.project.yozmcafe.controller.dto.cafe.CafeLocationRequest; import com.project.yozmcafe.controller.dto.cafe.CafeLocationResponse; import com.project.yozmcafe.domain.cafe.Cafe; import com.project.yozmcafe.domain.cafe.CafeRepository; @@ -42,12 +43,18 @@ void findCafesFromLocations() { final CafeCoordinate coordinate2 = new CafeCoordinate(PointGenerator.generateWithCoordinate(60, 50), cafe2); cafeCoordinateRepository.save(coordinate2); - //when - final List results = locationService.findCafesFromLocations( + final CafeLocationRequest cafeLocationRequest = new CafeLocationRequest( 20.00001, 10.00001, 0.004504504505, - 1); + 1 + ); + + //when + + final List results = locationService.findCafesFromLocations( + cafeLocationRequest + ); //then assertSoftly(softAssertions -> { From e6774f55f383d37ea50f261e2857ccc114d9cf4e Mon Sep 17 00:00:00 2001 From: dev_kong Date: Thu, 21 Sep 2023 21:10:09 +0900 Subject: [PATCH 24/31] feat: GeometryGenerator#generateStringPolygon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기준점과 델타값들을 통해 최소위도(경도)와 최대위도(경도)를 구하여 문자열 폴리곤 생성하는 기능 구현 --- .../dto/cafe/CafeCoordinateRequest.java | 4 +- .../domain/cafe/GeometryGenerator.java | 60 +++++++++++++++++++ .../yozmcafe/domain/cafe/PointGenerator.java | 36 ----------- .../yozmcafe/service/LocationService.java | 4 +- .../domain/cafe/CafeCoordinateTest.java | 2 +- ...orTest.java => GeometryGeneratorTest.java} | 22 ++++++- .../CafeCoordinateRepositoryTest.java | 8 ++- .../yozmcafe/service/LocationServiceTest.java | 8 ++- 8 files changed, 94 insertions(+), 50 deletions(-) create mode 100644 server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.java delete mode 100644 server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java rename server/src/test/java/com/project/yozmcafe/domain/cafe/{PointGeneratorTest.java => GeometryGeneratorTest.java} (59%) diff --git a/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.java b/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.java index 117f1345..82ea6bbd 100644 --- a/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.java +++ b/server/src/main/java/com/project/yozmcafe/controller/dto/cafe/CafeCoordinateRequest.java @@ -3,13 +3,13 @@ import org.locationtech.jts.geom.Point; import com.project.yozmcafe.domain.cafe.Cafe; -import com.project.yozmcafe.domain.cafe.PointGenerator; +import com.project.yozmcafe.domain.cafe.GeometryGenerator; import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinate; public record CafeCoordinateRequest(double latitude, double longitude) { public CafeCoordinate toCafeCoordinateWithCafe(final Cafe cafe) { - final Point point = PointGenerator.generateWithCoordinate(latitude, longitude); + final Point point = GeometryGenerator.generatePointWithCoordinate(latitude, longitude); return new CafeCoordinate(point, cafe); } } diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.java new file mode 100644 index 00000000..55b79ccc --- /dev/null +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.java @@ -0,0 +1,60 @@ +package com.project.yozmcafe.domain.cafe; + +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.Point; + +import com.project.yozmcafe.controller.dto.cafe.CafeLocationRequest; + +public class GeometryGenerator { + + private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(); + /** + * SRID(Spatial Reference Identifier)는 고유한 공간 좌표 식별자입니다. + *

+ * 그 중, 4326은 WGS84 경위도 좌표계를 의미합니다. GPS 기술에서도 사용되는 좌표계로 범용적으로 가장 널리 사용되는 좌표계입니다. + */ + private static final int SRID = 4326; + private static final String STRING_POINT_FORMAT = "POINT(%s)"; + private static final String STRING_POLYGON_FORMAT = "POLYGON(%s)"; + private static final String STRING_GEOMETRY_DELIMITER = " "; + private static final String POINT_DELIMITER = ", "; + + private GeometryGenerator() { + } + + public static Point generatePointWithCoordinate(final double latitude, final double longitude) { + final Point point = GEOMETRY_FACTORY.createPoint(new Coordinate(longitude, latitude)); + point.setSRID(SRID); + return point; + } + + public static String generateStringPoint(final double latitude, final double longitude) { + final String coordinate = String.join( + STRING_GEOMETRY_DELIMITER, + String.valueOf(latitude), + String.valueOf(longitude) + ); + return String.format(STRING_POINT_FORMAT, coordinate); + } + + public static String generateStringPolygon(final CafeLocationRequest cafeLocationRequest) { + final double latitude = cafeLocationRequest.latitude(); + final double longitude = cafeLocationRequest.longitude(); + final double latitudeDelta = cafeLocationRequest.latitudeDelta(); + final double longitudeDelta = cafeLocationRequest.longitudeDelta(); + + final String minLatitude = String.valueOf(latitude - latitudeDelta); + final String maxLatitude = String.valueOf(latitude + latitudeDelta); + final String minLongitude = String.valueOf(longitude - longitudeDelta); + final String maxLongitude = String.valueOf(longitude + longitudeDelta); + + final String firstVertex = String.join(STRING_GEOMETRY_DELIMITER, minLatitude, maxLongitude); + final String secondVertex = String.join(STRING_GEOMETRY_DELIMITER, maxLatitude, maxLongitude); + final String thirdVertex = String.join(STRING_GEOMETRY_DELIMITER, maxLatitude, minLongitude); + final String fourthVertex = String.join(STRING_GEOMETRY_DELIMITER, minLatitude, minLongitude); + + final String vertexes = String.join(POINT_DELIMITER, firstVertex, secondVertex, thirdVertex, fourthVertex); + return String.format(STRING_POLYGON_FORMAT, vertexes); + } +} diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java deleted file mode 100644 index 4a0a4be8..00000000 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/PointGenerator.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.project.yozmcafe.domain.cafe; - -import org.locationtech.jts.geom.Coordinate; -import org.locationtech.jts.geom.GeometryFactory; -import org.locationtech.jts.geom.Point; - -public class PointGenerator { - - private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(); - /** - * SRID(Spatial Reference Identifier)는 고유한 공간 좌표 식별자입니다. - *

- * 그 중, 4326은 WGS84 경위도 좌표계를 의미합니다. GPS 기술에서도 사용되는 좌표계로 범용적으로 가장 널리 사용되는 좌표계입니다. - */ - private static final int SRID = 4326; - private static final String STRING_POINT_FORMAT = "POINT(%s)"; - private static final String STRING_POINT_DELIMITER = " "; - - private PointGenerator() { - } - - public static Point generateWithCoordinate(final double latitude, final double longitude) { - final Point point = GEOMETRY_FACTORY.createPoint(new Coordinate(longitude, latitude)); - point.setSRID(SRID); - return point; - } - - public static String generateStringPoint(final double latitude, final double longitude) { - final String coordinate = String.join( - STRING_POINT_DELIMITER, - String.valueOf(latitude), - String.valueOf(longitude) - ); - return String.format(STRING_POINT_FORMAT, coordinate); - } -} diff --git a/server/src/main/java/com/project/yozmcafe/service/LocationService.java b/server/src/main/java/com/project/yozmcafe/service/LocationService.java index dd78087a..8f7cf9f8 100644 --- a/server/src/main/java/com/project/yozmcafe/service/LocationService.java +++ b/server/src/main/java/com/project/yozmcafe/service/LocationService.java @@ -7,7 +7,7 @@ import com.project.yozmcafe.controller.dto.cafe.CafeLocationRequest; import com.project.yozmcafe.controller.dto.cafe.CafeLocationResponse; -import com.project.yozmcafe.domain.cafe.PointGenerator; +import com.project.yozmcafe.domain.cafe.GeometryGenerator; import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinateRepository; import com.project.yozmcafe.domain.cafe.coordinate.RadiusCalculator; import com.project.yozmcafe.domain.cafe.coordinate.dto.CafePinDto; @@ -28,7 +28,7 @@ public List findCafesFromLocations(final CafeLocationReque final double latitudeDelta = cafeLocationRequest.latitudeDelta(); final double longitudeDelta = cafeLocationRequest.longitudeDelta(); - final String point = PointGenerator.generateStringPoint(latitude, longitude); + final String point = GeometryGenerator.generateStringPoint(latitude, longitude); final double radius = RadiusCalculator.calculate(latitude, latitudeDelta, longitudeDelta); final List cafeLocationDtos = cafeCoordinateRepository.findCafePinsFromCoordinate(point, radius); diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java index c398de87..e32d6e1d 100644 --- a/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/CafeCoordinateTest.java @@ -18,7 +18,7 @@ void getLatitudeAndLongitude() { //given final double latitude = 20.0; final double longitude = 10.0; - final Point point = PointGenerator.generateWithCoordinate(latitude, longitude); + final Point point = GeometryGenerator.generatePointWithCoordinate(latitude, longitude); final Cafe cafe = Fixture.getCafe("카페", "성수동", 0); final CafeCoordinate cafeCoordinate = new CafeCoordinate(point, cafe); diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/GeometryGeneratorTest.java similarity index 59% rename from server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java rename to server/src/test/java/com/project/yozmcafe/domain/cafe/GeometryGeneratorTest.java index 8f95b48a..148e88fe 100644 --- a/server/src/test/java/com/project/yozmcafe/domain/cafe/PointGeneratorTest.java +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/GeometryGeneratorTest.java @@ -7,7 +7,9 @@ import org.junit.jupiter.api.Test; import org.locationtech.jts.geom.Point; -class PointGeneratorTest { +import com.project.yozmcafe.controller.dto.cafe.CafeLocationRequest; + +class GeometryGeneratorTest { @Test @DisplayName("포인트 생성 테스트") @@ -15,7 +17,7 @@ void generate() { //given final double latitude = 20; final double longitude = 10; - final Point point = PointGenerator.generateWithCoordinate(latitude, longitude); + final Point point = GeometryGenerator.generatePointWithCoordinate(latitude, longitude); //when final int srid = point.getSRID(); @@ -38,9 +40,23 @@ void generateStringPoint() { final double longitude = 10; //when - final String point = PointGenerator.generateStringPoint(latitude, longitude); + final String point = GeometryGenerator.generateStringPoint(latitude, longitude); //then assertThat(point).isEqualTo("POINT(20.0 10.0)"); } + + @Test + @DisplayName("스트링 폴리곤 생성") + void generateStringPolygonTest() { + //given + final CafeLocationRequest cafeLocationRequest = new CafeLocationRequest(20, 10, 3, 1); + final String expected = "POLYGON(17.0 11.0, 23.0 11.0, 23.0 9.0, 17.0 9.0)"; + + //when + final String result = GeometryGenerator.generateStringPolygon(cafeLocationRequest); + + //then + assertThat(result).isEqualTo(expected); + } } diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java index d708bdf3..56440b04 100644 --- a/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java @@ -11,7 +11,7 @@ import com.project.yozmcafe.BaseTest; import com.project.yozmcafe.domain.cafe.Cafe; import com.project.yozmcafe.domain.cafe.CafeRepository; -import com.project.yozmcafe.domain.cafe.PointGenerator; +import com.project.yozmcafe.domain.cafe.GeometryGenerator; import com.project.yozmcafe.domain.cafe.coordinate.dto.CafePinDto; import com.project.yozmcafe.fixture.Fixture; @@ -30,10 +30,12 @@ void findCafePinsFromCoordinate() { final Cafe cafe1 = cafeRepository.save(Fixture.getCafe("cafe1", "주소1", 0)); final Cafe cafe2 = cafeRepository.save(Fixture.getCafe("cafe2", "주소2", 0)); - final CafeCoordinate coordinate1 = new CafeCoordinate(PointGenerator.generateWithCoordinate(20, 10), cafe1); + final CafeCoordinate coordinate1 = new CafeCoordinate(GeometryGenerator.generatePointWithCoordinate(20, 10), + cafe1); cafeCoordinateRepository.save(coordinate1); - final CafeCoordinate coordinate2 = new CafeCoordinate(PointGenerator.generateWithCoordinate(60, 50), cafe2); + final CafeCoordinate coordinate2 = new CafeCoordinate(GeometryGenerator.generatePointWithCoordinate(60, 50), + cafe2); cafeCoordinateRepository.save(coordinate2); //when diff --git a/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java b/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java index c70131e9..5d4ccd4a 100644 --- a/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java +++ b/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java @@ -14,7 +14,7 @@ import com.project.yozmcafe.controller.dto.cafe.CafeLocationResponse; import com.project.yozmcafe.domain.cafe.Cafe; import com.project.yozmcafe.domain.cafe.CafeRepository; -import com.project.yozmcafe.domain.cafe.PointGenerator; +import com.project.yozmcafe.domain.cafe.GeometryGenerator; import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinate; import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinateRepository; import com.project.yozmcafe.fixture.Fixture; @@ -37,10 +37,12 @@ void findCafesFromLocations() { final Cafe cafe1 = cafeRepository.save(Fixture.getCafe("cafe1", "주소1", 0)); final Cafe cafe2 = cafeRepository.save(Fixture.getCafe("cafe2", "주소2", 0)); - final CafeCoordinate coordinate1 = new CafeCoordinate(PointGenerator.generateWithCoordinate(20, 10), cafe1); + final CafeCoordinate coordinate1 = new CafeCoordinate(GeometryGenerator.generatePointWithCoordinate(20, 10), + cafe1); cafeCoordinateRepository.save(coordinate1); - final CafeCoordinate coordinate2 = new CafeCoordinate(PointGenerator.generateWithCoordinate(60, 50), cafe2); + final CafeCoordinate coordinate2 = new CafeCoordinate(GeometryGenerator.generatePointWithCoordinate(60, 50), + cafe2); cafeCoordinateRepository.save(coordinate2); final CafeLocationRequest cafeLocationRequest = new CafeLocationRequest( From a44ac828fec949a79b52d3c8d5dafa74480aa35b Mon Sep 17 00:00:00 2001 From: dev_kong Date: Thu, 21 Sep 2023 21:46:17 +0900 Subject: [PATCH 25/31] =?UTF-8?q?feat:=20STRING=5FPOLYGON=5FFORMAT=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/project/yozmcafe/domain/cafe/GeometryGenerator.java | 5 +++-- .../project/yozmcafe/domain/cafe/GeometryGeneratorTest.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.java index 55b79ccc..d7c8c7f0 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.java @@ -16,7 +16,7 @@ public class GeometryGenerator { */ private static final int SRID = 4326; private static final String STRING_POINT_FORMAT = "POINT(%s)"; - private static final String STRING_POLYGON_FORMAT = "POLYGON(%s)"; + private static final String STRING_POLYGON_FORMAT = "POLYGON((%s))"; private static final String STRING_GEOMETRY_DELIMITER = " "; private static final String POINT_DELIMITER = ", "; @@ -54,7 +54,8 @@ public static String generateStringPolygon(final CafeLocationRequest cafeLocatio final String thirdVertex = String.join(STRING_GEOMETRY_DELIMITER, maxLatitude, minLongitude); final String fourthVertex = String.join(STRING_GEOMETRY_DELIMITER, minLatitude, minLongitude); - final String vertexes = String.join(POINT_DELIMITER, firstVertex, secondVertex, thirdVertex, fourthVertex); + final String vertexes = String.join(POINT_DELIMITER, firstVertex, secondVertex, thirdVertex, fourthVertex, + firstVertex); return String.format(STRING_POLYGON_FORMAT, vertexes); } } diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/GeometryGeneratorTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/GeometryGeneratorTest.java index 148e88fe..c7de727c 100644 --- a/server/src/test/java/com/project/yozmcafe/domain/cafe/GeometryGeneratorTest.java +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/GeometryGeneratorTest.java @@ -51,7 +51,7 @@ void generateStringPoint() { void generateStringPolygonTest() { //given final CafeLocationRequest cafeLocationRequest = new CafeLocationRequest(20, 10, 3, 1); - final String expected = "POLYGON(17.0 11.0, 23.0 11.0, 23.0 9.0, 17.0 9.0)"; + final String expected = "POLYGON((17.0 11.0, 23.0 11.0, 23.0 9.0, 17.0 9.0, 17.0 11.0))"; //when final String result = GeometryGenerator.generateStringPolygon(cafeLocationRequest); From 93b795a1d9b3e9d477f138d4a6fc84c503176b3c Mon Sep 17 00:00:00 2001 From: dev_kong Date: Thu, 21 Sep 2023 21:54:05 +0900 Subject: [PATCH 26/31] =?UTF-8?q?feat:=20area=20=EB=82=B4=EB=B6=80?= =?UTF-8?q?=EC=97=90=20=EC=9E=88=EB=8A=94=20=EC=B9=B4=ED=8E=98=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coordinate/CafeCoordinateRepository.java | 10 ++++++++ .../CafeCoordinateRepositoryTest.java | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java index 67ef3038..eb5fba7c 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java @@ -20,4 +20,14 @@ SELECT c.id, c.name, c.address, ST_X(co.coordinate) AS latitude, ST_Y(co.coordin """) List findCafePinsFromCoordinate(@Param("point") final String point, @Param("radius") final double radius); + + @Query(nativeQuery = true, + value = """ + SELECT c.id, c.name, c.address, ST_X(co.coordinate) AS latitude, ST_Y(co.coordinate) AS longitude + FROM cafe_coordinate co + JOIN cafe AS c + ON co.cafe_id = c.id + WHERE ST_CONTAINS(ST_GeomFromText(:area, 4326), co.coordinate); + """) + List findCafePinsFromCoordinate(@Param("area") final String area); } diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java index 56440b04..e1478189 100644 --- a/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java @@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import com.project.yozmcafe.BaseTest; +import com.project.yozmcafe.controller.dto.cafe.CafeLocationRequest; import com.project.yozmcafe.domain.cafe.Cafe; import com.project.yozmcafe.domain.cafe.CafeRepository; import com.project.yozmcafe.domain.cafe.GeometryGenerator; @@ -45,4 +46,28 @@ void findCafePinsFromCoordinate() { //then assertThat(cafePins).hasSize(1); } + + @Test + @DisplayName("영역 내의 모든 카페 정보를 반환한다.") + void findCafePinsFromCoordinateWithAreaTest() { + //given + final Cafe cafe1 = cafeRepository.save(Fixture.getCafe("cafe1", "주소1", 0)); + final Cafe cafe2 = cafeRepository.save(Fixture.getCafe("cafe2", "주소2", 0)); + + final CafeCoordinate coordinate1 = new CafeCoordinate(GeometryGenerator.generatePointWithCoordinate(20, 10), + cafe1); + cafeCoordinateRepository.save(coordinate1); + + final CafeCoordinate coordinate2 = new CafeCoordinate(GeometryGenerator.generatePointWithCoordinate(60, 50), + cafe2); + cafeCoordinateRepository.save(coordinate2); + final CafeLocationRequest cafeLocationRequest = new CafeLocationRequest(20, 10, 3, 1); + final String area = GeometryGenerator.generateStringPolygon(cafeLocationRequest); + + //when + final List cafePins = cafeCoordinateRepository.findCafePinsFromCoordinate(area); + + //then + assertThat(cafePins).hasSize(1); + } } From 56188a576ce925b5e90a546be683c8184839fa90 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Thu, 21 Sep 2023 22:00:11 +0900 Subject: [PATCH 27/31] =?UTF-8?q?refactor:=20=EC=A2=8C=ED=91=9C=EA=B8=B0?= =?UTF-8?q?=EB=B0=98=20=EC=B9=B4=ED=8E=98=EA=B2=80=EC=83=89=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존에는 원을 그려서 원내부의 카페 데이터만 반환했으나, 화면에 보이는 지도전체(사각형)에 포함된 카페데이터를 반환하도록 변경 --- .../com/project/yozmcafe/service/LocationService.java | 11 ++--------- .../yozmcafe/controller/LocationControllerTest.java | 4 ++-- .../project/yozmcafe/service/LocationServiceTest.java | 1 - 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/server/src/main/java/com/project/yozmcafe/service/LocationService.java b/server/src/main/java/com/project/yozmcafe/service/LocationService.java index 8f7cf9f8..b7e2fe8e 100644 --- a/server/src/main/java/com/project/yozmcafe/service/LocationService.java +++ b/server/src/main/java/com/project/yozmcafe/service/LocationService.java @@ -9,7 +9,6 @@ import com.project.yozmcafe.controller.dto.cafe.CafeLocationResponse; import com.project.yozmcafe.domain.cafe.GeometryGenerator; import com.project.yozmcafe.domain.cafe.coordinate.CafeCoordinateRepository; -import com.project.yozmcafe.domain.cafe.coordinate.RadiusCalculator; import com.project.yozmcafe.domain.cafe.coordinate.dto.CafePinDto; @Service @@ -23,14 +22,8 @@ public LocationService(final CafeCoordinateRepository cafeCoordinateRepository) } public List findCafesFromLocations(final CafeLocationRequest cafeLocationRequest) { - final double latitude = cafeLocationRequest.latitude(); - final double longitude = cafeLocationRequest.longitude(); - final double latitudeDelta = cafeLocationRequest.latitudeDelta(); - final double longitudeDelta = cafeLocationRequest.longitudeDelta(); - - final String point = GeometryGenerator.generateStringPoint(latitude, longitude); - final double radius = RadiusCalculator.calculate(latitude, latitudeDelta, longitudeDelta); - final List cafeLocationDtos = cafeCoordinateRepository.findCafePinsFromCoordinate(point, radius); + final String area = GeometryGenerator.generateStringPolygon(cafeLocationRequest); + final List cafeLocationDtos = cafeCoordinateRepository.findCafePinsFromCoordinate(area); return cafeLocationDtos.stream() .map(CafeLocationResponse::from) diff --git a/server/src/test/java/com/project/yozmcafe/controller/LocationControllerTest.java b/server/src/test/java/com/project/yozmcafe/controller/LocationControllerTest.java index 6650081d..381bef7c 100644 --- a/server/src/test/java/com/project/yozmcafe/controller/LocationControllerTest.java +++ b/server/src/test/java/com/project/yozmcafe/controller/LocationControllerTest.java @@ -62,7 +62,7 @@ void findCafesFromLocation() { saveLocation(cafeId4, 20.004, 10); saveLocation(cafeId5, 20.005, 10); saveLocation(cafeId6, 20.006, 10); - saveLocation(cafeId7, 20.007, 10); + saveLocation(cafeId7, 30.007, 10); //when final Response response = given(spec) @@ -90,7 +90,7 @@ void findCafesFromLocation() { //then assertSoftly(softAssertions -> { assertThat(response.statusCode()).isEqualTo(200); - assertThat(results).hasSize(4); + assertThat(results).hasSize(6); }); } diff --git a/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java b/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java index 5d4ccd4a..a5c6cd8f 100644 --- a/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java +++ b/server/src/test/java/com/project/yozmcafe/service/LocationServiceTest.java @@ -53,7 +53,6 @@ void findCafesFromLocations() { ); //when - final List results = locationService.findCafesFromLocations( cafeLocationRequest ); From eb52d233cf68afaf5bf4ca50a6be2a2665b308a6 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Thu, 21 Sep 2023 22:03:25 +0900 Subject: [PATCH 28/31] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EA=B0=92=20&=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/cafe/GeometryGenerator.java | 10 -------- .../coordinate/CafeCoordinateRepository.java | 11 --------- .../domain/cafe/GeometryGeneratorTest.java | 14 ----------- .../CafeCoordinateRepositoryTest.java | 23 ------------------- 4 files changed, 58 deletions(-) diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.java index d7c8c7f0..394e448e 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/GeometryGenerator.java @@ -15,7 +15,6 @@ public class GeometryGenerator { * 그 중, 4326은 WGS84 경위도 좌표계를 의미합니다. GPS 기술에서도 사용되는 좌표계로 범용적으로 가장 널리 사용되는 좌표계입니다. */ private static final int SRID = 4326; - private static final String STRING_POINT_FORMAT = "POINT(%s)"; private static final String STRING_POLYGON_FORMAT = "POLYGON((%s))"; private static final String STRING_GEOMETRY_DELIMITER = " "; private static final String POINT_DELIMITER = ", "; @@ -29,15 +28,6 @@ public static Point generatePointWithCoordinate(final double latitude, final dou return point; } - public static String generateStringPoint(final double latitude, final double longitude) { - final String coordinate = String.join( - STRING_GEOMETRY_DELIMITER, - String.valueOf(latitude), - String.valueOf(longitude) - ); - return String.format(STRING_POINT_FORMAT, coordinate); - } - public static String generateStringPolygon(final CafeLocationRequest cafeLocationRequest) { final double latitude = cafeLocationRequest.latitude(); final double longitude = cafeLocationRequest.longitude(); diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java index eb5fba7c..7bfc7183 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepository.java @@ -10,17 +10,6 @@ public interface CafeCoordinateRepository extends JpaRepository { - @Query(nativeQuery = true, - value = """ - SELECT c.id, c.name, c.address, ST_X(co.coordinate) AS latitude, ST_Y(co.coordinate) AS longitude - FROM cafe_coordinate co - JOIN cafe AS c - ON co.cafe_id = c.id - WHERE ST_CONTAINS(ST_Buffer(ST_GeomFromText(:point, 4326), :radius), co.coordinate); - """) - List findCafePinsFromCoordinate(@Param("point") final String point, - @Param("radius") final double radius); - @Query(nativeQuery = true, value = """ SELECT c.id, c.name, c.address, ST_X(co.coordinate) AS latitude, ST_Y(co.coordinate) AS longitude diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/GeometryGeneratorTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/GeometryGeneratorTest.java index c7de727c..2d31c8d2 100644 --- a/server/src/test/java/com/project/yozmcafe/domain/cafe/GeometryGeneratorTest.java +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/GeometryGeneratorTest.java @@ -32,20 +32,6 @@ void generate() { }); } - @Test - @DisplayName("스트링 포인트 생성") - void generateStringPoint() { - //given - final double latitude = 20; - final double longitude = 10; - - //when - final String point = GeometryGenerator.generateStringPoint(latitude, longitude); - - //then - assertThat(point).isEqualTo("POINT(20.0 10.0)"); - } - @Test @DisplayName("스트링 폴리곤 생성") void generateStringPolygonTest() { diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java index e1478189..ad0b702a 100644 --- a/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java +++ b/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinateRepositoryTest.java @@ -24,29 +24,6 @@ class CafeCoordinateRepositoryTest extends BaseTest { @Autowired private CafeRepository cafeRepository; - @Test - @DisplayName("반경내의 카페 정보를 모두 반환한다.") - void findCafePinsFromCoordinate() { - //given - final Cafe cafe1 = cafeRepository.save(Fixture.getCafe("cafe1", "주소1", 0)); - final Cafe cafe2 = cafeRepository.save(Fixture.getCafe("cafe2", "주소2", 0)); - - final CafeCoordinate coordinate1 = new CafeCoordinate(GeometryGenerator.generatePointWithCoordinate(20, 10), - cafe1); - cafeCoordinateRepository.save(coordinate1); - - final CafeCoordinate coordinate2 = new CafeCoordinate(GeometryGenerator.generatePointWithCoordinate(60, 50), - cafe2); - cafeCoordinateRepository.save(coordinate2); - - //when - final List cafePins = cafeCoordinateRepository.findCafePinsFromCoordinate( - "POINT(20.00001 10.00001)", 500); - - //then - assertThat(cafePins).hasSize(1); - } - @Test @DisplayName("영역 내의 모든 카페 정보를 반환한다.") void findCafePinsFromCoordinateWithAreaTest() { From 7c42a0159c1ff1c34d1fa0e8bd70cccad6f9d880 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Fri, 22 Sep 2023 17:34:01 +0900 Subject: [PATCH 29/31] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cafe/coordinate/RadiusCalculator.java | 17 ------------- .../cafe/coordinate/RadiusCalculatorTest.java | 24 ------------------- 2 files changed, 41 deletions(-) delete mode 100644 server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculator.java delete mode 100644 server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculatorTest.java diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculator.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculator.java deleted file mode 100644 index a443a30a..00000000 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculator.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.project.yozmcafe.domain.cafe.coordinate; - -public class RadiusCalculator { - private static final int METER_PER_DEGREE = 111_000; - - private RadiusCalculator() { - } - - public static double calculate(final double latitude, final double latitudeDelta, final double longitudeDelta) { - double radianLatitude = Math.toRadians(latitude); - - double metersLatitude = latitudeDelta * METER_PER_DEGREE; - double metersLongitude = Math.cos(radianLatitude) * longitudeDelta * METER_PER_DEGREE; - - return Math.min(metersLatitude, metersLongitude); - } -} diff --git a/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculatorTest.java b/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculatorTest.java deleted file mode 100644 index 721b4655..00000000 --- a/server/src/test/java/com/project/yozmcafe/domain/cafe/coordinate/RadiusCalculatorTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.project.yozmcafe.domain.cafe.coordinate; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -class RadiusCalculatorTest { - - @Test - @DisplayName("radius를 계산하여 반환한다") - void calculate() { - //given - final double latitude = 20; - final double latitudeDelta = 0.001; - final double longitudeDelta = 10; - - //when - final double radius = RadiusCalculator.calculate(latitude, latitudeDelta, longitudeDelta); - - //then - assertThat(radius).isEqualTo(111); - } -} From c379a6c41a204b368dfa9e73d147cbfd12ffc801 Mon Sep 17 00:00:00 2001 From: dev_kong Date: Mon, 25 Sep 2023 14:26:44 +0900 Subject: [PATCH 30/31] =?UTF-8?q?chore:=20spatial=20=EB=94=94=ED=8E=9C?= =?UTF-8?q?=EB=8D=98=EC=8B=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/build.gradle b/server/build.gradle index 79a2f5f8..6dae4d74 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -25,7 +25,7 @@ dependencies { runtimeOnly 'com.mysql:mysql-connector-j' testImplementation "org.testcontainers:junit-jupiter:1.19.0" testImplementation 'org.testcontainers:mysql' - implementation group: 'org.hibernate', name: 'hibernate-spatial', version: '6.2.5.Final' + implementation 'org.hibernate:hibernate-spatial:6.2.5.Final' //JWT implementation 'io.jsonwebtoken:jjwt-api:0.11.5' From 4d014f2d357401d242d27f675ce95fdc48957bed Mon Sep 17 00:00:00 2001 From: dev_kong Date: Mon, 25 Sep 2023 14:28:27 +0900 Subject: [PATCH 31/31] =?UTF-8?q?refactor:=20CafeCoordinate=20name=20optio?= =?UTF-8?q?n=20=EC=82=AD=EC=A0=9C=20&=20=EA=B8=B0=EB=B3=B8=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EC=A0=91=EA=B7=BC=EC=A0=9C=ED=95=9C=20pub?= =?UTF-8?q?lic=20->=20protected?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yozmcafe/domain/cafe/coordinate/CafeCoordinate.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.java b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.java index 613f6c0d..9e1f6a1b 100644 --- a/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.java +++ b/server/src/main/java/com/project/yozmcafe/domain/cafe/coordinate/CafeCoordinate.java @@ -12,7 +12,7 @@ import jakarta.persistence.Id; import jakarta.persistence.OneToOne; -@Entity(name = "cafe_coordinate") +@Entity public class CafeCoordinate { @Id @@ -24,7 +24,7 @@ public class CafeCoordinate { @OneToOne(fetch = FetchType.LAZY) private Cafe cafe; - public CafeCoordinate() { + protected CafeCoordinate() { } public CafeCoordinate(final Long id, final Point coordinate, final Cafe cafe) {