-
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
…-api Feat: 내 근처 품앗이 목록 조회 API 구현
- Loading branch information
Showing
6 changed files
with
121 additions
and
31 deletions.
There are no files selected for viewing
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/backend/DuruDuru/global/repository/TradeRepository.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,7 +1,28 @@ | ||
package com.backend.DuruDuru.global.repository; | ||
|
||
import com.backend.DuruDuru.global.domain.entity.Trade; | ||
import com.backend.DuruDuru.global.domain.enums.TradeType; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface TradeRepository extends JpaRepository<Trade, Long> { | ||
// 사용자와의 거리가 1km 이내인 게시글 리스트 반환 | ||
@Query(value = """ | ||
SELECT * FROM trade | ||
WHERE (6371 * acos(cos(radians(:memberLat)) * cos(radians(latitude)) * cos(radians(longitude) - radians(:memberLon)) + sin(radians(:memberLat)) * sin(radians(latitude)))) <= 1 | ||
AND trade_type = :tradeType | ||
ORDER BY updated_at DESC | ||
LIMIT :size OFFSET :offset | ||
""", nativeQuery = true) | ||
List<Trade> findNearbyTrades( | ||
@Param("memberLat") double memberLat, | ||
@Param("memberLon") double memberLon, | ||
@Param("tradeType") String tradeType, | ||
@Param("size") int size, | ||
@Param("offset") int offset | ||
); | ||
} | ||
|
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