Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/get path favorites #11

Merged
merged 26 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5db0a24
refactor: BaseEntity의 PK 선언 방식을 IDENTITY->SEQUENCE로 변경
Moon-1C May 5, 2024
cb3d3c6
feat: MemberEntity 생성
Moon-1C May 5, 2024
aaa5049
feat: TrafficEntity 생성
Moon-1C May 5, 2024
a7ce12e
feat: PathFavoritesEntity 생성
Moon-1C May 5, 2024
da0366e
feat: TrafficFavoritesEntity 생성
Moon-1C May 5, 2024
f629406
feat: application-data-local.yml 파일에 mysql의 spatial 방언 추가
Moon-1C May 5, 2024
7c2499d
feat: hibernate-spatial 의존성 추가
Moon-1C May 5, 2024
264f7dc
feat: Repository 추가
Moon-1C May 5, 2024
358689d
Test: Entity 테스트 추가
Moon-1C May 5, 2024
c79c78b
refactor: spotlessApply적용
Moon-1C May 5, 2024
826d4cf
Merge remote-tracking branch 'origin/feat/data-entity' into data-entity
Moon-1C May 13, 2024
8d3044e
refactor: 누락된 api 요구사항 추가
Moon-1C May 13, 2024
e1584d6
Merge remote-tracking branch 'origin/feat/refactor-data-entity' into …
Moon-1C May 13, 2024
dcadda6
refactor: PathFavoritesEntity의 path속성 변경, name, order 추가
Moon-1C May 15, 2024
9b712a1
feat: PathFavoritesVo 구현
Moon-1C May 15, 2024
8752da1
feat: OrderFilter enum의 ORDER 타입 추가
Moon-1C May 15, 2024
98f8768
refactor: FavoritePathBody에 출발지, 목적지에 대한 이름 필드 추가
Moon-1C May 15, 2024
9dbcdec
refactor: FavoritePointDetail에 출발지, 목적지, 순서에 대한 필드 추가
Moon-1C May 15, 2024
6c9697f
refacotr: 필드의 변수명을 상황에 맞게 변경
Moon-1C May 15, 2024
0cca87f
feat: PathFavoritesRepository의 검색, 정렬에 대한 기준의 메서드 추가
Moon-1C May 15, 2024
a4a67fe
feat: PathController의 get-favorite 메서드 구현
Moon-1C May 15, 2024
26cf6f5
feat: ReadFavoritesPathResponse 구현
Moon-1C May 15, 2024
c91ec26
feat: ReadFavoritesPathService 구현
Moon-1C May 15, 2024
8ea6694
test: 즐겨찾기 경로 검색 테스트 구현
Moon-1C May 15, 2024
57d9ae7
Merge branch 'main' into feat/get-path-favorites
belljun3395 May 20, 2024
b599128
fix: PathControllerTest 충돌 해결
belljun3395 May 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<PathFavoritesEntity, Long> {}
public interface PathFavoritesRepository extends JpaRepository<PathFavoritesEntity, Long> {

@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<PathFavoritesVo> 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<PathFavoritesVo> 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<PathFavoritesVo> 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<PathFavoritesVo> findPathFavoritesByMemberFkAndFilterName(
@Param("memberFk") MemberEntity memberFk, @Param("name") String name);

@Query("select max(pf.order)" + "from PathFavoritesEntity pf")
Long findMaxOrder();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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<TrafficDetail> traffics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ public class FavoriteRouteDetail {
private PointDetail startPoint;
private PointDetail endPoint;
private LocalDateTime createdAt;
private String startAlias;
private String endAlias;
private Long order;
}
Original file line number Diff line number Diff line change
@@ -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<ReadFavoritesPathResponse> execute(Long memberId, String name) {

List<PathFavoritesVo> pathFavorites =
pathFavoritesRepository.findPathFavoritesByMemberFkAndFilterName(
memberRepository.findById(memberId).get(), name);

return mappedFavoritesPathOrder(pathFavorites);
}

public List<ReadFavoritesPathResponse> 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<ReadFavoritesPathResponse> mappedFavoritesPathOrder(
List<PathFavoritesVo> pathFavorites) {
// 인덱스를 위한 AtomicInteger
AtomicInteger index = new AtomicInteger();

List<ReadFavoritesPathResponse> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ 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)
private String startAlias;

@Column(nullable = false, length = 50)
private String endAlias;

@Column(nullable = false, length = 50)
private String name;

@Column(nullable = false, name = "orders")
private Long order;
}
Loading