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

[#101] 오늘의 인기 활동 API 구축 #107

Merged
merged 2 commits into from
May 29, 2024
Merged

[#101] 오늘의 인기 활동 API 구축 #107

merged 2 commits into from
May 29, 2024

Conversation

KkomSang
Copy link
Collaborator

@KkomSang KkomSang commented May 29, 2024

#️⃣ 연관된 이슈

Resolves #101

📝 작업 내용

이번 PR에서 작업한 내용을 간략히 설명해주세요 (이미지 첨부 가능)

오늘 많이 기록된 상위 3개 활동의 이름과 기록 횟수를 조회할 수 있는 API를 구축했습니다!

@Query("SELECT r.activity, COUNT(r) as count FROM Record r WHERE r.createdAt >= :time GROUP BY r.activity ORDER BY count DESC limit 3")
    List<Object[]> findPopularActivities(@Param("time")LocalDateTime time);

쿼리문을 작성하여 오늘의 기록된 행복 기록에서 개수가 가장 많은 상위 3개의 활동과 그 활동의 기록횟수를 조회했습니다.

  • /api/trend/popular 로 조회시 다음과 같은 응답을 받을 수 있습니다.
{
  "success": true,
  "code": 0,
  "message": "오늘의 인기 활동을 성공적으로 조회했습니다.",
  "data": [
    {
      "ranking": 1,
      "name": "축구",
      "emoji": "⚽️",
      "times": 5
    },
    {
      "ranking": 2,
      "name": "밥먹기",
      "emoji": "🍽️",
      "times": 3
    },
    {
      "ranking": 3,
      "name": "코딩하기",
      "emoji": "👩‍💻",
      "times": 2
    }
  ]
}

🥸 수정사항

응답에 activityId는 사용되지 않으므로 삭제했습니다.

💬 리뷰 요구사항(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?

만약 동일한 횟수로 기록된 활동이 3개 이상이라면 다음과 같은 응답을 받을 수 있습니다.

{
  "success": true,
  "code": 0,
  "message": "오늘의 인기 활동을 성공적으로 조회했습니다.",
  "data": [
    {
      "ranking": 1,
      "name": "축구",
      "emoji": "⚽️",
      "times": 2
    },
    {
      "ranking": 2,
      "name": "기타치기",
      "emoji": "🎸",
      "times": 2
    },
    {
      "ranking": 3,
      "name": "피크닉",
      "emoji": "🧺",
      "times": 2
    }
  ]
}

정확히 어떤 기준으로 순서가 정해진 것인지는 사실 잘 모르겠습니다만...
찾아보니 데이테베이스 시스템, 혹은 저장 순서 등에 따라 랜덤인 것 같습니다. (다만 실행할 때마다 순서가 바뀌진 않고 동일한 응답이 나옵니다.)
혹시 추가적인 정렬 기준이 필요할까요??

✅ Check List

  • PR 제목을 커밋 규칙에 맞게 작성했는가?
  • PR에 해당되는 Issue를 연결했는가?
  • 적절한 라벨을 설정했는가?
  • 작업한 사람을 모두 Assign했는가?

@KkomSang KkomSang added the feat 새로운 기능을 추가합니다 label May 29, 2024
@KkomSang KkomSang self-assigned this May 29, 2024
@KkomSang KkomSang requested a review from yel-m May 29, 2024 09:22
@yel-m
Copy link
Member

yel-m commented May 29, 2024

@KkomSang 추가적인 정렬 기준은 필요하지 않을 것 같다고 생각합니당!!
저도 순서가 정해지는 게 랜덤인 것을 방금 깨달아서, 제 코드에서 랜덤 돌리는 로직은 빼야겠다구 생각했어요!
특히 쿼리문 작성하니까 코드가 훨씬 깔꼼하네요!! 넘 수고하셨습니당

@KkomSang
Copy link
Collaborator Author

@KkomSang 추가적인 정렬 기준은 필요하지 않을 것 같다고 생각합니당!! 저도 순서가 정해지는 게 랜덤인 것을 방금 깨달아서, 제 코드에서 랜덤 돌리는 로직은 빼야겠다구 생각했어요! 특히 쿼리문 작성하니까 코드가 훨씬 깔꼼하네요!! 넘 수고하셨습니당

@yel-m 이게 랜덤으로 순서가 정해지긴 하나, 랜덤 내의 기준이 있는건지,, 다시 실행한다고 해서 순서가 바뀌진 않는 것 같습니다. 그래서 랜덤 로직은 그대로 두는 것이 좋을 것 같습니다!!

@yel-m
Copy link
Member

yel-m commented May 29, 2024

아하 완전 갓잇입니댜
수고하셨슴니다!!
ps. 워크플로도 이제 잘 돌아가는군뇨,,, 감동의 도가니탕,,,

@yel-m yel-m merged commit cb8cc16 into develop May 29, 2024
1 check passed
@yel-m yel-m deleted the feat/#101 branch May 29, 2024 15:22
@KkomSang KkomSang restored the feat/#101 branch May 29, 2024 15:35
@KkomSang KkomSang deleted the feat/#101 branch May 29, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat 새로운 기능을 추가합니다
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants