채널 쪽 api를 설계 후 우리의 erd를 보니깐 현재 이메일하고 비밀번호밖에 없다.
그래서 user name이라고, 닉네임 같은 걸 넣어줬다.
그래서 dto에 user name을 추가해 주고!
@AllArgsConstructor
@Getter
public class UserRequestDto {
private String username;
private String email;
private String password;
private String intro;
}
@Getter
public class UserResponseDto {
@JsonProperty
private Long id;
@JsonProperty
private String username;
@JsonProperty
private String email;
@JsonProperty
private String intro;
@JsonProperty
private String status;
public UserResponseDto(User user) {
this.id = user.getId();
this.username = user.getUsername();
this.email = user.getEmail();
this.intro = user.getIntro();
this.status = User.Status.values()[user.getStatus()].name();
}
}
엔티티에도 추가를 해줬다
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
public class User {
@Id
private Long id;
private String email;
private String password;
private String intro;
private String username;
private int status;
private int verificationCode;
// 상태: 인증 전, 인증 완료, 탈퇴
public enum Status {
TEMPORARY, ACTIVATE, DEACTIVATE
}
@Builder
public User(Long id, String email, String password, String intro, String username, Status status, Integer verificationCode) {
this.id = id;
this.email = email;
this.password = password;
this.intro = intro;
this.username = username;
this.status = status == null ? Status.TEMPORARY.ordinal() : status.ordinal();
this.verificationCode = verificationCode == null ? new Random(System.currentTimeMillis()).nextInt(900000) + 100000 : verificationCode;
}
public boolean checkActivate() {
return this.status == Status.ACTIVATE.ordinal();
}
public void activateStatus() {
if (this.status == Status.ACTIVATE.ordinal()) {
throw new CustomException(UserErrorCode.ALREADY_ACCOUNT_ACTIVATED);
}
this.status = Status.ACTIVATE.ordinal();
}
public boolean checkVerificationCode(int inputCode) {
return this.getVerificationCode() == inputCode;
}
public void updateUsername(String username) {
this.username = username;
}
public void updateIntro(String intro) {
this.intro = intro;
}
public void updatePassword(String password) {
this.password = password;
}
}
sql도 추가를 해줬다
create table if not exists user (
id bigint primary key auto_increment,
username varchar(50),
email varchar(50),
password varchar(255),
intro varchar(100),
status int(1),
verification_code int(6)
);
userservice도 변경.
@RequiredArgsConstructor
@Service
public class UserService {
private final UserRepository userRepository;
private final PasswordEncoder passwordEncoder;
protected Mono<User> signup(UserRequestDto req) {
return checkDuplicateEmail(req.getEmail())
.subscribeOn(Schedulers.boundedElastic())
.then(Mono.just(User.builder()
.email(req.getEmail())
.password(passwordEncoder.encode(req.getPassword()))
.intro(req.getIntro())
.username(req.getUsername())
.status(User.Status.TEMPORARY)
.build())
)
.flatMap(userRepository::save)
.doOnError(error -> System.err.println("Error: " + error.getMessage()));
}
그냥 user name만 추가하는 거라 그렇게 어렵진 않았다.
'TIL' 카테고리의 다른 글
TIL - 2024/07/31 (0) | 2024.08.05 |
---|---|
TIL - 2024/07/30 (0) | 2024.08.05 |
TIL - 2024/07/28 (0) | 2024.08.02 |
TIL - 2024/07/27 (0) | 2024.07.31 |
TIL - 2024/07/26 (0) | 2024.07.27 |