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

추가/즐겨찾기/이삭줍기 카운트 백엔드 #53

Merged
merged 2 commits into from
Jan 24, 2022

Conversation

junglesub
Copy link
Member

#48 기능 백엔드 기능입니다.

한번도 sequelize 라이브러리를 사용해 본적이 없어 기존 @zoomkoding 님의 코드를 보고 구글링을 하면서 최대한 따라해 보았습니다. 많이 부족한데, 더 좋은 방법이나 다른 접근 방법이 있으면 알려주세요!

추가사항

이제 검색했을 때 count 요소를 반환합니다.

{
  ...lecture,
  "count": {
      "add": 1,
      "bookmark": 0,
      "spike": 0
  }
}
  • add - 시간표에 추가한 사람들의 인원
  • bookmark - 북마크에 추가된 횟수
  • spike - 이삭줍기를 신청한 사람들의 인원

부가적인 기능이므로 따로 클라이언트 업데이트는 필요 없으며 클라이언트 정보를 추가해주는 방식으로 프론트 개발을 하면 될 것 같습니다.

앞으로의 추가사항

클라이언트에서 북마크를 추가할 때 업데이트된 수를 확인할 수 있도록 controllers/user.js 파일에 있는 add/remove 함수들도 수정할 예정입니다.

@junglesub junglesub self-assigned this Jan 21, 2022
@vercel
Copy link

vercel bot commented Jan 21, 2022

Someone is attempting to deploy a commit to a Personal Account owned by @zoomkoding on Vercel.

@zoomkoding first needs to authorize it.

@vercel
Copy link

vercel bot commented Jan 22, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/zoomkoding/college-timetable/EASyhELRaZ4rnWAyj7717sqShA9S
✅ Preview: https://college-timetable-git-fork-junglesub-feat-sta-9ebcf1-zoomkoding.vercel.app

@zoomkoding
Copy link
Collaborator

정섭님 코드 잘 봤습니다! sequelize를 처음 써보시는데 역시 빨리 터득해서 어려운 쿼리도 뚝딱이시네요 ㅎㅎ
다만 promise.all 내부에 promise를 따로 쓰지 않고 아래와 같이 코드를 구성해보는 건 어떨까요?
promise.all에서 promise로 다시 감싸주신 이유가 있다면 말씀해주세요!

  // Get lectures with count
  const lecturesWithCount = await Promise.all(
    lectures.map(async (lecture) => {
      const [add, bookmark, spike] = await Promise.all([
        // Add
        Timetable.count({
          include: { model: Lecture, where: { id: lecture.id } },
          distinct: true,
          col: 'userId',
        }),
        // Bookmark
        UserLectureRelation.count({
          where: { lectureId: lecture.id },
        }),
        // Spike
        UserLectureGleaningRelation.count({
          where: { lectureId: lecture.id },
        }),
      ]);
      return { ...lecture.dataValues, count: { add, bookmark, spike } };
    }),
  );

@zoomkoding
Copy link
Collaborator

그리고 정섭님도 contributor시니까 포크 떠간 정섭님 레포가 아니라 이 레포에서 브랜치를 따서 PR을 날리시면 됩니다~😄

@junglesub
Copy link
Member Author

당시 코드 짤 때 new Promise() 를 사용하지 않았더니 애러가 떠서 급하게 사용한 방법이었는데, 말씀하신대로 수정해보니 잘 작동 되네요! 피드백 감사합니다!

내일중으로 추가사항 작업 마무리 하겠습니다.

@zoomkoding zoomkoding marked this pull request as ready for review January 24, 2022 05:11
@zoomkoding zoomkoding merged commit 4d974ae into handong-life:main Jan 24, 2022
@junglesub junglesub linked an issue Jan 24, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants