Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
회원가입 로직 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Feb 18, 2024
1 parent bf93d74 commit 4f3fa20
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions src/main/java/com/example/daemawiki/domain/auth/service/Signup.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

import com.example.daemawiki.domain.auth.dto.request.SignupRequest;
import com.example.daemawiki.domain.document.component.CreateDocumentByUser;
import com.example.daemawiki.domain.file.model.DefaultProfile;
import com.example.daemawiki.domain.mail.repository.AuthMailRepository;
import com.example.daemawiki.domain.user.model.User;
import com.example.daemawiki.domain.user.model.UserDetail;
import com.example.daemawiki.domain.user.model.type.component.GetMajorType;
import com.example.daemawiki.domain.user.repository.UserRepository;
import com.example.daemawiki.global.exception.h409.EmailAlreadyExistsException;
import com.example.daemawiki.global.exception.h403.UnVerifiedEmailException;
import com.example.daemawiki.domain.file.model.DefaultProfile;
import com.example.daemawiki.global.exception.h409.EmailAlreadyExistsException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

/*
유저 회원가입 성공시
Expand Down Expand Up @@ -44,32 +43,36 @@ public Signup(UserRepository userRepository,AuthMailRepository authMailRepositor
public Mono<Void> execute(SignupRequest request) {
return userRepository.findByEmail(request.email())
.flatMap(user -> Mono.error(EmailAlreadyExistsException.EXCEPTION))
.switchIfEmpty(Mono.defer(() -> authMailRepository.findByMail(request.email())
.flatMap(verified -> {
if (!verified) {
return Mono.error(UnVerifiedEmailException.EXCEPTION);
}
.switchIfEmpty(Mono.justOrEmpty(authMailRepository.findByMail(request.email())
.flatMap(verified -> {
if (!verified) {
return Mono.error(UnVerifiedEmailException.EXCEPTION);
}

return Mono.fromCallable(() -> passwordEncoder.encode(request.password()))
.subscribeOn(scheduler)
.flatMap(password -> {
User newUser = User.builder()
.name(request.name())
.email(request.email())
.password(password)
.profile(defaultProfile.defaultProfile())
.detail(UserDetail.builder()
.gen(request.gen())
.major(getMajorType.execute(request.major()))
.build())
.build();

return Mono.fromCallable(() -> passwordEncoder.encode(request.password()))
.subscribeOn(scheduler)
.map(password -> User.builder()
.name(request.name())
.email(request.email())
.password(password)
.profile(defaultProfile.defaultProfile())
.detail(UserDetail.builder()
.gen(request.gen())
.major(getMajorType.execute(request.major()))
.build())
.build())
.flatMap(userRepository::save)
.publishOn(Schedulers.parallel())
.flatMap(user -> createDocumentByUser.execute(user)
.flatMap(document -> {
user.setDocumentId(document.getId());
return userRepository.save(user);
}).subscribeOn(scheduler));
}))).then();
return userRepository.save(newUser)
.flatMap(user -> createDocumentByUser.execute(user)
.flatMap(document -> {
user.setDocumentId(document.getId());
return userRepository.save(user);
}));
});
})))
.then();
}


}

0 comments on commit 4f3fa20

Please sign in to comment.