Skip to content

[Fix] createAndDeleteScrap시 스크랩 전체 개수도 반환#135

Merged
RinRinPARK merged 2 commits intodevfrom
fix/#134
Dec 20, 2023
Merged

[Fix] createAndDeleteScrap시 스크랩 전체 개수도 반환#135
RinRinPARK merged 2 commits intodevfrom
fix/#134

Conversation

@RinRinPARK
Copy link
Copy Markdown
Contributor

@RinRinPARK RinRinPARK commented Dec 18, 2023

😶 무슨 이슈인가요?


closes #134

🤔 어떻게 이슈를 해결했나요?


  • scrap할 public course를 넘겨주고, 해당 public course가 스크랩된 횟수를 count해 넘겨줌(scrapRepository)

🤯 주의할 점이 있나요?


@RinRinPARK RinRinPARK added the fix label Dec 18, 2023
Copy link
Copy Markdown
Contributor

@funnysunny08 funnysunny08 left a comment

Choose a reason for hiding this comment

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

수고했어용👍

Copy link
Copy Markdown
Contributor

@YuSuhwa-ve YuSuhwa-ve left a comment

Choose a reason for hiding this comment

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

리뷰확인해주시면 감사하겠습니다

}

// 해당 public course의 전체 스크랩 개수
Long scrapCount = scrapRepository.countByPublicCourseAndScrapTFIsTrue(publicCourse);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pulicCourse entity에 아래와같은 칼럼이 있어서 위에서 publicCourse 가져올때 이미 스크랩카운트 가지고 있어요. 그거 쓰는게 더 편할듯해요

@Formula("(select count(*) from Scrap where Scrap.public_course_id=id and Scrap.scraptf=true)")
  private Integer scrapCount;

Copy link
Copy Markdown
Contributor Author

@RinRinPARK RinRinPARK Dec 19, 2023

Choose a reason for hiding this comment

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

오옷 몰랐씀다!!
근데 방금 말씀하신 getScrapCount로 가져오는 방식으로 바꿔서 테스트를 해봤는데 publicCourse객체를 스크랩 하기 전에 findById로 찾아오고 -> 스크랩 생성/취소-> 그 객체에 getScrapCount를 했을 때, 이미 생성해둔 객체에 getScrapCount를 하는 로직이라 스크랩생성/취소한게 반영이 안되네요 ㅠㅜ 그래서 말씀해주신 방식을 사용하려면 publicCourse객체를 스크랩 생성/취소 후 새로 findById하는 방식을 사용하거나 아니면 생성/취소에 따라 getScrapCount에 +-1을 해주는 방식을 써야할 것 같습니다!! 지금 코드 그대로 가는 방법도 있구~.~
근데 개인적으로 +-1 해주는게 디비 접근을 제일 적게 해서 괜찮을 것 같기도 한데..? 어떤게 좋을까유

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

아 그렇네 이미 publicCourse 가져오고 나서 scrap update 구나!! 기존로직 그대로 가도 좋을것같아요!

@RinRinPARK RinRinPARK merged commit 549c69d into dev Dec 20, 2023
@RinRinPARK RinRinPARK self-assigned this Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Fix] createAndDeleteScrap에 scrap개수 포함

3 participants