Skip to content
New issue

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

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

Already on GitHub? # to your account

[#11] 최근 검색 내역 API 구현 #14

Merged
merged 15 commits into from
Feb 26, 2025
Merged

Conversation

JiwonKKang
Copy link
Collaborator

@JiwonKKang JiwonKKang commented Feb 24, 2025

#️⃣연관된 이슈

📝작업 내용

  • 최근 검색 내역 조회
  • 최근 검색 내역 추가
  • 최근 검색 내역 삭제
  • 최근 검색 내역 전체 삭제

💬리뷰 요구사항(선택)

  • 디자인된 화면의 최근 검색 내역에 거리 데이터가 있어서 거리 계산 로직을 추가했습니다. TMAP을 이용한 POI 검색 시에는 거리 데이터까지 함께 반환되지만 검색 내역을 조회하는 시점에는 검색했을 당시와 같은 위치가 아닐 가능성이 크기때문에 거리를 다시 계산해야한다고 생각했습니다! 따라서 하버사인 공식으로 현재좌표를 파리미터로 받아 추가적으로 거리계산한뒤에 반환하도록 만들었습니다!

  • 최근 검색 내역 관련 코드만 봐주시면 됩니다! 다른 코드는 이후 PR에서 변경사항이있어요!

Copy link
Member

@jhon3242 jhon3242 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지원님! 수고하셨어요!
정팩메 관련해서 컨벤션을 명확하게 정해야할 것 같아요! 이 부분에 대해 같이 의견 나눠봐요!

Redis에 관해서 익숙하지 않아 궁금한점을 있어서 질문을 좀 많이 한 것 같네요 ㅋㅋ
검색해보려고 해도 어떤 키워드로 검색해야할지 잘 모르겠어서 관련 자료를 찾기가 어렵네요.
답하기 귀찮으시면 관한 링크만 주셔도 좋습니다! 😄

Comment on lines 44 to 50
@PostMapping("/histories")
fun addRecentPOI(
@RequestBody request: POIHistoryRequest
): ApiResponse<Unit> =
locationService.addPOIHistory(request.toPOI()).let {
return ApiResponse.success()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

딱히 응답할 값이 없어도 200에다 SUCESS를 보내는 것인가용??
저는 아무것도 리턴하지 않고 204 No Contend를 보내주었는데 통일해야할 것 같네요 😆
저도 이 방식으로 통일할게요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞다 이것도 204를 보내기로했었죠! 204로 합시다!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아니면 통일성 있게 responseCode를 보내주는건 어떨까요??

{
	"responseCode" : "NO CONTENT",
	"timeStamp": "2025-02-23T16:07:18.761921",
	"result": {}
}

이렇게요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 좋습니다 제가 API Response에 noContent()도 추가해서 넣어놓을게요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

찾아보니 NO_CONENT응답은 바디가 없는게 표준이더라고요!
그래서 그냥 원준님이 하신대로 @ResponseStatus()를 사용하면될거같습니다

아래는 예시입니다!

@PostMapping("/histories")
    @ResponseStatus(HttpStatus.CREATED)
    fun addRecentPOI(
        @RequestBody request: POIHistoryRequest
    ) = locationService.addPOIHistory(request.toPOI())

Comment on lines +18 to +26
override fun push(
user: User,
poi: POI
) {
val key: String = getKey(user)
logger.info { "Pushing POI to Redis: $poi" }
redisTemplate.opsForList().leftPush(key, poi)
redisTemplate.opsForList().trim(key, 0, LIST_FULL_SIZE - 1)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

질문) redis에 대해 잘 몰라서 그러는데 이 작업을 하면 key 별로 리스트가 지정되는건가요??
예).

leftPush("userA", "1")
leftPush("userB", "1")
leftPush("userA", "2")

이렇게 하면

userA : [1, 2]
userB : [1]

이렇게 저장되는건가 해서요!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

질문) 히스터리를 저장하는 용도이면 Set로 하면 중복값을 제거할 수 있을 것 같은데 안되나요??
찾아보니까 opsForZSet() 를 사용하면 Sorted Set 자료 구조를 사용할 수 있는 것 같아서 질문드렸습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 맞아요! 중복되면 안되는 데이터를 순서대로 저장해야한다고했을때 Sorted Set 자료구조를 활용하면 좋아요!

저는 최근 검색 내역이 10~20개 밖에 안되기도하고 List로 구현할경우에도 저장 순서가 유지되기때문에 간단하게 List로 구현했어요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저장은
POI_HISTORY:1 : [1,2,3...]

요런식으로 된다고생각하시면 되요!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 최근 검색 내역이 10~20개 밖에 안되기도하고 List로 구현할경우에도 저장 순서가 유지되기때문에 간단하게 List로 구현했어요!

그러면 동일한 주소 검색을 여러번하면 똑같은 검색 내역이 여러개 나오지 않을까요??
강남역을 3번 검색하면 검색 히스토리에 강남역이 3개나 나올 것 같아서요!

Comment on lines +55 to +57
private fun getKey(user: User): String {
return "POI_HISTORY:${user.id}"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

질문) 앞에 "POI_HISTORY"가 prefix로 붙여주는 것을 보면 동일한 테이블 내에 여러키로 데이터가 저장될 수 있는 것 같은데 맞나요??

예)

POI_HISTORY:1 -> [1, 2]
POI_HISTORY:2 -> [1, 2]
POI_HISTORY:3 -> [1, 2]
...
POI_SOMETHING:1 -> [1, 2]
POI_SOMETHING:2 -> [1, 2]
...

이런 <키, 자료구조> 테이블에 모든 자료구조를 저장하는 형식인지 궁금합니다!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

질문) 만약 위 질문이 맞다면 같은 키인데 자료구조가 다른 경우는 어떻게 처리되는건가요??
이런 경우 다른 키 값을 줘야하는 건가요??
예)

POI_HISTORY_QUEUE:1 -> [1, 2]
POI_HISTORY_SET:1 -> (1, 2)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 redis는 keyValue store라서 원준님이 말하신대로 모든게 <키, 자료구조> 형태로 저장되는걸로 알고있어요!

저도 궁금해서 찾아봤는데 다른 자료구조로 동일한 키를 사용할수 없다고하네요

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오홍 그렇군요! 그러면 데이터의 양이 꽤 많아져서 조회할 때 많은 데이터를 순회해야할 것 같은데 괜찮나요?? 물론 인메모리여서 조회 속도는 빠를 것 같긴 한데 데이터의 양이 워낙 많다면 성능이 떨어지지 않을까 싶어서요! (단순 궁금증입니다!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

데이터 양이 많아진다는게 어떤부분일까요?

Comment on lines +14 to +18
if (poiHistoryQueue.exists(user, poi)) {
poiHistoryQueue.pop(user, poi)
}
poiHistoryQueue.push(user, poi)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhon3242

중복처리로직은 여기부분에서 해결했어용

@JiwonKKang JiwonKKang merged commit c1d790c into dev Feb 26, 2025
1 check passed
@JiwonKKang JiwonKKang deleted the feat/search-history/#11 branch February 26, 2025 18:13
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] 최근 검색내역 API 구현
3 participants