[Fix] createAndDeleteScrap시 스크랩 전체 개수도 반환#135
Merged
RinRinPARK merged 2 commits intodevfrom Dec 20, 2023
Merged
Conversation
YuSuhwa-ve
reviewed
Dec 19, 2023
| } | ||
|
|
||
| // 해당 public course의 전체 스크랩 개수 | ||
| Long scrapCount = scrapRepository.countByPublicCourseAndScrapTFIsTrue(publicCourse); |
Contributor
There was a problem hiding this comment.
pulicCourse entity에 아래와같은 칼럼이 있어서 위에서 publicCourse 가져올때 이미 스크랩카운트 가지고 있어요. 그거 쓰는게 더 편할듯해요
@Formula("(select count(*) from Scrap where Scrap.public_course_id=id and Scrap.scraptf=true)")
private Integer scrapCount;
Contributor
Author
There was a problem hiding this comment.
오옷 몰랐씀다!!
근데 방금 말씀하신 getScrapCount로 가져오는 방식으로 바꿔서 테스트를 해봤는데 publicCourse객체를 스크랩 하기 전에 findById로 찾아오고 -> 스크랩 생성/취소-> 그 객체에 getScrapCount를 했을 때, 이미 생성해둔 객체에 getScrapCount를 하는 로직이라 스크랩생성/취소한게 반영이 안되네요 ㅠㅜ 그래서 말씀해주신 방식을 사용하려면 publicCourse객체를 스크랩 생성/취소 후 새로 findById하는 방식을 사용하거나 아니면 생성/취소에 따라 getScrapCount에 +-1을 해주는 방식을 써야할 것 같습니다!! 지금 코드 그대로 가는 방법도 있구~.~
근데 개인적으로 +-1 해주는게 디비 접근을 제일 적게 해서 괜찮을 것 같기도 한데..? 어떤게 좋을까유
Contributor
There was a problem hiding this comment.
아 그렇네 이미 publicCourse 가져오고 나서 scrap update 구나!! 기존로직 그대로 가도 좋을것같아요!
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
😶 무슨 이슈인가요?
closes #134
🤔 어떻게 이슈를 해결했나요?
🤯 주의할 점이 있나요?