Skip to content

Commit

Permalink
[fix] 회원가입 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ksj000625 committed Dec 22, 2024
1 parent 3ade1d7 commit 6f67a20
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@AllArgsConstructor
public class UserBaseInfo {
private String userId;
private String email;
private String profileImage;
private String nickname;
private String password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
public class SignupRequest {
@Schema(description = "회원 프로필 이미지 URL", example = "profile image url")
private String profileImage;
@Schema(description = "이메일", example = "[email protected]")
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,30 +47,31 @@ public class AuthServiceImpl implements AuthService {
@Transactional
public JwtDto signup(SignupRequest request) {
// Check new by name & phoneNumber
Optional<UserIdentityJpaEntity> identityJpaEntity = userIdentityRepository.findUserByPhoneNumberWithoutWithdraw(request.getIdentity().getPhoneNumber());
// Optional<UserIdentityJpaEntity> identityJpaEntity = userIdentityRepository.findUserByPhoneNumberWithoutWithdraw(request.getIdentity().getPhoneNumber());

Optional<UserJpaEntity> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<UserJpaEntity> findByEmailWithoutWithdraw(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -40,4 +42,14 @@ public void updateProfileById(String userId, ProfileRequest request) {

qb.execute();
}

@Override
public Optional<UserJpaEntity> findByEmailWithoutWithdraw(String email) {
QUserJpaEntity qUser = QUserJpaEntity.userJpaEntity;

JPAQuery<UserJpaEntity> qb = query.selectFrom(qUser)
.where(qUser.email.eq(email).and(qUser.withdrawStatus.isFalse()));

return Optional.ofNullable(qb.fetchOne());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
import java.util.Optional;

public interface UserIdentityDslRepository {
public Optional<UserIdentityJpaEntity> findUserByPhoneNumberWithoutWithdraw(String phoneNumber);
Optional<UserIdentityJpaEntity> findUserByPhoneNumberWithoutWithdraw(String phoneNumber);
}

0 comments on commit 6f67a20

Please sign in to comment.