Skip to content

Commit

Permalink
refactor: 골 참여자 아이디 리스트 가져오는 로직 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
jhsseonn committed Mar 2, 2024
1 parent 322e219 commit 6d52552
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@ private User getUser(final Long userId) {
}

private void validateUserInGoalTeams(final Goal goal, final Long userId) {
final List<Long> teamUserIds = goal.getTeams()
.stream()
.map(goalTeam -> goalTeam.getUser().getId())
.toList();
final List<Long> teamUserIds = getTeamUserIds(goal);
if (!teamUserIds.contains(userId)) {
throw new CreateStampForbiddenException();
}
}

private List<Long> getTeamUserIds(final Goal goal) {
return goal.getTeams()
.getGoalTeams()
.stream()
.map(goalTeam -> goalTeam.getUser().getId())
.toList();
}

private void validateExistStamp(final Long userId, final int day) {
final boolean isExistsStamp = stampRepository.existsByUserIdAndDayAndDeletedIsFalse(userId, day);
if (isExistsStamp) {
Expand Down Expand Up @@ -92,11 +97,7 @@ public ReadAllStampDto readAllByGoalId(final Long goalId, final Long userId) {
}

private void validateUserToRead(final Goal goal, final Long userId) {
final List<Long> teamUserIds = goal.getTeams()
.getGoalTeams()
.stream()
.map(goalTeam -> goalTeam.getUser().getId())
.toList();
final List<Long> teamUserIds = getTeamUserIds(goal);
if (!teamUserIds.contains(userId)) {
throw new ReadStampForbiddenException();
}
Expand Down

0 comments on commit 6d52552

Please sign in to comment.