diff --git a/src/main/java/com/gamja/tiggle/common/BaseResponseStatus.java b/src/main/java/com/gamja/tiggle/common/BaseResponseStatus.java index 513da1f..3d09c8d 100644 --- a/src/main/java/com/gamja/tiggle/common/BaseResponseStatus.java +++ b/src/main/java/com/gamja/tiggle/common/BaseResponseStatus.java @@ -28,10 +28,10 @@ public enum BaseResponseStatus { USER_EMPTY_EMAIL(false, 2001, "이메일 등록란은 필수 항목입니다."), USER_EMPTY_NAME(false, 2002, "이름 등록란은 필수 항목입니다."), USER_EMPTY_PASSWORD(false, 2003, "패스워드 입력란은 필수 항목입니다."), + EXISTED_EMAIL(false,2004,"이미 가입된 이메일(아이디)입니다."), POINT_NOT_ENOUGH(false, 2101, "소유 포인트 보다 높은 포인트는 사용할 수 없습니다."), - /** * 필터 단계에서 확인되는 에러는 실제 에러코드 형태여야 함. */ diff --git a/src/main/java/com/gamja/tiggle/user/adapter/in/web/SignupUserController.java b/src/main/java/com/gamja/tiggle/user/adapter/in/web/SignupUserController.java index eb059cd..58891ce 100644 --- a/src/main/java/com/gamja/tiggle/user/adapter/in/web/SignupUserController.java +++ b/src/main/java/com/gamja/tiggle/user/adapter/in/web/SignupUserController.java @@ -4,7 +4,9 @@ import com.gamja.tiggle.common.BaseException; import com.gamja.tiggle.common.BaseResponse; import com.gamja.tiggle.common.BaseResponseStatus; +import com.gamja.tiggle.user.adapter.in.web.request.DuplicatedEmailRequest; import com.gamja.tiggle.user.adapter.in.web.request.SignupUserRequest; +import com.gamja.tiggle.user.application.port.in.DuplicatedEmailCommand; import com.gamja.tiggle.user.application.port.in.SignupUserCommand; import com.gamja.tiggle.user.application.port.in.SignupUserUseCase; import io.swagger.v3.oas.annotations.Operation; @@ -30,9 +32,9 @@ BaseResponse signup(@RequestBody SignupUserRequest request) { return new BaseResponse<>(USER_EMPTY_EMAIL); } if (request.getName() == null) { - return new BaseResponse<>(USER_EMPTY_NAME); - } - if(request.getPassword() == null) { + return new BaseResponse<>(USER_EMPTY_NAME); + } + if (request.getPassword() == null) { return new BaseResponse<>(USER_EMPTY_PASSWORD); } @@ -56,4 +58,10 @@ BaseResponse signup(@RequestBody SignupUserRequest request) { return new BaseResponse(BaseResponseStatus.SUCCESS); } + @PostMapping("/duplicatedEmail") + public BaseResponse duplicatedEmail(@RequestBody DuplicatedEmailRequest request) { + Boolean result = signupUserUseCase.duplicatedEmail(DuplicatedEmailCommand + .builder().email(request.getEmail()).build()); + return new BaseResponse<>(result); + } } diff --git a/src/main/java/com/gamja/tiggle/user/adapter/in/web/VerifyUserController.java b/src/main/java/com/gamja/tiggle/user/adapter/in/web/VerifyUserController.java index 124d1da..9441938 100644 --- a/src/main/java/com/gamja/tiggle/user/adapter/in/web/VerifyUserController.java +++ b/src/main/java/com/gamja/tiggle/user/adapter/in/web/VerifyUserController.java @@ -35,4 +35,6 @@ BaseResponse signup(String email, String uuid) { return new BaseResponse(BaseResponseStatus.SUCCESS); } + + } diff --git a/src/main/java/com/gamja/tiggle/user/adapter/in/web/request/DuplicatedEmailRequest.java b/src/main/java/com/gamja/tiggle/user/adapter/in/web/request/DuplicatedEmailRequest.java new file mode 100644 index 0000000..93b3c2f --- /dev/null +++ b/src/main/java/com/gamja/tiggle/user/adapter/in/web/request/DuplicatedEmailRequest.java @@ -0,0 +1,14 @@ +package com.gamja.tiggle.user.adapter.in.web.request; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DuplicatedEmailRequest { + private String email; +} diff --git a/src/main/java/com/gamja/tiggle/user/adapter/out/persistence/JpaUserRepository.java b/src/main/java/com/gamja/tiggle/user/adapter/out/persistence/JpaUserRepository.java index 9a7f0c6..32f0447 100644 --- a/src/main/java/com/gamja/tiggle/user/adapter/out/persistence/JpaUserRepository.java +++ b/src/main/java/com/gamja/tiggle/user/adapter/out/persistence/JpaUserRepository.java @@ -6,4 +6,6 @@ public interface JpaUserRepository extends JpaRepository { UserEntity findByEmail(String email); + + Boolean existsByEmail(String email); } diff --git a/src/main/java/com/gamja/tiggle/user/adapter/out/persistence/UserPersistenceAdapter.java b/src/main/java/com/gamja/tiggle/user/adapter/out/persistence/UserPersistenceAdapter.java index 5d0cd9d..733caab 100644 --- a/src/main/java/com/gamja/tiggle/user/adapter/out/persistence/UserPersistenceAdapter.java +++ b/src/main/java/com/gamja/tiggle/user/adapter/out/persistence/UserPersistenceAdapter.java @@ -97,5 +97,10 @@ public void existUser(Long id) throws BaseException { throw new BaseException(BaseResponseStatus.NOT_FOUND_USER); } } + + @Override + public Boolean existEmail(String email) { + return jpaUserRepository.existsByEmail(email); + } } diff --git a/src/main/java/com/gamja/tiggle/user/application/port/in/DuplicatedEmailCommand.java b/src/main/java/com/gamja/tiggle/user/application/port/in/DuplicatedEmailCommand.java new file mode 100644 index 0000000..df0549f --- /dev/null +++ b/src/main/java/com/gamja/tiggle/user/application/port/in/DuplicatedEmailCommand.java @@ -0,0 +1,11 @@ +package com.gamja.tiggle.user.application.port.in; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class DuplicatedEmailCommand { + + private String email; +} diff --git a/src/main/java/com/gamja/tiggle/user/application/port/in/SignupUserUseCase.java b/src/main/java/com/gamja/tiggle/user/application/port/in/SignupUserUseCase.java index 280e772..79002d9 100644 --- a/src/main/java/com/gamja/tiggle/user/application/port/in/SignupUserUseCase.java +++ b/src/main/java/com/gamja/tiggle/user/application/port/in/SignupUserUseCase.java @@ -4,4 +4,6 @@ public interface SignupUserUseCase { String signup(SignupUserCommand command) throws BaseException; + + Boolean duplicatedEmail(DuplicatedEmailCommand command); } diff --git a/src/main/java/com/gamja/tiggle/user/application/port/out/UserPersistencePort.java b/src/main/java/com/gamja/tiggle/user/application/port/out/UserPersistencePort.java index ed426f9..ddee750 100644 --- a/src/main/java/com/gamja/tiggle/user/application/port/out/UserPersistencePort.java +++ b/src/main/java/com/gamja/tiggle/user/application/port/out/UserPersistencePort.java @@ -16,5 +16,7 @@ public interface UserPersistencePort { void savePoint(Long id, Integer point) throws BaseException; void existUser(Long id) throws BaseException; + + Boolean existEmail(String email); } diff --git a/src/main/java/com/gamja/tiggle/user/application/service/SignupUserService.java b/src/main/java/com/gamja/tiggle/user/application/service/SignupUserService.java index e38f65d..d0e01f6 100644 --- a/src/main/java/com/gamja/tiggle/user/application/service/SignupUserService.java +++ b/src/main/java/com/gamja/tiggle/user/application/service/SignupUserService.java @@ -1,6 +1,8 @@ package com.gamja.tiggle.user.application.service; import com.gamja.tiggle.common.BaseException; +import com.gamja.tiggle.common.BaseResponseStatus; +import com.gamja.tiggle.user.application.port.in.DuplicatedEmailCommand; import com.gamja.tiggle.user.application.port.in.SignupUserCommand; import com.gamja.tiggle.user.application.port.in.SignupUserUseCase; import com.gamja.tiggle.user.application.port.out.EmailVerifyPort; @@ -19,6 +21,11 @@ public class SignupUserService implements SignupUserUseCase { @Override public String signup(SignupUserCommand command) throws BaseException { + + if (userPersistencePort.existEmail(command.getEmail())) { + throw new BaseException(BaseResponseStatus.EXISTED_EMAIL); + } + User user = User.builder() .name(command.getName()) .email(command.getEmail()) @@ -37,4 +44,9 @@ public String signup(SignupUserCommand command) throws BaseException { return uuid; } + + @Override + public Boolean duplicatedEmail(DuplicatedEmailCommand command) { + return userPersistencePort.existEmail(command.getEmail()); + } }