-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat #38 매칭 필터링 및 알고리즘 구현
- Loading branch information
Showing
11 changed files
with
170 additions
and
24 deletions.
There are no files selected for viewing
19 changes: 16 additions & 3 deletions
19
src/main/java/com/gachtaxi/domain/matching/algorithm/service/MatchingAlgorithmService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
package com.gachtaxi.domain.matching.algorithm.service; | ||
|
||
import com.gachtaxi.domain.matching.algorithm.dto.FindRoomResult; | ||
import com.gachtaxi.domain.matching.common.entity.MatchingRoom; | ||
import com.gachtaxi.domain.matching.common.entity.enums.Tags; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.domain.Page; | ||
|
||
public interface MatchingAlgorithmService { | ||
|
||
/** | ||
* 방을 찾는 메서드 | ||
* 이미 방에 들어가있는 멤버가 다시 요청했을 때 Optional.empty()를 반환하도록 로직을 구성해야함 | ||
* @param userId 방에 들어가려는 사용자 ID | ||
* @param startPoint 매칭 시작 지점 좌표 | ||
* @param destinationPoint 도착지 좌표 | ||
* @param startLongitude 시작 지점 경도 | ||
* @param startLatitude 시작 지점 위도 | ||
* @param destinationLongitude 도착 지점 경도 | ||
* @param destinationLatitude 도착 지점 위도 | ||
* @param criteria 방 검색에 필요한 기타 조건 (태그 등) | ||
* @return Optional<FindRoomResult> - 매칭 가능한 방 정보가 있으면 값이 있고, 없으면 empty | ||
*/ | ||
Optional<FindRoomResult> findRoom(Long userId, String startPoint, String destinationPoint, List<Tags> criteria); | ||
Optional<FindRoomResult> findRoom(Long userId, double startLongitude, double startLatitude, double destinationLongitude, double destinationLatitude, List<Tags> criteria); | ||
|
||
/** | ||
* 전체 매칭 방을 페이지 단위로 조회 | ||
* | ||
* @param pageNumber 페이지 번호 (0부터 시작) | ||
* @param pageSize 한 페이지에 포함될 매칭 방의 개수 | ||
* @return Page<MatchingRoom> - 페이지별 매칭 방 정보 | ||
*/ | ||
Page<MatchingRoom> findMatchingRooms(int pageNumber, int pageSize); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...n/java/com/gachtaxi/domain/matching/common/exception/DuplicatedMatchingRoomException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.gachtaxi.domain.matching.common.exception; | ||
|
||
import static com.gachtaxi.domain.matching.common.exception.ErrorMessage.DUPLICATED_MATCHING_ROOM; | ||
import static org.springframework.http.HttpStatus.BAD_REQUEST; | ||
|
||
import com.gachtaxi.global.common.exception.BaseException; | ||
|
||
public class DuplicatedMatchingRoomException extends BaseException { | ||
public DuplicatedMatchingRoomException() { | ||
super(BAD_REQUEST, DUPLICATED_MATCHING_ROOM.getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/gachtaxi/domain/matching/common/exception/PageNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.gachtaxi.domain.matching.common.exception; | ||
|
||
import com.gachtaxi.global.common.exception.BaseException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class PageNotFoundException extends BaseException { | ||
public PageNotFoundException() { | ||
super(HttpStatus.NOT_FOUND, ErrorMessage.NOT_FOUND_PAGE.getMessage()); | ||
} | ||
} |
20 changes: 19 additions & 1 deletion
20
src/main/java/com/gachtaxi/domain/matching/common/repository/MatchingRoomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
package com.gachtaxi.domain.matching.common.repository; | ||
|
||
import com.gachtaxi.domain.matching.common.entity.MatchingRoom; | ||
import com.gachtaxi.domain.members.entity.Members; | ||
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 MatchingRoomRepository extends JpaRepository<MatchingRoom, Long> { | ||
|
||
@Query("SELECT r FROM MatchingRoom r " + | ||
"WHERE " + | ||
"FUNCTION('ST_Distance_Sphere', FUNCTION('POINT', :startLongitude, :startLatitude), FUNCTION('POINT', r.route.startLongitude, r.route.startLatitude)) <= :radius " + | ||
"AND FUNCTION('ST_Distance_Sphere', FUNCTION('POINT', :destinationLongitude, :destinationLatitude), FUNCTION('POINT', r.route.endLongitude, r.route.endLatitude)) <= :radius ") | ||
List<MatchingRoom> findRoomsByStartAndDestination( | ||
@Param("startLongitude") double startLongitude, | ||
@Param("startLatitude") double startLatitude, | ||
@Param("destinationLongitude") double destinationLongitude, | ||
@Param("destinationLatitude") double destinationLatitude, | ||
@Param("radius") double radius | ||
); | ||
@Query("SELECT CASE WHEN COUNT(m) > 0 THEN true ELSE false END " + | ||
"FROM MatchingRoom r JOIN r.memberMatchingRoomChargingInfo m " + | ||
"WHERE m.members = :user") | ||
boolean existsByMemberInMatchingRoom(@Param("user") Members user); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters