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

feat: 즐겨찾기 기능을 구현한다. #50

Merged
merged 18 commits into from
Feb 8, 2025
Merged

Conversation

boyekim
Copy link
Member

@boyekim boyekim commented Feb 7, 2025

작업 내용

즐겨찾기 기능을 구현했습니다.
현재는 등록 기능만 구현해두었구요, 추후 계속 커밋 추가하겠습니다.
기존 핀 기능처럼 5개로 제한해두었어요. 핀 기능은 5개 제한인데 이거는 제한이 없는건 이상한 것 같아서요.
리뷰와 병렬적으로 가져가고자 우선 pr 올립니다.

고민 지점과 리뷰 포인트

@boyekim boyekim self-assigned this Feb 7, 2025
@boyekim boyekim linked an issue Feb 7, 2025 that may be closed by this pull request
@boyekim boyekim marked this pull request as draft February 7, 2025 08:43
Copy link

github-actions bot commented Feb 7, 2025

Test Results

59 tests   59 ✅  6s ⏱️
17 suites   0 💤
17 files     0 ❌

Results for commit 3c3dec7.

♻️ This comment has been updated with latest results.

Copy link
Member

@3Juhwan 3Juhwan left a comment

Choose a reason for hiding this comment

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

빨리 해주셨네요 👍
몇 가지 코멘트 남겼는데 확인 부탁드려요~~

src/main/java/kr/allcll/seatfinder/star/Star.java Outdated Show resolved Hide resolved
src/main/java/kr/allcll/seatfinder/star/Star.java Outdated Show resolved Hide resolved
src/main/java/kr/allcll/seatfinder/star/StarService.java Outdated Show resolved Hide resolved
Comment on lines 88 to 93
String expectExceptionMessage = new AllcllException(AllcllErrorCode.DUPLICATE_STAR, "컴퓨터구조").getMessage();

// when, then
assertThatThrownBy(() -> starService.addStarOnSubject(subject.getId(), TOKEN))
.isInstanceOf(AllcllException.class)
.hasMessageContaining(expectExceptionMessage);
Copy link
Member

Choose a reason for hiding this comment

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

expectedExceptionMessage를 문자열 하드코딩하는 것은 어떨까요? 위랑 다르네요

Copy link
Member Author

Choose a reason for hiding this comment

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

위와 다르네요 가 어떤 말일까요..?
어느 위를 말하는걸까요???
어떤 말을 하는지 잘 이해가 안가는데 다시 한번 설명해주실 수 있으실까용

Copy link
Member

Choose a reason for hiding this comment

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

바로 위에 있는 테스트 78번 라인을 보면

.hasMessageContaining(String.format(AllcllErrorCode.STAR_LIMIT_EXCEEDED.getMessage(), MAX_STAR_NUMBER));

라고 되어 있어요. 하지만 이 테스트는 Exception 객체를 생성하고 거기에서 예외 메시지를 뽑아내고 있어요. 일관성이 안 맞아서 남긴 코멘트였어요.

@boyekim boyekim marked this pull request as ready for review February 7, 2025 13:36
Copy link
Member

@3Juhwan 3Juhwan left a comment

Choose a reason for hiding this comment

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

바쁜 와중 잘 구현해 주셨어요 👍
코멘트 읽어보고 반영해 주시면 감사할 것 같아요.
추가로 pin 패키지 작업이 이 pr에 왜 있는 건지,, 설명 부탁드려요!

