From 5db0a246c67457a128ae82d950f560e75728d784 Mon Sep 17 00:00:00 2001 From: Moon1C Date: Mon, 6 May 2024 01:47:56 +0900 Subject: [PATCH 01/23] =?UTF-8?q?refactor:=20BaseEntity=EC=9D=98=20PK=20?= =?UTF-8?q?=EC=84=A0=EC=96=B8=20=EB=B0=A9=EC=8B=9D=EC=9D=84=20IDENTITY->SE?= =?UTF-8?q?QUENCE=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/src/main/java/com/walking/data/entity/BaseEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/src/main/java/com/walking/data/entity/BaseEntity.java b/data/src/main/java/com/walking/data/entity/BaseEntity.java index 1cfe9d66..a28d879c 100644 --- a/data/src/main/java/com/walking/data/entity/BaseEntity.java +++ b/data/src/main/java/com/walking/data/entity/BaseEntity.java @@ -29,7 +29,7 @@ public abstract class BaseEntity { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) + @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long id; @Column(nullable = false, updatable = false) From cb3d3c63148e2f86689937a74b5038223dde5590 Mon Sep 17 00:00:00 2001 From: Moon1C Date: Mon, 6 May 2024 01:48:29 +0900 Subject: [PATCH 02/23] =?UTF-8?q?feat:=20MemberEntity=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 경# 제목을 작성하고 반드시 빈 줄 한 줄을 만들어야 함 --- .../data/entity/member/MemberEntity.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 data/src/main/java/com/walking/data/entity/member/MemberEntity.java diff --git a/data/src/main/java/com/walking/data/entity/member/MemberEntity.java b/data/src/main/java/com/walking/data/entity/member/MemberEntity.java new file mode 100644 index 00000000..82a91dab --- /dev/null +++ b/data/src/main/java/com/walking/data/entity/member/MemberEntity.java @@ -0,0 +1,33 @@ +package com.walking.data.entity.member; + +import com.walking.data.entity.BaseEntity; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.SQLDelete; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Entity +@SuperBuilder(toBuilder = true) +@Table(name = "member") +@SQLDelete(sql = "UPDATE member SET deleted=true where id=?") +public class MemberEntity extends BaseEntity { + + @Column(nullable = false) + private String memberId; + + @Column(nullable = false) + private String password; + + + + +} From aaa504994b7410ff2e8f845103e5fa0ac7572900 Mon Sep 17 00:00:00 2001 From: Moon1C Date: Mon, 6 May 2024 01:48:46 +0900 Subject: [PATCH 03/23] =?UTF-8?q?feat:=20TrafficEntity=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/entity/traffic/TrafficEntity.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java diff --git a/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java b/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java new file mode 100644 index 00000000..8c3a877f --- /dev/null +++ b/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java @@ -0,0 +1,35 @@ +package com.walking.data.entity.traffic; + + +import com.walking.data.entity.BaseEntity; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.SQLDelete; +import org.locationtech.jts.geom.Point; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Entity +@SuperBuilder(toBuilder = true) +@Table(name = "traffic") +@SQLDelete(sql = "UPDATE traffic SET deleted=true where id=?") +public class TrafficEntity extends BaseEntity { + + @Column(nullable = false , updatable = false) + private String detail; + + @Column(nullable = false) + private String name; + + @Column( columnDefinition = "POINT SRID 4326", nullable = false) + private Point point; + +} From a7ce12e5e3e62b962ba5cd131ff657d601dd89b6 Mon Sep 17 00:00:00 2001 From: Moon1C Date: Mon, 6 May 2024 01:49:04 +0900 Subject: [PATCH 04/23] =?UTF-8?q?feat:=20PathFavoritesEntity=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/member/PathFavoritesEntity.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 data/src/main/java/com/walking/data/entity/member/PathFavoritesEntity.java diff --git a/data/src/main/java/com/walking/data/entity/member/PathFavoritesEntity.java b/data/src/main/java/com/walking/data/entity/member/PathFavoritesEntity.java new file mode 100644 index 00000000..563e2581 --- /dev/null +++ b/data/src/main/java/com/walking/data/entity/member/PathFavoritesEntity.java @@ -0,0 +1,45 @@ +package com.walking.data.entity.member; + +import com.walking.data.entity.BaseEntity; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.SQLDelete; +import org.locationtech.jts.geom.LineString; +import org.locationtech.jts.geom.Point; + +import javax.persistence.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Entity +@SuperBuilder(toBuilder = true) +@Table(name = "path_favorites") +@SQLDelete(sql = "UPDATE path_favorites SET deleted=true where id=?") +public class PathFavoritesEntity extends BaseEntity { + + @ManyToOne(fetch = FetchType.LAZY) + private MemberEntity memberEntity; + + @Column(columnDefinition = "POINT") + private Point startPoint; + + @Column(columnDefinition = "POINT") + private Point endPoint; + + @Column(columnDefinition = "LINESTRING") + private LineString path; + + @Column(nullable = false) + private String startAlias; + + @Column(nullable = false) + private String endAlias; + + + + +} From da0366ef287b4194b856f013b818e93fc9b2a1fb Mon Sep 17 00:00:00 2001 From: Moon1C Date: Mon, 6 May 2024 01:49:18 +0900 Subject: [PATCH 05/23] =?UTF-8?q?feat:=20TrafficFavoritesEntity=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/member/TrafficFavoritesEntity.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 data/src/main/java/com/walking/data/entity/member/TrafficFavoritesEntity.java diff --git a/data/src/main/java/com/walking/data/entity/member/TrafficFavoritesEntity.java b/data/src/main/java/com/walking/data/entity/member/TrafficFavoritesEntity.java new file mode 100644 index 00000000..25026334 --- /dev/null +++ b/data/src/main/java/com/walking/data/entity/member/TrafficFavoritesEntity.java @@ -0,0 +1,32 @@ +package com.walking.data.entity.member; + +import com.walking.data.entity.BaseEntity; +import com.walking.data.entity.traffic.TrafficEntity; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.SQLDelete; + +import javax.persistence.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Entity +@SuperBuilder(toBuilder = true) +@Table(name = "traffic_favorites") +@SQLDelete(sql = "UPDATE traffuc_favorites SET deleted=true where id=?") +public class TrafficFavoritesEntity extends BaseEntity { + + @ManyToOne(fetch = FetchType.LAZY) + private MemberEntity memberEntity; + + @OneToOne(fetch = FetchType.LAZY) + private TrafficEntity trafficEntity; + + @Column(nullable = false) + private String alias; + +} From f629406390fe8b486a41555578d21754eb5e2bc4 Mon Sep 17 00:00:00 2001 From: Moon1C Date: Mon, 6 May 2024 01:50:05 +0900 Subject: [PATCH 06/23] =?UTF-8?q?feat:=20application-data-local.yml=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=97=90=20mysql=EC=9D=98=20spatial=20?= =?UTF-8?q?=EB=B0=A9=EC=96=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/src/main/resources/application-data-local.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/src/main/resources/application-data-local.yml b/data/src/main/resources/application-data-local.yml index 117f9aaa..619d6cca 100644 --- a/data/src/main/resources/application-data-local.yml +++ b/data/src/main/resources/application-data-local.yml @@ -4,4 +4,6 @@ spring: ddl-auto: update properties: hibernate: - format_sql: true \ No newline at end of file + format_sql: true + dialect: org.hibernate.spatial.dialect.mysql.MySQL8SpatialDialect + From 7c2499da44fac8a71fec54f30e907c7917df1ffa Mon Sep 17 00:00:00 2001 From: Moon1C Date: Mon, 6 May 2024 01:54:04 +0900 Subject: [PATCH 07/23] =?UTF-8?q?feat:=20hibernate-spatial=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index 2cf2f492..8f50f220 100644 --- a/build.gradle +++ b/build.gradle @@ -93,6 +93,9 @@ subprojects { // validation implementation 'org.springframework.boot:spring-boot-starter-validation' + // hibernate spatial + implementation 'org.hibernate:hibernate-spatial' + // test testImplementation 'org.springframework.boot:spring-boot-starter-test' } From 264f7dc3c84c5d91cb54723e948f62a260905411 Mon Sep 17 00:00:00 2001 From: Moon1C Date: Mon, 6 May 2024 01:54:52 +0900 Subject: [PATCH 08/23] =?UTF-8?q?feat:=20Repository=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/web/repository/member/MemberRepository.java | 8 ++++++++ .../web/repository/member/PathFavoritesRepository.java | 8 ++++++++ .../web/repository/member/TrafficFavoritesRepository.java | 8 ++++++++ .../api/web/repository/traffic/TrafficRepository.java | 8 ++++++++ 4 files changed, 32 insertions(+) create mode 100644 api/src/main/java/com/walking/api/web/repository/member/MemberRepository.java create mode 100644 api/src/main/java/com/walking/api/web/repository/member/PathFavoritesRepository.java create mode 100644 api/src/main/java/com/walking/api/web/repository/member/TrafficFavoritesRepository.java create mode 100644 api/src/main/java/com/walking/api/web/repository/traffic/TrafficRepository.java diff --git a/api/src/main/java/com/walking/api/web/repository/member/MemberRepository.java b/api/src/main/java/com/walking/api/web/repository/member/MemberRepository.java new file mode 100644 index 00000000..8d3312df --- /dev/null +++ b/api/src/main/java/com/walking/api/web/repository/member/MemberRepository.java @@ -0,0 +1,8 @@ +package com.walking.api.web.repository.member; + +import com.walking.data.entity.member.MemberEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface MemberRepository extends JpaRepository {} diff --git a/api/src/main/java/com/walking/api/web/repository/member/PathFavoritesRepository.java b/api/src/main/java/com/walking/api/web/repository/member/PathFavoritesRepository.java new file mode 100644 index 00000000..71131a1b --- /dev/null +++ b/api/src/main/java/com/walking/api/web/repository/member/PathFavoritesRepository.java @@ -0,0 +1,8 @@ +package com.walking.api.web.repository.member; + +import com.walking.data.entity.member.PathFavoritesEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface PathFavoritesRepository extends JpaRepository {} diff --git a/api/src/main/java/com/walking/api/web/repository/member/TrafficFavoritesRepository.java b/api/src/main/java/com/walking/api/web/repository/member/TrafficFavoritesRepository.java new file mode 100644 index 00000000..3d59d871 --- /dev/null +++ b/api/src/main/java/com/walking/api/web/repository/member/TrafficFavoritesRepository.java @@ -0,0 +1,8 @@ +package com.walking.api.web.repository.member; + +import com.walking.data.entity.member.TrafficFavoritesEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface TrafficFavoritesRepository extends JpaRepository {} diff --git a/api/src/main/java/com/walking/api/web/repository/traffic/TrafficRepository.java b/api/src/main/java/com/walking/api/web/repository/traffic/TrafficRepository.java new file mode 100644 index 00000000..8c4e3349 --- /dev/null +++ b/api/src/main/java/com/walking/api/web/repository/traffic/TrafficRepository.java @@ -0,0 +1,8 @@ +package com.walking.api.web.repository.traffic; + +import com.walking.data.entity.traffic.TrafficEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface TrafficRepository extends JpaRepository {} From 358689daedf17c1c98926c8a101d58fd5ba52cd4 Mon Sep 17 00:00:00 2001 From: Moon1C Date: Mon, 6 May 2024 01:55:18 +0900 Subject: [PATCH 09/23] =?UTF-8?q?Test:=20Entity=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/com/walking/api/RepoTest.java | 142 ++++++++++++++++++ .../java/com/walking/api/RepositoryTest.java | 41 +++++ 2 files changed, 183 insertions(+) create mode 100644 api/src/test/java/com/walking/api/RepoTest.java create mode 100644 api/src/test/java/com/walking/api/RepositoryTest.java diff --git a/api/src/test/java/com/walking/api/RepoTest.java b/api/src/test/java/com/walking/api/RepoTest.java new file mode 100644 index 00000000..f4e258cd --- /dev/null +++ b/api/src/test/java/com/walking/api/RepoTest.java @@ -0,0 +1,142 @@ +package com.walking.api; + +import com.walking.api.web.repository.member.MemberRepository; +import com.walking.api.web.repository.member.PathFavoritesRepository; +import com.walking.api.web.repository.member.TrafficFavoritesRepository; +import com.walking.api.web.repository.traffic.TrafficRepository; +import com.walking.data.entity.member.MemberEntity; +import com.walking.data.entity.member.PathFavoritesEntity; +import com.walking.data.entity.member.TrafficFavoritesEntity; +import com.walking.data.entity.traffic.TrafficEntity; +import java.util.Optional; +import javax.persistence.EntityManager; +import lombok.extern.slf4j.Slf4j; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.LineString; +import org.locationtech.jts.geom.Point; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.Rollback; + +@Slf4j +public class RepoTest extends RepositoryTest { + + @Autowired EntityManager em; + + @Autowired MemberRepository memberRepository; + + @Autowired TrafficRepository trafficRepository; + + @Autowired PathFavoritesRepository pathFavoritesRepository; + @Autowired TrafficFavoritesRepository trafficFavoritesRepository; + + @Nested + class MemberEntityTest { + + @Test + // @Rollback(value = false) + public void saveMember() { + MemberEntity memberEntity = MemberEntity.builder().memberId("124").password("123").build(); + + MemberEntity saved = memberRepository.save(memberEntity); + + Assertions.assertThat(memberEntity.getId()).isEqualTo(saved.getId()); + } + + @Test + // @Rollback(value = false) + public void deleteMember() { + MemberEntity memberEntity = MemberEntity.builder().memberId("123").password("123").build(); + + MemberEntity saved = memberRepository.save(memberEntity); + } + + @Test + // @Rollback(value = false) + public void saveTraffic() { + + GeometryFactory gf = new GeometryFactory(); + Point point = gf.createPoint(new Coordinate(123, 321)); + + TrafficEntity traffic = + TrafficEntity.builder().detail("123-L").name("제법이 집 앞").point(point).build(); + + TrafficEntity savedTraffic = trafficRepository.save(traffic); + + Optional findTraffic = trafficRepository.findById(savedTraffic.getId()); + + Assertions.assertThat(traffic.getId()).isEqualTo(findTraffic.get().getId()); + } + + @Test + @Rollback(value = false) + public void saveTrafficFavorites() { + + GeometryFactory gf = new GeometryFactory(); + Point point = gf.createPoint(new Coordinate(123, 321)); + + MemberEntity memberEntity = MemberEntity.builder().memberId("123").password("123").build(); + + TrafficEntity traffic = + TrafficEntity.builder().detail("123-L").name("제법이 집 앞").point(point).build(); + + em.persist(memberEntity); + em.persist(traffic); + em.flush(); + + TrafficFavoritesEntity trafficFavorites = + TrafficFavoritesEntity.builder() + .memberEntity(memberEntity) + .trafficEntity(traffic) + .alias("123") + .build(); + + TrafficFavoritesEntity save = trafficFavoritesRepository.save(trafficFavorites); + + TrafficFavoritesEntity trafficFavoritesEntity = + trafficFavoritesRepository.findById(save.getId()).get(); + + Assertions.assertThat(save.getId()).isEqualTo(trafficFavoritesEntity.getId()); + } + + @Test + @Rollback(value = false) + public void savePathFavorites() { + + GeometryFactory gf = new GeometryFactory(); + Coordinate[] coordinates = new Coordinate[3]; + for (int i = 0; i < 3; i++) { + coordinates[i] = new Coordinate(i * 10, i * 20); + } + LineString lineString = gf.createLineString(coordinates); + + Point startPoint = gf.createPoint(coordinates[0]); + Point endPoint = gf.createPoint(coordinates[2]); + + MemberEntity memberEntity = MemberEntity.builder().memberId("123").password("123").build(); + + em.persist(memberEntity); + em.flush(); + + PathFavoritesEntity build = + PathFavoritesEntity.builder() + .memberEntity(memberEntity) + .startPoint(startPoint) + .startAlias("시작") + .endPoint(endPoint) + .endAlias("끝") + .path(lineString) + .build(); + + PathFavoritesEntity save = pathFavoritesRepository.save(build); + + PathFavoritesEntity pathFavoritesEntity = + pathFavoritesRepository.findById(save.getId()).get(); + + Assertions.assertThat(save.getId()).isEqualTo(pathFavoritesEntity.getId()); + } + } +} diff --git a/api/src/test/java/com/walking/api/RepositoryTest.java b/api/src/test/java/com/walking/api/RepositoryTest.java new file mode 100644 index 00000000..e78fc93b --- /dev/null +++ b/api/src/test/java/com/walking/api/RepositoryTest.java @@ -0,0 +1,41 @@ +package com.walking.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.walking.api.config.ApiDataSourceConfig; +import com.walking.api.config.ApiEntityConfig; +import com.walking.api.config.ApiJpaConfig; +import com.walking.data.config.DataJpaConfig; +import com.walking.data.config.HibernatePropertyMapProvider; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; +import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; + +@Slf4j +@ActiveProfiles(profiles = {"test"}) +@DataJpaTest( + excludeAutoConfiguration = { + DataSourceAutoConfiguration.class, + DataSourceTransactionManagerAutoConfiguration.class, + HibernateJpaAutoConfiguration.class, + }) +@TestPropertySource(locations = "classpath:application-test.yml") +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) +@ContextConfiguration( + classes = { + ApiDataSourceConfig.class, + ApiEntityConfig.class, + ApiJpaConfig.class, + DataJpaConfig.class, + HibernatePropertyMapProvider.class, + ObjectMapper.class, + }) +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +class RepositoryTest {} From c79c78bf2ccadf21fbdf761f83345f2a9203d570 Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Mon, 6 May 2024 02:16:47 +0900 Subject: [PATCH 10/23] =?UTF-8?q?refactor:=20spotlessApply=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/entity/member/MemberEntity.java | 19 +++++------- .../entity/member/PathFavoritesEntity.java | 31 ++++++++----------- .../entity/member/TrafficFavoritesEntity.java | 16 +++++----- .../data/entity/traffic/TrafficEntity.java | 21 ++++++------- 4 files changed, 36 insertions(+), 51 deletions(-) diff --git a/data/src/main/java/com/walking/data/entity/member/MemberEntity.java b/data/src/main/java/com/walking/data/entity/member/MemberEntity.java index 82a91dab..01ee41a2 100644 --- a/data/src/main/java/com/walking/data/entity/member/MemberEntity.java +++ b/data/src/main/java/com/walking/data/entity/member/MemberEntity.java @@ -1,6 +1,9 @@ package com.walking.data.entity.member; import com.walking.data.entity.BaseEntity; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; @@ -8,10 +11,6 @@ import lombok.experimental.SuperBuilder; import org.hibernate.annotations.SQLDelete; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @@ -21,13 +20,9 @@ @SQLDelete(sql = "UPDATE member SET deleted=true where id=?") public class MemberEntity extends BaseEntity { - @Column(nullable = false) - private String memberId; - - @Column(nullable = false) - private String password; - - - + @Column(nullable = false) + private String memberId; + @Column(nullable = false) + private String password; } diff --git a/data/src/main/java/com/walking/data/entity/member/PathFavoritesEntity.java b/data/src/main/java/com/walking/data/entity/member/PathFavoritesEntity.java index 563e2581..2d0275f6 100644 --- a/data/src/main/java/com/walking/data/entity/member/PathFavoritesEntity.java +++ b/data/src/main/java/com/walking/data/entity/member/PathFavoritesEntity.java @@ -1,6 +1,7 @@ package com.walking.data.entity.member; import com.walking.data.entity.BaseEntity; +import javax.persistence.*; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; @@ -10,8 +11,6 @@ import org.locationtech.jts.geom.LineString; import org.locationtech.jts.geom.Point; -import javax.persistence.*; - @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @@ -21,25 +20,21 @@ @SQLDelete(sql = "UPDATE path_favorites SET deleted=true where id=?") public class PathFavoritesEntity extends BaseEntity { - @ManyToOne(fetch = FetchType.LAZY) - private MemberEntity memberEntity; - - @Column(columnDefinition = "POINT") - private Point startPoint; - - @Column(columnDefinition = "POINT") - private Point endPoint; - - @Column(columnDefinition = "LINESTRING") - private LineString path; - - @Column(nullable = false) - private String startAlias; + @ManyToOne(fetch = FetchType.LAZY) + private MemberEntity memberEntity; - @Column(nullable = false) - private String endAlias; + @Column(columnDefinition = "POINT") + private Point startPoint; + @Column(columnDefinition = "POINT") + private Point endPoint; + @Column(columnDefinition = "LINESTRING") + private LineString path; + @Column(nullable = false) + private String startAlias; + @Column(nullable = false) + private String endAlias; } diff --git a/data/src/main/java/com/walking/data/entity/member/TrafficFavoritesEntity.java b/data/src/main/java/com/walking/data/entity/member/TrafficFavoritesEntity.java index 25026334..f5596a1b 100644 --- a/data/src/main/java/com/walking/data/entity/member/TrafficFavoritesEntity.java +++ b/data/src/main/java/com/walking/data/entity/member/TrafficFavoritesEntity.java @@ -2,6 +2,7 @@ import com.walking.data.entity.BaseEntity; import com.walking.data.entity.traffic.TrafficEntity; +import javax.persistence.*; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; @@ -9,8 +10,6 @@ import lombok.experimental.SuperBuilder; import org.hibernate.annotations.SQLDelete; -import javax.persistence.*; - @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @@ -20,13 +19,12 @@ @SQLDelete(sql = "UPDATE traffuc_favorites SET deleted=true where id=?") public class TrafficFavoritesEntity extends BaseEntity { - @ManyToOne(fetch = FetchType.LAZY) - private MemberEntity memberEntity; - - @OneToOne(fetch = FetchType.LAZY) - private TrafficEntity trafficEntity; + @ManyToOne(fetch = FetchType.LAZY) + private MemberEntity memberEntity; - @Column(nullable = false) - private String alias; + @OneToOne(fetch = FetchType.LAZY) + private TrafficEntity trafficEntity; + @Column(nullable = false) + private String alias; } diff --git a/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java b/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java index 8c3a877f..8afb0378 100644 --- a/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java +++ b/data/src/main/java/com/walking/data/entity/traffic/TrafficEntity.java @@ -1,7 +1,9 @@ package com.walking.data.entity.traffic; - import com.walking.data.entity.BaseEntity; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; @@ -10,10 +12,6 @@ import org.hibernate.annotations.SQLDelete; import org.locationtech.jts.geom.Point; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(access = AccessLevel.PRIVATE) @@ -23,13 +21,12 @@ @SQLDelete(sql = "UPDATE traffic SET deleted=true where id=?") public class TrafficEntity extends BaseEntity { - @Column(nullable = false , updatable = false) - private String detail; - - @Column(nullable = false) - private String name; + @Column(nullable = false, updatable = false) + private String detail; - @Column( columnDefinition = "POINT SRID 4326", nullable = false) - private Point point; + @Column(nullable = false) + private String name; + @Column(columnDefinition = "POINT SRID 4326", nullable = false) + private Point point; } From 8d3044ec820e122b6bf7293b99b442aea1fdd423 Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Tue, 14 May 2024 02:12:33 +0900 Subject: [PATCH 11/23] =?UTF-8?q?refactor:=20=EB=88=84=EB=9D=BD=EB=90=9C?= =?UTF-8?q?=20api=20=EC=9A=94=EA=B5=AC=EC=82=AC=ED=95=AD=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/walking/api/web/dto/response/RouteDetailResponse.java | 3 +++ .../com/walking/api/web/dto/response/detail/TrafficDetail.java | 1 + 2 files changed, 4 insertions(+) diff --git a/api/src/main/java/com/walking/api/web/dto/response/RouteDetailResponse.java b/api/src/main/java/com/walking/api/web/dto/response/RouteDetailResponse.java index e728a62a..ffd28a4b 100644 --- a/api/src/main/java/com/walking/api/web/dto/response/RouteDetailResponse.java +++ b/api/src/main/java/com/walking/api/web/dto/response/RouteDetailResponse.java @@ -20,6 +20,9 @@ public class RouteDetailResponse { public Long totalTime; public Long trafficCount; + public Integer timeToFirstTraffic; + public Integer totalDistance; + public Integer distanceToFirstTraffic; public PointDetail startPoint; public PointDetail endPoint; public List traffics; diff --git a/api/src/main/java/com/walking/api/web/dto/response/detail/TrafficDetail.java b/api/src/main/java/com/walking/api/web/dto/response/detail/TrafficDetail.java index b7a3574d..6fbaa66c 100644 --- a/api/src/main/java/com/walking/api/web/dto/response/detail/TrafficDetail.java +++ b/api/src/main/java/com/walking/api/web/dto/response/detail/TrafficDetail.java @@ -19,5 +19,6 @@ public class TrafficDetail { private String state; private Long remainTime; private Long greenCycle; + private Long redCycle; private PointDetail point; } From dcadda61604a2d2c959afe6a3f8f7a8ed70c2f85 Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Wed, 15 May 2024 19:15:22 +0900 Subject: [PATCH 12/23] =?UTF-8?q?refactor:=20PathFavoritesEntity=EC=9D=98?= =?UTF-8?q?=20path=EC=86=8D=EC=84=B1=20=EB=B3=80=EA=B2=BD,=20name,=20order?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MySQL의 LineString의 경우 SRID 타입이 0이어야 한다. 전체 이름에 대한 name과 기본적인 순서를 위해 order 필드를 생성해주었다. --- .../walking/data/entity/member/PathFavoritesEntity.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/data/src/main/java/com/walking/data/entity/member/PathFavoritesEntity.java b/data/src/main/java/com/walking/data/entity/member/PathFavoritesEntity.java index f027a785..0292f8df 100644 --- a/data/src/main/java/com/walking/data/entity/member/PathFavoritesEntity.java +++ b/data/src/main/java/com/walking/data/entity/member/PathFavoritesEntity.java @@ -30,7 +30,7 @@ public class PathFavoritesEntity extends BaseEntity { @Column(nullable = false, columnDefinition = "POINT SRID 4326") private Point endPoint; - @Column(nullable = false, columnDefinition = "LINESTRING SRID 4326") + @Column(nullable = false, columnDefinition = "LINESTRING SRID 0") private LineString path; @Column(nullable = false, length = 50) @@ -38,4 +38,10 @@ public class PathFavoritesEntity extends BaseEntity { @Column(nullable = false, length = 50) private String endAlias; + + @Column(nullable = false, length = 50) + private String name; + + @Column(nullable = false, name = "orders") + private Long order; } From 9b712a16da75ddeab58d638cd9fc9272dc0b8394 Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Wed, 15 May 2024 19:16:14 +0900 Subject: [PATCH 13/23] =?UTF-8?q?feat:=20PathFavoritesVo=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 --- .../dto/response/PathFavoritesVo.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 api/src/main/java/com/walking/api/repository/dto/response/PathFavoritesVo.java diff --git a/api/src/main/java/com/walking/api/repository/dto/response/PathFavoritesVo.java b/api/src/main/java/com/walking/api/repository/dto/response/PathFavoritesVo.java new file mode 100644 index 00000000..6c3ff815 --- /dev/null +++ b/api/src/main/java/com/walking/api/repository/dto/response/PathFavoritesVo.java @@ -0,0 +1,20 @@ +package com.walking.api.repository.dto.response; + +import java.time.LocalDateTime; +import lombok.*; +import org.locationtech.jts.geom.Geometry; + +@Getter +@ToString +@EqualsAndHashCode +@AllArgsConstructor +public class PathFavoritesVo { + + private Long id; + private Geometry startPoint; + private Geometry endPoint; + private String startAlias; + private String endAlias; + private String name; + private LocalDateTime createdAt; +} From 8752da1633ea9cc6fafb17fd16c96376c849517e Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Wed, 15 May 2024 19:17:10 +0900 Subject: [PATCH 14/23] =?UTF-8?q?feat:=20OrderFilter=20enum=EC=9D=98=20ORD?= =?UTF-8?q?ER=20=ED=83=80=EC=9E=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/walking/api/web/dto/request/OrderFilter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/walking/api/web/dto/request/OrderFilter.java b/api/src/main/java/com/walking/api/web/dto/request/OrderFilter.java index 3cb4a632..f086b80b 100644 --- a/api/src/main/java/com/walking/api/web/dto/request/OrderFilter.java +++ b/api/src/main/java/com/walking/api/web/dto/request/OrderFilter.java @@ -5,7 +5,8 @@ @Getter public enum OrderFilter { NAME("name"), - CREATEDAT("createdAt"); + CREATEDAT("createdAt"), + ORDER("order"); private String field; From 98f876873e44bdd0990ae44d9843fc36ae4e60ee Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Wed, 15 May 2024 19:18:45 +0900 Subject: [PATCH 15/23] =?UTF-8?q?refactor:=20FavoritePathBody=EC=97=90=20?= =?UTF-8?q?=EC=B6=9C=EB=B0=9C=EC=A7=80,=20=EB=AA=A9=EC=A0=81=EC=A7=80?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=9D=B4=EB=A6=84=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../walking/api/web/dto/request/path/FavoritePathBody.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/src/main/java/com/walking/api/web/dto/request/path/FavoritePathBody.java b/api/src/main/java/com/walking/api/web/dto/request/path/FavoritePathBody.java index d682ee59..059c0482 100644 --- a/api/src/main/java/com/walking/api/web/dto/request/path/FavoritePathBody.java +++ b/api/src/main/java/com/walking/api/web/dto/request/path/FavoritePathBody.java @@ -24,6 +24,12 @@ public class FavoritePathBody { /* 즐겨찾기 경로 이름 */ @Nullable private String name; + /* 시작점 이름 */ + @Nullable private String startAlias; + + /* 종료점 이름 */ + @Nullable private String endAlias; + /* 시작점 위도 */ @LatParam private double startLat; From 9dbcdec3ca08856e8b453044c48e7bc06a186c0b Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Wed, 15 May 2024 19:19:18 +0900 Subject: [PATCH 16/23] =?UTF-8?q?refactor:=20FavoritePointDetail=EC=97=90?= =?UTF-8?q?=20=EC=B6=9C=EB=B0=9C=EC=A7=80,=20=EB=AA=A9=EC=A0=81=EC=A7=80,?= =?UTF-8?q?=20=EC=88=9C=EC=84=9C=EC=97=90=20=EB=8C=80=ED=95=9C=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/web/dto/response/detail/FavoritePointDetail.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/src/main/java/com/walking/api/web/dto/response/detail/FavoritePointDetail.java b/api/src/main/java/com/walking/api/web/dto/response/detail/FavoritePointDetail.java index 3b703ad9..61982963 100644 --- a/api/src/main/java/com/walking/api/web/dto/response/detail/FavoritePointDetail.java +++ b/api/src/main/java/com/walking/api/web/dto/response/detail/FavoritePointDetail.java @@ -21,4 +21,7 @@ public class FavoritePointDetail { private PointDetail startPoint; private PointDetail endPoint; private LocalDateTime createdAt; + private String startAlias; + private String endAlias; + private Long order; } From 6c9697fdc45a0a06daa29fd99a5e818af765f5af Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Wed, 15 May 2024 19:21:02 +0900 Subject: [PATCH 17/23] =?UTF-8?q?refacotr:=20=ED=95=84=EB=93=9C=EC=9D=98?= =?UTF-8?q?=20=EB=B3=80=EC=88=98=EB=AA=85=EC=9D=84=20=EC=83=81=ED=99=A9?= =?UTF-8?q?=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit favoritePoints -> favoritePahts로 변경 --- .../api/web/dto/response/BrowseFavoriteRouteResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/com/walking/api/web/dto/response/BrowseFavoriteRouteResponse.java b/api/src/main/java/com/walking/api/web/dto/response/BrowseFavoriteRouteResponse.java index da76e17e..071e207c 100644 --- a/api/src/main/java/com/walking/api/web/dto/response/BrowseFavoriteRouteResponse.java +++ b/api/src/main/java/com/walking/api/web/dto/response/BrowseFavoriteRouteResponse.java @@ -17,5 +17,5 @@ @Builder public class BrowseFavoriteRouteResponse { - private List favoritePoints; + private List favoritePaths; } From 0cca87f89d98acb5e86c809265bf6d3ab6cf95c7 Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Wed, 15 May 2024 19:25:41 +0900 Subject: [PATCH 18/23] =?UTF-8?q?feat:=20PathFavoritesRepository=EC=9D=98?= =?UTF-8?q?=20=EA=B2=80=EC=83=89,=20=EC=A0=95=EB=A0=AC=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20=EA=B8=B0=EC=A4=80=EC=9D=98=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 이름,생성일자,order의 순으로 정렬해주는 필터와 이름을 통한 검색을 지원하는 메서드 추가 --- .../member/PathFavoritesRepository.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/com/walking/api/repository/member/PathFavoritesRepository.java b/api/src/main/java/com/walking/api/repository/member/PathFavoritesRepository.java index e4f8c070..2f072948 100644 --- a/api/src/main/java/com/walking/api/repository/member/PathFavoritesRepository.java +++ b/api/src/main/java/com/walking/api/repository/member/PathFavoritesRepository.java @@ -1,8 +1,50 @@ package com.walking.api.repository.member; +import com.walking.api.repository.dto.response.PathFavoritesVo; +import com.walking.data.entity.member.MemberEntity; import com.walking.data.entity.member.PathFavoritesEntity; +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 org.springframework.stereotype.Repository; @Repository -public interface PathFavoritesRepository extends JpaRepository {} +public interface PathFavoritesRepository extends JpaRepository { + + @Query( + " select new com.walking.api.repository.dto.response.PathFavoritesVo(pf.id,pf.startPoint,pf.endPoint,pf.startAlias,pf.endAlias,pf.name,pf.createdAt)" + + " from PathFavoritesEntity pf" + + " where pf.memberFk = :memberFk" + + " order by pf.order desc ") + List findPathFavoritesEntitiesByMemberFkOrderByOrderDesc( + @Param("memberFk") MemberEntity memberFk); + + @Query( + " select new com.walking.api.repository.dto.response.PathFavoritesVo(pf.id,pf.startPoint,pf.endPoint,pf.startAlias,pf.endAlias,pf.name,pf.createdAt)" + + " from PathFavoritesEntity pf" + + " where pf.memberFk = :memberFk" + + " order by pf.createdAt") + List findPathFavoritesByMemberFkOrderByCreatedAt( + @Param("memberFk") MemberEntity memberFk); + + @Query( + " select new com.walking.api.repository.dto.response.PathFavoritesVo(pf.id,pf.startPoint,pf.endPoint,pf.startAlias,pf.endAlias,pf.name,pf.createdAt)" + + " from PathFavoritesEntity pf" + + " where pf.memberFk = :memberFk" + + " order by pf.name") + List findPathFavoritesByMemberFkOrderByName( + @Param("memberFk") MemberEntity memberFk); + + @Query( + " select new com.walking.api.repository.dto.response.PathFavoritesVo(pf.id,pf.startPoint,pf.endPoint,pf.startAlias,pf.endAlias,pf.name,pf.createdAt)" + + " from PathFavoritesEntity pf" + + " where pf.memberFk = :memberFk" + + " and ( pf.name like concat('%',:name,'%') or pf.startAlias like concat('%',:name,'%') or pf.endAlias like concat('%',:name,'%')) " + + " order by pf.order desc") + List findPathFavoritesByMemberFkAndFilterName( + @Param("memberFk") MemberEntity memberFk, @Param("name") String name); + + @Query("select max(pf.order)" + "from PathFavoritesEntity pf") + Long findMaxOrder(); +} From a4a67fe21e910f3f3cda35d32c0dc90ffd4137d5 Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Wed, 15 May 2024 19:27:11 +0900 Subject: [PATCH 19/23] =?UTF-8?q?feat:=20PathController=EC=9D=98=20get-fav?= =?UTF-8?q?orite=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/path/PathController.java | 57 +++++++++++++++---- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/com/walking/api/web/controller/path/PathController.java b/api/src/main/java/com/walking/api/web/controller/path/PathController.java index 66a12e95..4a5a314d 100644 --- a/api/src/main/java/com/walking/api/web/controller/path/PathController.java +++ b/api/src/main/java/com/walking/api/web/controller/path/PathController.java @@ -10,12 +10,15 @@ import com.walking.api.web.dto.response.detail.FavoritePointDetail; import com.walking.api.web.dto.response.detail.PointDetail; import com.walking.api.web.dto.response.detail.TrafficDetail; +import com.walking.api.web.service.path.ReadFavoritesPathService; +import com.walking.api.web.service.path.dto.response.ReadFavoritesPathResponse; import com.walking.api.web.support.ApiResponse; import com.walking.api.web.support.ApiResponseGenerator; import com.walking.api.web.support.MessageCode; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import javax.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -39,6 +42,8 @@ @RequiredArgsConstructor public class PathController { + private final ReadFavoritesPathService readFavoritesPathService; + @GetMapping("/detail") public ApiResponse> detailRoute( @Valid RoutePointParam routePointParam) { @@ -62,20 +67,26 @@ public ApiResponse addFavoriteRoute( @GetMapping("/favorite") public ApiResponse> browseFavoriteRoute( @AuthenticationPrincipal TokenUserDetails userDetails, - @RequestParam(required = true, defaultValue = "createdAt") OrderFilter filter, + @RequestParam(required = false, defaultValue = "order") OrderFilter filter, @RequestParam(required = false) Optional name) { - // Long memberId = Long.valueOf(userDetails.getUsername()); - Long memberId = 999L; + // Long memberId = Long.valueOf(userDetails.getUsername()); + Long memberId = 1L; + log.info("컨트롤러 진입"); if (name.isPresent()) { - // todo implement: name 기준 검색 + + List favoritesPaths = + readFavoritesPathService.execute(memberId, name.get()); + log.info("Favorite route browse request: name={}", name.get()); - BrowseFavoriteRouteResponse response = getSearchFavoriteRouteResponse(); + BrowseFavoriteRouteResponse response = getFavoriteRouteResponse(favoritesPaths); return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.SUCCESS); } - // todo implement: filter 기준 정렬 + List favoritesPaths = + readFavoritesPathService.execute(memberId, filter); + log.info("Favorite route browse request: filter={}", filter); - BrowseFavoriteRouteResponse response = getFilterFavoriteRouteResponse(); + BrowseFavoriteRouteResponse response = getFavoriteRouteResponse(favoritesPaths); return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.SUCCESS); } @@ -112,6 +123,32 @@ public ApiResponse deleteFavoriteRoute( return ApiResponseGenerator.success(HttpStatus.OK, MessageCode.RESOURCE_DELETED); } + private BrowseFavoriteRouteResponse getFavoriteRouteResponse( + List favoritesPaths) { + // ReadFavoritesPathResponse 리스트를 FavoritePointDetail 리스트로 변환 + List favoritePoints = + favoritesPaths.stream() + .map( + path -> + FavoritePointDetail.builder() + .id(path.getId()) + .name(path.getName()) + .startPoint( + new PointDetail( + path.getStartPoint().getX(), path.getStartPoint().getY())) + .endPoint( + new PointDetail(path.getEndPoint().getX(), path.getEndPoint().getY())) + .createdAt(path.getCreatedAt()) + .startAlias(path.getStartAlias()) + .endAlias(path.getEndAlias()) + .order(path.getOrder()) + .build()) + .collect(Collectors.toList()); + + // BrowseFavoriteRouteResponse 객체 생성 및 반환 + return BrowseFavoriteRouteResponse.builder().favoritePaths(favoritePoints).build(); + } + private static RouteDetailResponse getSampleRouteDetailResponse() { return RouteDetailResponse.builder() .totalTime(100L) @@ -141,9 +178,9 @@ private static RouteDetailResponse getSampleRouteDetailResponse() { .build(); } - private static BrowseFavoriteRouteResponse getSearchFavoriteRouteResponse() { + private static BrowseFavoriteRouteResponse getFavoriteRouteResponse() { return BrowseFavoriteRouteResponse.builder() - .favoritePoints( + .favoritePaths( List.of( FavoritePointDetail.builder() .id(1L) @@ -157,7 +194,7 @@ private static BrowseFavoriteRouteResponse getSearchFavoriteRouteResponse() { private static BrowseFavoriteRouteResponse getFilterFavoriteRouteResponse() { return BrowseFavoriteRouteResponse.builder() - .favoritePoints( + .favoritePaths( List.of( FavoritePointDetail.builder() .id(1L) From 26cf6f51ecbb3a6ddcbe960a28aa81e406882ada Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Wed, 15 May 2024 19:27:46 +0900 Subject: [PATCH 20/23] =?UTF-8?q?feat:=20ReadFavoritesPathResponse=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 --- .../response/ReadFavoritesPathResponse.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 api/src/main/java/com/walking/api/web/service/path/dto/response/ReadFavoritesPathResponse.java diff --git a/api/src/main/java/com/walking/api/web/service/path/dto/response/ReadFavoritesPathResponse.java b/api/src/main/java/com/walking/api/web/service/path/dto/response/ReadFavoritesPathResponse.java new file mode 100644 index 00000000..b61fb254 --- /dev/null +++ b/api/src/main/java/com/walking/api/web/service/path/dto/response/ReadFavoritesPathResponse.java @@ -0,0 +1,23 @@ +package com.walking.api.web.service.path.dto.response; + +import java.time.LocalDateTime; +import lombok.*; +import org.locationtech.jts.geom.Point; + +@Getter +@ToString +@EqualsAndHashCode +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ReadFavoritesPathResponse { + + private Long id; + private Point startPoint; + private Point endPoint; + private String startAlias; + private String endAlias; + private String name; + private LocalDateTime createdAt; + private Long order; +} From c91ec26278137455ecdf160ad78e131fa32c3d64 Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Wed, 15 May 2024 19:28:25 +0900 Subject: [PATCH 21/23] =?UTF-8?q?feat:=20ReadFavoritesPathService=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 --- .../path/ReadFavoritesPathService.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 api/src/main/java/com/walking/api/web/service/path/ReadFavoritesPathService.java diff --git a/api/src/main/java/com/walking/api/web/service/path/ReadFavoritesPathService.java b/api/src/main/java/com/walking/api/web/service/path/ReadFavoritesPathService.java new file mode 100644 index 00000000..aaad9dc0 --- /dev/null +++ b/api/src/main/java/com/walking/api/web/service/path/ReadFavoritesPathService.java @@ -0,0 +1,83 @@ +package com.walking.api.web.service.path; + +import com.walking.api.repository.dto.response.PathFavoritesVo; +import com.walking.api.repository.member.MemberRepository; +import com.walking.api.repository.member.PathFavoritesRepository; +import com.walking.api.web.dto.request.OrderFilter; +import com.walking.api.web.service.path.dto.response.ReadFavoritesPathResponse; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.locationtech.jts.geom.Point; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** 데이터베이스에 저장된 멤버의 즐겨찾기 경로를 조회합니다. */ +@Service +@Slf4j +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class ReadFavoritesPathService { + + private final PathFavoritesRepository pathFavoritesRepository; + private final MemberRepository memberRepository; + + public List execute(Long memberId, String name) { + + List pathFavorites = + pathFavoritesRepository.findPathFavoritesByMemberFkAndFilterName( + memberRepository.findById(memberId).get(), name); + + return mappedFavoritesPathOrder(pathFavorites); + } + + public List execute(Long memberId, OrderFilter orderFilter) { + + if (orderFilter == OrderFilter.NAME) { + + return mappedFavoritesPathOrder( + pathFavoritesRepository.findPathFavoritesByMemberFkOrderByName( + memberRepository.findById(memberId).get())); + } + if (orderFilter == OrderFilter.CREATEDAT) { + + return mappedFavoritesPathOrder( + pathFavoritesRepository.findPathFavoritesByMemberFkOrderByCreatedAt( + memberRepository.findById(memberId).get())); + } + + if (orderFilter == OrderFilter.ORDER) { + return mappedFavoritesPathOrder( + pathFavoritesRepository.findPathFavoritesEntitiesByMemberFkOrderByOrderDesc( + memberRepository.findById(memberId).get())); + } + + throw new IllegalArgumentException("잘못된 OrderFilter입니다."); + } + + private List mappedFavoritesPathOrder( + List pathFavorites) { + // 인덱스를 위한 AtomicInteger + AtomicInteger index = new AtomicInteger(); + + List responses = + pathFavorites.stream() + .map( + vo -> + ReadFavoritesPathResponse.builder() + .id(vo.getId()) + .startPoint((Point) vo.getStartPoint()) + .endPoint((Point) vo.getEndPoint()) + .startAlias(vo.getStartAlias()) + .endAlias(vo.getEndAlias()) + .name(vo.getName()) + .createdAt(vo.getCreatedAt()) + .order((long) index.getAndIncrement()) // 인덱스 값 사용 및 증가 + .build()) + .collect(Collectors.toList()); + + return responses; + } +} From 8ea669462996eb2be11de87a78464982bf7af5ea Mon Sep 17 00:00:00 2001 From: Moon-1C Date: Wed, 15 May 2024 19:29:25 +0900 Subject: [PATCH 22/23] =?UTF-8?q?test:=20=EC=A6=90=EA=B2=A8=EC=B0=BE?= =?UTF-8?q?=EA=B8=B0=20=EA=B2=BD=EB=A1=9C=20=EA=B2=80=EC=83=89=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/path/PathControllerTest.java | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 api/src/test/java/com/walking/api/web/controller/path/PathControllerTest.java diff --git a/api/src/test/java/com/walking/api/web/controller/path/PathControllerTest.java b/api/src/test/java/com/walking/api/web/controller/path/PathControllerTest.java new file mode 100644 index 00000000..bb295c76 --- /dev/null +++ b/api/src/test/java/com/walking/api/web/controller/path/PathControllerTest.java @@ -0,0 +1,99 @@ +package com.walking.api.web.controller.path; + +import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; +import static com.epages.restdocs.apispec.ResourceDocumentation.resource; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.epages.restdocs.apispec.ResourceSnippetParameters; +import com.epages.restdocs.apispec.Schema; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.walking.api.ApiApp; +import com.walking.api.web.dto.request.path.FavoritePathBody; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.annotation.Rollback; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; + +@ActiveProfiles(value = "test") +@AutoConfigureRestDocs +@AutoConfigureMockMvc(addFilters = false) +@SpringBootTest(classes = ApiApp.class) +@Slf4j +class PathControllerTest { + + @Autowired private MockMvc mockMvc; + @Autowired private ObjectMapper objectMapper; + private static final String TAG = "PathControllerTest"; + private static final String BASE_URL = "/api/v1/paths"; + + @Test + @Rollback(value = false) + @DisplayName("즐겨찾기 경로를 추가한다.") + void addFavoriteRoute() throws Exception { + FavoritePathBody favoritePathBody = + FavoritePathBody.builder() + .name("test") + .startAlias("12") + .endAlias("12") + .startLat(33.5662952) + .startLng(124.9779451) + .endLat(33.5662952) + .endLng(124.9779451) + .build(); + + String content = objectMapper.writeValueAsString(favoritePathBody); + + mockMvc + .perform( + post(BASE_URL + "/favorite") + .contentType(MediaType.APPLICATION_JSON) + .content(content) + .header("Authorization", "Bearer {{accessToken}}")) + .andExpect(status().is2xxSuccessful()) + .andDo( + document( + "addFavoriteRoute", + resource( + ResourceSnippetParameters.builder() + .description("즐겨찾기 경로 추가") + .tag(TAG) + .requestSchema(Schema.schema("AddFavoriteRouteRequest")) + // + // .requestHeaders(Description.authHeader()) + .responseSchema(Schema.schema("AddFavoriteRouteResponse")) + // + // .responseFields(Description.common()) + .build()))); + } + + @Test + @DisplayName("즐겨찾기 경로를 검색한다.") + void getFavoriteRoute() throws Exception { + + MvcResult result = + mockMvc + .perform( + get(BASE_URL + "/favorite?filter=order") + .param("filter", "name") + .header("Authorization", "Bearer {{accessToken}}")) + .andDo(print()) + .andExpect(status().is2xxSuccessful()) + .andReturn(); + + // response 데이터 변환 + Map responseMap = + new ObjectMapper().readValue(result.getResponse().getContentAsString(), Map.class); + } +} From b599128ce929281ae66a87c5995402c380c50e79 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Mon, 20 May 2024 15:27:22 +0900 Subject: [PATCH 23/23] =?UTF-8?q?fix:=20PathControllerTest=20=EC=B6=A9?= =?UTF-8?q?=EB=8F=8C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/web/controller/path/PathControllerTest.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/api/src/test/java/com/walking/api/web/controller/path/PathControllerTest.java b/api/src/test/java/com/walking/api/web/controller/path/PathControllerTest.java index bf9c7561..13c399dc 100644 --- a/api/src/test/java/com/walking/api/web/controller/path/PathControllerTest.java +++ b/api/src/test/java/com/walking/api/web/controller/path/PathControllerTest.java @@ -175,21 +175,12 @@ void addFavoriteRoute() throws Exception { FavoritePathBody favoritePathBody = FavoritePathBody.builder() .name("test") -<<<<<<< HEAD - .startAlias("12") - .endAlias("12") - .startLat(33.5662952) - .startLng(124.9779451) - .endLat(33.5662952) - .endLng(124.9779451) -======= .startName("출발지") .startLat(35.1782) .startLng(126.909) .endName("도착지") .endLat(35.178600) .endLng(126.912772) ->>>>>>> main .build(); String content = objectMapper.writeValueAsString(favoritePathBody);