-
Notifications
You must be signed in to change notification settings - Fork 0
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
골 참여자 방출 기능 구현 #99
골 참여자 방출 기능 구현 #99
Changes from all commits
d6df41a
7440c2d
ce65227
8097b98
c69a1d4
4ee2bd6
04042d2
0d8fe1d
3100d79
5b4f9e0
c3b55c5
157465a
d070051
a3b8651
4996979
c8d2760
1683ec2
4ca692c
07dc4bc
c6517ad
62ea675
42d3d58
41c9d66
80fbb73
e3ff334
13c9f2e
560e6ca
80a9449
f0daa20
43a95f3
a8a8d1e
4d35b0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.backend.blooming.goal.application.exception; | ||
|
||
import com.backend.blooming.exception.BloomingException; | ||
import com.backend.blooming.exception.ExceptionMessage; | ||
|
||
public class ForbiddenGoalToDeleteException extends BloomingException { | ||
|
||
private ForbiddenGoalToDeleteException(final ExceptionMessage exceptionMessage) { | ||
super(exceptionMessage); | ||
} | ||
|
||
public static class ForbiddenUserToDeleteGoal extends ForbiddenGoalToDeleteException { | ||
|
||
public ForbiddenUserToDeleteGoal() { | ||
super(ExceptionMessage.DELETE_GOAL_FORBIDDEN); | ||
} | ||
} | ||
|
||
public static class ForbiddenUserToDeleteUser extends ForbiddenGoalToDeleteException { | ||
|
||
public ForbiddenUserToDeleteUser() { | ||
super(ExceptionMessage.FORBIDDEN_USER_TO_DELETE_USER); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.backend.blooming.goal.application.exception; | ||
|
||
import com.backend.blooming.exception.BloomingException; | ||
import com.backend.blooming.exception.ExceptionMessage; | ||
|
||
public class ForbiddenGoalToUpdateException extends BloomingException { | ||
|
||
private ForbiddenGoalToUpdateException(final ExceptionMessage exceptionMessage) { | ||
super(exceptionMessage); | ||
} | ||
|
||
public static class ForbiddenUserToUpdateGoalToUpdate extends ForbiddenGoalToUpdateException { | ||
|
||
public ForbiddenUserToUpdateGoalToUpdate() { | ||
super(ExceptionMessage.UPDATE_GOAL_FORBIDDEN); | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.backend.blooming.goal.domain; | ||
|
||
import com.backend.blooming.common.entity.BaseTimeEntity; | ||
import com.backend.blooming.goal.application.exception.DeleteGoalForbiddenException; | ||
import com.backend.blooming.goal.application.exception.ForbiddenGoalToDeleteException; | ||
import com.backend.blooming.goal.application.exception.InvalidGoalAcceptException; | ||
import com.backend.blooming.goal.application.exception.InvalidGoalException; | ||
import com.backend.blooming.user.domain.User; | ||
|
@@ -107,9 +107,10 @@ public void updateDeleted(final Long userId) { | |
|
||
private void validUserToDelete(final Long userId) { | ||
if (!isManager(userId)) { | ||
throw new DeleteGoalForbiddenException(); | ||
throw new ForbiddenGoalToDeleteException.ForbiddenUserToDeleteGoal(); | ||
} | ||
} | ||
|
||
public boolean isTeam(final User user) { | ||
return teams.isTeam(user); | ||
} | ||
|
@@ -139,4 +140,22 @@ private void validateUserToAccept(final User user) { | |
public boolean isTeamAndAccepted(final User user) { | ||
return teams.isTeamAndAccepted(user); | ||
} | ||
|
||
public void deleteUser(final User user, final Long managerId) { | ||
validUserToDelete(user); | ||
validUserToDeleteUser(managerId); | ||
teams.deleteUser(user); | ||
} | ||
|
||
private void validUserToDelete(final User user) { | ||
if (!this.isTeam(user)) { | ||
throw new InvalidGoalException.InvalidInvalidUserToDelete(); | ||
} | ||
} | ||
|
||
private void validUserToDeleteUser(final Long userId) { | ||
if (!isManager(userId)) { | ||
throw new ForbiddenGoalToDeleteException.ForbiddenUserToDeleteUser(); | ||
} | ||
} | ||
Comment on lines
+156
to
+160
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 부분은 생각하지 못했는데 좋네요! 👍 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,4 +78,8 @@ public boolean isTeamAndAccepted(final User user) { | |
return goalTeams.stream() | ||
.anyMatch(goalTeam -> goalTeam.getUser().equals(user) && goalTeam.isAccepted()); | ||
} | ||
|
||
public void deleteUser(final User user) { | ||
goalTeams.removeIf(goalTeam -> goalTeam.getUser().equals(user)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍👍👍 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.backend.blooming.goal.infrastructure.repository; | ||
|
||
import com.backend.blooming.goal.domain.GoalTeam; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.Optional; | ||
|
||
public interface GoalTeamRepository extends JpaRepository<GoalTeam, Long> { | ||
|
||
@Query(""" | ||
SELECT gt | ||
FROM GoalTeam gt | ||
WHERE (gt.user.id = :userId AND gt.goal.id = :goalId) | ||
""") | ||
Optional<GoalTeam> findByUserIdAndGoalId(final Long userId, final Long goalId); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,11 @@ SELECT EXISTS( | |
WHERE s.id = :stampId | ||
""") | ||
Optional<Stamp> findByIdAndFetchGoalAndUser(final Long stampId); | ||
|
||
@Query(""" | ||
SELECT s | ||
FROM Stamp s | ||
WHERE s.goal.id = :goalId AND s.user.id = :userId | ||
""") | ||
List<Stamp> findAllByGoalIdAndUserId(final Long goalId, final Long userId); | ||
Comment on lines
+47
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. jpa 네이밍만으로 안 되기에 쿼리문을 사용한 것이 맞을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 맞습니다! 네이밍만으로 조회가 불가하다고 판단해 쿼리문 사용했습니다! |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
당장 좋은 아이디어가 떠오르지 않지만, 추후 리팩터링 진행 시 어떻게 하면 쿼리를 줄일 수 있을지 함께 고민해 보면 좋을 것 같습니다.
(정말 줄일 수 없는 것이라면 그러한 결론도 괜찮고요!)
기록 겸 코멘트 달아둡니다.