diff --git a/src/main/java/com/spomatch/users/DefaultUserService.java b/src/main/java/com/spomatch/users/DefaultUserService.java index 8e1e565..f323e76 100644 --- a/src/main/java/com/spomatch/users/DefaultUserService.java +++ b/src/main/java/com/spomatch/users/DefaultUserService.java @@ -41,7 +41,7 @@ private UserId getNextId() { } @Override - public User update(User toUpdate) { + public User updateUserInfo(User toUpdate) { for (User user : registeredUsers) { if (user.equals(toUpdate)) { @@ -53,6 +53,19 @@ public User update(User toUpdate) { throw new UserNotExistException(); } + @Override + public User updatePlayers(User toUpdate) { + + for (User user : registeredUsers) { + if (user.equals(toUpdate)) { + user.setPlayers(toUpdate.getPlayers()); + return user; + } + } + + throw new UserNotExistException(); + } + private User cloneUser(User toClone) { User user = new User(); @@ -68,8 +81,14 @@ private User cloneUser(User toClone) { } @Override - public void cancel(User toCancel) { - registeredUsers.removeIf(user -> user.equals(toCancel)); + public void cancel(UserId idToCancel) { + + User toCancel = getById(idToCancel); + + if (toCancel.getPlayerSize() > 0) + throw new PlayerExistWhenCancelMembershipException(); + + registeredUsers.removeIf(user -> user.getId().equals(idToCancel)); } @Override diff --git a/src/main/java/com/spomatch/users/PlayerExistWhenCancelMembershipException.java b/src/main/java/com/spomatch/users/PlayerExistWhenCancelMembershipException.java new file mode 100644 index 0000000..dbdb33d --- /dev/null +++ b/src/main/java/com/spomatch/users/PlayerExistWhenCancelMembershipException.java @@ -0,0 +1,18 @@ +package com.spomatch.users; + +/** + * 회원 탈퇴 시도 시 플레이어가 존재하는 경우 던져지는 예외 + * + * @author Seongbin Kim + */ +public class PlayerExistWhenCancelMembershipException extends RuntimeException { + + private static final long serialVersionUID = 5362410971263147389L; + + public PlayerExistWhenCancelMembershipException() { + } + + public PlayerExistWhenCancelMembershipException(String message) { + super(message); + } +} diff --git a/src/main/java/com/spomatch/users/User.java b/src/main/java/com/spomatch/users/User.java index 48c5d4e..d2316d0 100644 --- a/src/main/java/com/spomatch/users/User.java +++ b/src/main/java/com/spomatch/users/User.java @@ -172,7 +172,6 @@ public void removePlayerBySportsType(SportsType typeToRemove) { } public void updateUserInfo(User toUpdate) { - this.pw = toUpdate.pw; this.preferredLocations = toUpdate.preferredLocations; this.age = toUpdate.age; diff --git a/src/main/java/com/spomatch/users/UserService.java b/src/main/java/com/spomatch/users/UserService.java index a52d532..25d44a2 100644 --- a/src/main/java/com/spomatch/users/UserService.java +++ b/src/main/java/com/spomatch/users/UserService.java @@ -4,9 +4,11 @@ public interface UserService { User register(User user); - User update(User registered); + User updateUserInfo(User toUpdate); - void cancel(User user); + User updatePlayers(User toUpdate); + + void cancel(UserId idToCancel); User getById(UserId id); diff --git a/src/test/java/com/spomatch/users/TestUserService.java b/src/test/java/com/spomatch/users/TestUserService.java index aa4e01f..fcbcbb0 100644 --- a/src/test/java/com/spomatch/users/TestUserService.java +++ b/src/test/java/com/spomatch/users/TestUserService.java @@ -7,6 +7,9 @@ import org.apache.commons.lang3.RandomStringUtils; import org.junit.Test; +import com.spomatch.users.players.Player; +import com.spomatch.users.players.SoccerPlayer; + /** * 유저 서비스의 도메인 규칙을 분석하여 서비스의 스펙을 정의하고, 테스트합니다. * @@ -119,7 +122,7 @@ public class TestUserService { registered.setIdForLogin(newIdForLogin); registered.setName(newName); - User updated = userService.update(registered); + User updated = userService.updateUserInfo(registered); // then assertEquals(newPassword, updated.getPw()); @@ -137,11 +140,28 @@ public class TestUserService { User user = registerDummy(); // when - userService.cancel(user); + userService.cancel(user.getId()); userService.getById(user.getId()); } + // then + @Test(expected = PlayerExistWhenCancelMembershipException.class) + public void 회원은_탈퇴할_수_있다_플레이어가_있어서_실패() { + + // given + User user = registerDummy(); + + Player soccerPlayer = new SoccerPlayer(); + + user.addPlayer(soccerPlayer); + + userService.updatePlayers(user); + + // when + userService.cancel(user.getId()); + } + private User registerDummy() { User toRegister = UserTests.createDummy();