diff --git a/src/main/java/site/billbill/apiserver/api/auth/domain/UserBaseInfo.java b/src/main/java/site/billbill/apiserver/api/auth/domain/UserBaseInfo.java index 8cb0459..6e29421 100644 --- a/src/main/java/site/billbill/apiserver/api/auth/domain/UserBaseInfo.java +++ b/src/main/java/site/billbill/apiserver/api/auth/domain/UserBaseInfo.java @@ -7,6 +7,7 @@ @AllArgsConstructor public class UserBaseInfo { private String userId; + private String email; private String profileImage; private String nickname; private String password; diff --git a/src/main/java/site/billbill/apiserver/api/auth/dto/request/LoginRequest.java b/src/main/java/site/billbill/apiserver/api/auth/dto/request/LoginRequest.java index d6e8df6..7edd923 100644 --- a/src/main/java/site/billbill/apiserver/api/auth/dto/request/LoginRequest.java +++ b/src/main/java/site/billbill/apiserver/api/auth/dto/request/LoginRequest.java @@ -5,8 +5,10 @@ @Data public class LoginRequest { - @Schema(description = "전화번호", example = "010-0000-0001") - private String phoneNumber; +// @Schema(description = "전화번호", example = "010-0000-0001") +// private String phoneNumber; + @Schema(description = "이메일", example = "abcde@gmail.com") + private String email; @Schema(description = "비밀번호", example = "password") private String password; } diff --git a/src/main/java/site/billbill/apiserver/api/auth/dto/request/SignupRequest.java b/src/main/java/site/billbill/apiserver/api/auth/dto/request/SignupRequest.java index b176857..77a010a 100644 --- a/src/main/java/site/billbill/apiserver/api/auth/dto/request/SignupRequest.java +++ b/src/main/java/site/billbill/apiserver/api/auth/dto/request/SignupRequest.java @@ -7,16 +7,18 @@ public class SignupRequest { @Schema(description = "회원 프로필 이미지 URL", example = "profile image url") private String profileImage; + @Schema(description = "이메일", example = "abcde@gmail.com") + private String email; @Schema(description = "회원 닉네임", example = "nickname") private String nickname; @Schema(description = "비밀번호", example = "password") private String password; - @Schema(description = "회원 본인인증 정보") - private IdentityRequest identity; +// @Schema(description = "회원 본인인증 정보") +// private IdentityRequest identity; @Schema(description = "각종 약관 동의") private AgreeRequest agree; - @Schema(description = "위치 정보") - private LocationRequest location; +// @Schema(description = "위치 정보") +// private LocationRequest location; @Schema(description = "디바이스 정보") private DeviceRequest device; } \ No newline at end of file diff --git a/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java b/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java index bafea2c..504e718 100644 --- a/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/auth/service/AuthServiceImpl.java @@ -27,6 +27,7 @@ import site.billbill.apiserver.model.user.*; import site.billbill.apiserver.repository.user.*; +import javax.swing.text.html.Option; import java.util.Optional; @Slf4j @@ -46,30 +47,31 @@ public class AuthServiceImpl implements AuthService { @Transactional public JwtDto signup(SignupRequest request) { // Check new by name & phoneNumber - Optional identityJpaEntity = userIdentityRepository.findUserByPhoneNumberWithoutWithdraw(request.getIdentity().getPhoneNumber()); +// Optional identityJpaEntity = userIdentityRepository.findUserByPhoneNumberWithoutWithdraw(request.getIdentity().getPhoneNumber()); + + Optional userAlready = userRepository.findByEmailWithoutWithdraw(request.getEmail()); // if user already exists - if (identityJpaEntity.isPresent()) { + if (userAlready.isPresent()) throw new CustomException(ErrorCode.Conflict, "이미 존재하는 회원입니다.", HttpStatus.CONFLICT); - } String encryptedPassword = bCryptPasswordEncoder.encode(request.getPassword()); // if user new String userId = ULIDUtil.generatorULID("USER"); - UserIdentityJpaEntity userIdentity = UserIdentityJpaEntity.toJpaEntity(userId, request.getIdentity()); - UserJpaEntity user = new UserJpaEntity(new UserBaseInfo(userId, request.getProfileImage(), request.getNickname(), encryptedPassword)); +// UserIdentityJpaEntity userIdentity = UserIdentityJpaEntity.toJpaEntity(userId, request.getIdentity()); + UserJpaEntity user = new UserJpaEntity(new UserBaseInfo(userId, request.getEmail(), request.getProfileImage(), request.getNickname(), encryptedPassword)); UserAgreeHistJpaEntity userAgree = new UserAgreeHistJpaEntity(userId, request.getAgree().isServiceAgree(), request.getAgree().isPrivacyAgree(), request.getAgree().isMarketingAgree(), request.getAgree().isThirdPartyAgree()); UserDeviceJpaEntity userDevice = new UserDeviceJpaEntity(userId, ULIDUtil.generatorULID("DEVICE"), request.getDevice().getDeviceToken(), request.getDevice().getDeviceType(), request.getDevice().getAppVersion()); // save new user userRepository.save(user); - userIdentityRepository.save(userIdentity); +// userIdentityRepository.save(userIdentity); userDeviceRepository.save(userDevice); userAgreeHistRepository.save(userAgree); // save location - userService.saveLocation(userId, request.getLocation()); +// userService.saveLocation(userId, request.getLocation()); return jwtUtil.generateJwtDto(userId, UserRole.USER); } @@ -77,23 +79,19 @@ public JwtDto signup(SignupRequest request) { @Override public JwtDto login(LoginRequest request) { // bring user's phone number - Optional userIdentityJpaEntity = userIdentityRepository.findUserByPhoneNumberWithoutWithdraw(request.getPhoneNumber()); +// Optional userIdentityJpaEntity = userIdentityRepository.findUserByPhoneNumberWithoutWithdraw(request.getPhoneNumber()); - if (userIdentityJpaEntity.isEmpty()) - throw new CustomException(ErrorCode.NotFound, "전화번호를 확인해주세요", HttpStatus.NOT_FOUND); + Optional user = userRepository.findByEmailWithoutWithdraw(request.getEmail()); - // bring user's password - String userId = userIdentityJpaEntity.get().getUserId(); - Optional userJpaEntity = userRepository.findById(userId); - if (userJpaEntity.isEmpty()) - throw new CustomException(ErrorCode.NotFound, "해당 회원이 존재하지 않습니다.", HttpStatus.NOT_FOUND); + // if user already exists + if (user.isEmpty()) + throw new CustomException(ErrorCode.Conflict, "해당 회원이 존재하지 않습니다.", HttpStatus.CONFLICT); - String encryptedPassword = userJpaEntity.get().getPassword(); + String encryptedPassword = user.get().getPassword(); if (!checkPassword(request.getPassword(), encryptedPassword)) throw new CustomException(ErrorCode.Unauthorized, "비밀번호를 확인해 주세요.", HttpStatus.UNAUTHORIZED); - - - return jwtUtil.generateJwtDto(userId, userJpaEntity.get().getRole()); + + return jwtUtil.generateJwtDto(user.get().getUserId(), user.get().getRole()); } @Override diff --git a/src/main/java/site/billbill/apiserver/model/user/UserJpaEntity.java b/src/main/java/site/billbill/apiserver/model/user/UserJpaEntity.java index db47e4c..afea7da 100644 --- a/src/main/java/site/billbill/apiserver/model/user/UserJpaEntity.java +++ b/src/main/java/site/billbill/apiserver/model/user/UserJpaEntity.java @@ -57,6 +57,7 @@ public class UserJpaEntity extends BaseTime { public UserJpaEntity(UserBaseInfo info) { this.userId = info.getUserId(); + this.email = info.getEmail(); this.nickname = info.getNickname(); this.profile = info.getProfileImage(); this.password = info.getPassword(); diff --git a/src/main/java/site/billbill/apiserver/repository/user/UserDslRepository.java b/src/main/java/site/billbill/apiserver/repository/user/UserDslRepository.java index 97a168b..c0bd827 100644 --- a/src/main/java/site/billbill/apiserver/repository/user/UserDslRepository.java +++ b/src/main/java/site/billbill/apiserver/repository/user/UserDslRepository.java @@ -1,9 +1,14 @@ package site.billbill.apiserver.repository.user; import site.billbill.apiserver.api.users.dto.request.ProfileRequest; +import site.billbill.apiserver.model.user.UserJpaEntity; + +import java.util.Optional; public interface UserDslRepository { void withdrawUserById(String userId); void updateProfileById(String userId, ProfileRequest request); + + Optional findByEmailWithoutWithdraw(String email); } diff --git a/src/main/java/site/billbill/apiserver/repository/user/UserDslRepositoryImpl.java b/src/main/java/site/billbill/apiserver/repository/user/UserDslRepositoryImpl.java index 197fc6a..028aed4 100644 --- a/src/main/java/site/billbill/apiserver/repository/user/UserDslRepositoryImpl.java +++ b/src/main/java/site/billbill/apiserver/repository/user/UserDslRepositoryImpl.java @@ -7,8 +7,10 @@ import org.springframework.stereotype.Repository; import site.billbill.apiserver.api.users.dto.request.ProfileRequest; import site.billbill.apiserver.model.user.QUserJpaEntity; +import site.billbill.apiserver.model.user.UserJpaEntity; import java.time.OffsetDateTime; +import java.util.Optional; @Repository @RequiredArgsConstructor @@ -40,4 +42,14 @@ public void updateProfileById(String userId, ProfileRequest request) { qb.execute(); } + + @Override + public Optional findByEmailWithoutWithdraw(String email) { + QUserJpaEntity qUser = QUserJpaEntity.userJpaEntity; + + JPAQuery qb = query.selectFrom(qUser) + .where(qUser.email.eq(email).and(qUser.withdrawStatus.isFalse())); + + return Optional.ofNullable(qb.fetchOne()); + } } diff --git a/src/main/java/site/billbill/apiserver/repository/user/UserIdentityDslRepository.java b/src/main/java/site/billbill/apiserver/repository/user/UserIdentityDslRepository.java index 3afde8b..c76e526 100644 --- a/src/main/java/site/billbill/apiserver/repository/user/UserIdentityDslRepository.java +++ b/src/main/java/site/billbill/apiserver/repository/user/UserIdentityDslRepository.java @@ -5,5 +5,5 @@ import java.util.Optional; public interface UserIdentityDslRepository { - public Optional findUserByPhoneNumberWithoutWithdraw(String phoneNumber); + Optional findUserByPhoneNumberWithoutWithdraw(String phoneNumber); }