Skip to content

Commit

Permalink
[feat] signup generateName 함수 추가
Browse files Browse the repository at this point in the history
signup generateName 함수 추가
  • Loading branch information
liyusang1 committed Jan 8, 2024
1 parent 858b46b commit 73fb55b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public record SignUpRequestDto(
String password
) {

public Member toEntity(String encodedPassword) {
public Member toEntity(String encodedPassword, String name) {
return Member.builder()
.email(email)
.nickname(name)
.password(encodedPassword)
.authority("ROLE_USER")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.haejwo.tripcometrue.domain.member.entity.Member;
import com.haejwo.tripcometrue.domain.member.exception.EmailDuplicateException;
import com.haejwo.tripcometrue.domain.member.repository.MemberRepository;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
Expand All @@ -26,7 +29,7 @@ public SignUpResponseDto signup(SignUpRequestDto signUpRequestDto) {

String encodedPassword = passwordEncoder.encode(signUpRequestDto.password());

Member newMember = signUpRequestDto.toEntity(encodedPassword);
Member newMember = signUpRequestDto.toEntity(encodedPassword, generateName());
memberRepository.save(newMember);
return SignUpResponseDto.fromEntity(newMember);
}
Expand All @@ -36,4 +39,16 @@ public void checkDuplicateEmail(String email) {
throw new EmailDuplicateException();
});
}

public String generateName() {
List<String> first = Arrays.asList("자유로운", "서운한",
"당당한", "배부른", "수줍은", "멋있는",
"열받은", "심심한", "잘생긴", "이쁜", "시끄러운");
List<String> name = Arrays.asList("사자", "코끼리", "호랑이", "곰", "여우", "늑대", "너구리",
"참새", "고슴도치", "강아지", "고양이", "거북이", "토끼", "앵무새", "하이에나", "돼지", "하마",
"얼룩말", "치타", "악어", "기린", "수달", "염소", "다람쥐", "판다");
Collections.shuffle(first);
Collections.shuffle(name);
return first.get(0) + name.get(0);
}
}

0 comments on commit 73fb55b

Please sign in to comment.