From 6d525521c056daa17a77016904fee9e31dfad2d3 Mon Sep 17 00:00:00 2001 From: jhsseonn Date: Sun, 3 Mar 2024 01:18:33 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EA=B3=A8=20=EC=B0=B8=EC=97=AC?= =?UTF-8?q?=EC=9E=90=20=EC=95=84=EC=9D=B4=EB=94=94=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stamp/application/StampService.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/backend/blooming/stamp/application/StampService.java b/src/main/java/com/backend/blooming/stamp/application/StampService.java index 16198962..6a66f716 100644 --- a/src/main/java/com/backend/blooming/stamp/application/StampService.java +++ b/src/main/java/com/backend/blooming/stamp/application/StampService.java @@ -53,15 +53,20 @@ private User getUser(final Long userId) { } private void validateUserInGoalTeams(final Goal goal, final Long userId) { - final List teamUserIds = goal.getTeams() - .stream() - .map(goalTeam -> goalTeam.getUser().getId()) - .toList(); + final List teamUserIds = getTeamUserIds(goal); if (!teamUserIds.contains(userId)) { throw new CreateStampForbiddenException(); } } + private List 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) { @@ -92,11 +97,7 @@ public ReadAllStampDto readAllByGoalId(final Long goalId, final Long userId) { } private void validateUserToRead(final Goal goal, final Long userId) { - final List teamUserIds = goal.getTeams() - .getGoalTeams() - .stream() - .map(goalTeam -> goalTeam.getUser().getId()) - .toList(); + final List teamUserIds = getTeamUserIds(goal); if (!teamUserIds.contains(userId)) { throw new ReadStampForbiddenException(); }