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

골 수락 기능 구현 #86

Merged
merged 18 commits into from
Mar 16, 2024
Merged

골 수락 기능 구현 #86

merged 18 commits into from
Mar 16, 2024

Conversation

jhsseonn
Copy link
Member

@jhsseonn jhsseonn commented Mar 9, 2024

3/10
골 수락 기능 구현 완료했습니다. 이번주까지 시험이 있어서 진도를 많이 못나갔습니다.. 다음주부터 속도 내보겠습니다!

[주요 작업 내용]

  • 골 초대 수락
    • 골 관리자의 경우 골 생성시에 수락됨으로 처리
    • 골 참여자가 아니거나 골 참여자이지만 수락을 하지 않은 사용자는 단일 골 조회를 할 수 없도록 제한
  • closed [Feat] 골 수락 기능 구현 #58

[질문]

  1. 골 수락 기능 서비스 테스트를 하는데 로직에는 문제가 없는데 테스트에는 반영이 제대로 되지 않아서 혹시 트랜잭션 문제인가 싶어 @Transactional 을 테스트 메서드에 부여해주니 문제없이 잘 돌아가더라구요.. 이전까지 수정 기능 테스트하면서 트랜잭션 문제가 있었던 적이 없었는데 이번에 처음 발생한 문제라 정확한 원인을 좀 더 찾아보도록 하겠습니다. 우선 테스트 상으로는 문제가 없어 그대로 둘지 아니면 수정하는 것이 좋을지 질문드립니다!

@jhsseonn jhsseonn added the feature 기능 추가 label Mar 9, 2024
@jhsseonn jhsseonn self-assigned this Mar 9, 2024
Copy link
Member

@JJ503 JJ503 left a comment

Choose a reason for hiding this comment

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

기능 구현 고생 많으셨습니다!
코드를 보며 몇 가지 질문과 수정하면 좋겠는 방향에 대해 작성해 보았습니다.
그래서 일단 rc로 처리합니다.


return ReadGoalDetailDto.from(goal);
}

private void validateUserToRead(final User user, final Goal goal) {
if (!goal.isTeam(user) || !goal.isAccepted(user)) {
Copy link
Member

Choose a reason for hiding this comment

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

goal에서 isTeam 자체를 수락까지 완료한 사용자만 true로 반환하면 안 될까요?
만약, 기존 isTeam의 메서드도 필요하다면, 해당 메서드의 이름을 대기 중인 팀원 등으로 변경하면 좋을 것 같아요.

Copy link
Member Author

Choose a reason for hiding this comment

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

말씀하신대로 아직 골 수락을 하지 않은 초대 멤버에 대해서는 팀원으로 취급하지 않아도 될 것 같아서 isTeam 호출에서 수락한 사람들만 가져오는 것으로 변경했습니다. 추후에 초대한 팀원의 수락 여부를 받아와야할 경우가 생긴다면 그 때 메서드를 분리하면 좋을 것 같네요!

Copy link
Member Author

Choose a reason for hiding this comment

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

테스트를 돌렸는데 초대한 팀원 목록을 받아와야하는 경우가 있어 오류가 나더군요.. 다시 메서드 분리하고 메서드명을 isTeamAndAccepted로 설정했습니다!


public class InvalidGoalAcceptException extends BloomingException {

public InvalidGoalAcceptException(final ExceptionMessage exceptionMessage) {
Copy link
Member

Choose a reason for hiding this comment

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

해당 메서드를 클래스 외부에서 사용할 것이 아니라면 private으로 설정해줘도 좋을 것 같아요!

Comment on lines 55 to 58
private void validateUserIsManager(final User user, final Goal goal) {
if (goal.getManagerId().equals(user.getId())) {
updateAccepted();
}
Copy link
Member

Choose a reason for hiding this comment

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

검증보다는, 특정 조건에 대한 전처리에 더 가까운 것 같아 validate라는 네이밍이 와닿지 않는 것 같습니다.
그리고 위 updateAccepted 메서드와 순서가 변경되면 더 좋겠네요!

Copy link
Member Author

Choose a reason for hiding this comment

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

이전에 컨벤션 회의에서 값을 기본 설정해주는 메서드의 경우 processDefault를 붙이기로 했어서 컨벤션대로 수정했습니다!

@@ -102,4 +105,15 @@ public ResponseEntity<Void> delete(
return ResponseEntity.noContent()
.build();
}

@PostMapping(value = "/{goalId}/accept", headers = "X-API-VERSION=1")
Copy link
Member

Choose a reason for hiding this comment

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

친구 수락의 경우 Patch였는데, 골 수락은 Post인 이유가 있을까요?

Copy link
Member Author

Choose a reason for hiding this comment

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

patch 생각을 못하고 post로 설정했습니다.. patch로 변경하도록 하겠습니다!

Comment on lines 319 to 322
final List<GoalTeam> acceptedGoalTeam = 현재_진행중인_골1.getTeams()
.stream()
.filter(GoalTeam::isAccepted)
.toList();
Copy link
Member

Choose a reason for hiding this comment

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

@Transactional을 사용하지 않기 위해선 GoalRepository 등을 @Autowired로 주입받아 조회를 통해 검증할 수 있습니다.
해당 경우 @Transactional이 없을 때 실패하는 이유는 서비스 메서드를 실행시켜 그에 대한 결과가 테스트 클래스까지 전파되기 위해선 하나의 트랜잭션이어야 하기 때문입니다.
다만, 이때 굳이 @Transactional을 사용해야 하는 가에 대한 고민이 필요할 것 같습니다.
저는 이번 프로젝트에서 @Transactional을 사용하지 않으면 좋겠다고 생각했는데, 메서드에 @Transactional을 붙이는 경우는 고려해보지 못했네요.
그래도 repository를 통해 변경된 데이터를 가져올 수 있으니, 사용하지 않는 것이 더 좋지 않을까 생각합니다.
그리고 메서드마다 매번 필요 여부를 따지는 것도 불편할 것 같아요.
사용하지 않으면 좋겠다고 처음 생각하게 된 이유의 참고 자료입니다.
효선님의 의견 알려주시면 감사하겠습니다!

Copy link
Member Author

Choose a reason for hiding this comment

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

말씀주신대로 repositoryautowired로 주입시켜 repository로부터 변경내용을 가져와 테스트를 해보니 잘 돌아가네요! 다만 repository에서 findByIdAndDeletedIsFalse 메서드로 불러왔을 경우에 GoalTeamfetch join 해주지 않아 조건에 맞는 GoalTeam 리스트를 생성할 수 없어 fetch join 설정이 되어 있는 findByIdWithUserAndDeletedIsFalse로 불러와 테스트했습니다.

Copy link
Member

@JJ503 JJ503 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

@jhsseonn jhsseonn merged commit 864661b into develop Mar 16, 2024
2 checks passed
@jhsseonn jhsseonn deleted the feature/58 branch March 16, 2024 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 기능 추가
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Feat] 골 수락 기능 구현
2 participants