@@ -23,15 +23,15 @@ public class PinService {

@Transactional
public void addPinOnSubject(Long subjectId, String token) {
List<Pin> userPins = pinRepository.findAllByToken(token);
Long pinCount = pinRepository.countAllByToken(token);
Copy link
Member

Choose a reason for hiding this comment

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

token을 index로 거는 게 필수겠군요 😀

@@ -23,15 +23,15 @@ public class PinService {

@Transactional
public void addPinOnSubject(Long subjectId, String token) {
List<Pin> userPins = pinRepository.findAllByToken(token);
Long pinCount = pinRepository.countAllByToken(token);
Copy link
Member

Choose a reason for hiding this comment

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

해당 라인을 validateCanAddPin 내부로 옮겨서 파라미터를 하나 줄이면 어떨까요?

Comment on lines 5 to +10
PIN_LIMIT_EXCEEDED("이미 %d개의 핀을 등록했습니다."),
STAR_LIMIT_EXCEEDED("이미 %d개의 즐겨찾기를 등록했습니다."),
DUPLICATE_PIN("%s은(는) 이미 핀 등록된 과목입니다."),
DUPLICATE_STAR("%s은(는) 이미 핀 등록된 과목입니다."),
PIN_SUBJECT_MISMATCH("핀에 등록된 과목이 아닙니다."),
STAR_SUBJECT_MISMATCH("즐겨찾기에 등록된 과목이 아닙니다."),
Copy link
Member

Choose a reason for hiding this comment

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

도메인 별로 모아서 구분하면 관리하면 좋을 것 같아요.

src/main/java/kr/allcll/seatfinder/star/StarService.java Outdated Show resolved Hide resolved

@Transactional
public void addStarOnSubject(Long subjectId, String token) {
Long starCount = starRepository.countAllByToken(token);
Copy link
Member

Choose a reason for hiding this comment

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

starCount도 validateCanAddStar 메서드 내부로 옮기면 어떨까요? starCount가 검증부에서만 사용하니까 validateCanAddStar 내부에 두면 어떨까요?

src/main/java/kr/allcll/seatfinder/star/StarService.java Outdated Show resolved Hide resolved
src/main/java/kr/allcll/seatfinder/star/StarService.java Outdated Show resolved Hide resolved
}

@Test
@DisplayName("등록되지 않은 즐겨찾기의 삭제에 대한 예외를 검증한다.")
Copy link
Member

Choose a reason for hiding this comment

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

등록되지 않은 즐겨찾기를 삭제하면 예외가 발생한다.

이렇게 변경하는 건 어떤가요? 저는 위 이름이 이해하기 어려워서요. 어떤 행위를 했을 때, 어떤 결과가 나오는지 좀더 친절하게 적어두면 이해하기 쉬운 것 같아요

@boyekim
Copy link
Member Author

boyekim commented Feb 8, 2025

저는 처음에 Star 관련한 로직에서 token이 존재하지 않는다는 문제가 구현의 문제가 될 수 있겠다고 생각하여 예외를 추가해두었으나, 이는 충분히 로깅으로 추적가능하구, token이 옳지 않은 경우는 악의적 접근일 가능성이 더 높지 않을까 하는 주환님의 의견이 공감이 갔습니다. 그래서 반영했습니다~! 한번 확인해주세여
그리고, 이전에는 터지지 않던 SubjectService 테스트가 터지는 문제가 갑자기 발생했는데요, ⁠subjects 테이블의 데이터를 삭제하려고 할 때 발생한 참조 무결성 제약 조건 위반...을 했대요
그래서 @BeforeEach 시점에 subjectRepository deleteAllInBatch()를 할 때에 starRepository도 먼저 deleteAllInBatch()를 해주었습니다.
이 테스트 클래스에서 starService는 쓰이지 않는데...왜 그런 오류가 터지는것일까 생각을 해보았는데요,
Star은 Subject에 의존을 하고있고, 이전에 다른 테스트를 돌때에 저장된 repository 정보가 남아있어서 그런거 아닐까? 싶어요.
이 또한 테스트 격리가 제대로 이루어지지 않았다고 볼 수 있는 걸까요?
@BeforeEach들을 @AfterEach들로 바꾸면 해결이 될까요...? 코멘트 작성하다가 갑자기 든 생각입니다...

@3Juhwan
Copy link
Member

3Juhwan commented Feb 8, 2025

이 테스트 클래스에서 starService는 쓰이지 않는데...왜 그런 오류가 터지는것일까 생각을 해보았는데요,
Star은 Subject에 의존을 하고있고, 이전에 다른 테스트를 돌때에 저장된 repository 정보가 남아있어서 그런거 아닐까? 싶어요.
이 또한 테스트 격리가 제대로 이루어지지 않았다고 볼 수 있는 걸까요?

테스트 격리가 이루지지 않은 것 같아요.

@BeforeEach들을 @AfterEach들로 바꾸면 해결이 될까요...? 코멘트 작성하다가 갑자기 든 생각입니다...

@AfterEach가 관리하기 쉽겠네요 👍 이렇게 수정해 보아요.

@3Juhwan 3Juhwan merged commit 71e7da3 into main Feb 8, 2025
3 checks passed
@3Juhwan 3Juhwan deleted the feat/47-stars-api branch February 8, 2025 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

즐겨찾기 기능을 구현한다.
2 participants