-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 회원가입 기능을 구현했어요. - 회원가입시 이메일 인증이 되어있지 않으면 예외를 발생시켜요. - 회원가입시 이미 존재하는 유저면 예외를 발생시켜요.
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/com/bamdoliro/sinabro/application/user/SignUpUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.bamdoliro.sinabro.application.user; | ||
|
||
import com.bamdoliro.sinabro.domain.user.domain.SignUpVerification; | ||
import com.bamdoliro.sinabro.domain.user.domain.User; | ||
import com.bamdoliro.sinabro.domain.user.domain.type.Authority; | ||
import com.bamdoliro.sinabro.infrastructure.persistence.user.SignUpVerificationRepository; | ||
import com.bamdoliro.sinabro.infrastructure.persistence.user.UserRepository; | ||
import com.bamdoliro.sinabro.presentation.user.dto.request.SignUpRequest; | ||
import com.bamdoliro.sinabro.shared.annotation.UseCase; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@UseCase | ||
public class SignUpUseCase { | ||
|
||
private final UserRepository userRepository; | ||
private final SignUpVerificationRepository signUpVerificationRepository; | ||
|
||
@Transactional | ||
public void execute(SignUpRequest request) { | ||
validate(request); | ||
|
||
userRepository.save( | ||
User.builder() | ||
.email(request.getEmail()) | ||
.name(request.getName()) | ||
.password(request.getPassword()) | ||
.authority(Authority.USER) | ||
.build() | ||
); | ||
} | ||
|
||
private void validate(SignUpRequest request) { | ||
SignUpVerification signUpVerification = signUpVerificationRepository.findById(request.getEmail()) | ||
.orElseThrow(RuntimeException::new); | ||
|
||
if (!signUpVerification.getIsVerified()) { | ||
throw new RuntimeException(); | ||
} | ||
|
||
if (userRepository.existsByEmail(request.getEmail())) { | ||
throw new RuntimeException(); | ||
} | ||
|
||
signUpVerificationRepository.delete(signUpVerification); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/bamdoliro/sinabro/presentation/user/dto/request/SignUpRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.bamdoliro.sinabro.presentation.user.dto.request; | ||
|
||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Pattern; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class SignUpRequest { | ||
|
||
@NotBlank(message = "필수값입니다.") | ||
@Email(message = "이메일 형식이어야 합니다") | ||
private String email; | ||
|
||
@NotBlank(message = "필수값입니다.") | ||
@Size(max = 50, message = "50자 이하여야 합니다.") | ||
private String name; | ||
|
||
@NotBlank(message = "필수값입니다.") | ||
@Size(max = 20, message = "비밀번호는 20글자 이하여야 합니다.") | ||
@Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d)(?=.*[$@$!%*#?&])[A-Za-z\\d$@$!%*#?&]{8,}$", | ||
message = "비밀번호는 최소 하나의 문자, 숫자, 특수문자를 포함하며 8 글자 이상이어야 합니다.") | ||
private String password; | ||
} |