Skip to content

Commit

Permalink
Merge pull request #166 from PawWithU/feat/165-sign-up-api-modify
Browse files Browse the repository at this point in the history
[Feature] 이동봉사자, 모집자 자체 회원가입 API 수정
  • Loading branch information
kyeong-hyeok committed May 1, 2024
2 parents 2f5bd06 + 2afbce6 commit 2e5ccf4
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public class SignUpController {
@Operation(summary = "이동봉사자 자체 회원가입", description = "이동봉사자 자체 회원가입을 합니다.",
responses = {@ApiResponse(responseCode = "204", description = "이동봉사자 자체 회원가입 성공")
, @ApiResponse(responseCode = "400"
, description = "V1, 이메일 형식에 맞지 않습니다. \t\n V1, 이메일은 필수 입력 값입니다. \t\n V1, 영문+숫자 10자 이상 또는 영문+숫자+특수기호 8자 이상을 입력해 주세요. \t\n " +
"V1, 닉네임은 한글, 숫자만 사용 가능합니다. \t\n V1, 닉네임은 필수 입력 값입니다. \t\n V1, 닉네임은 2~10자로 입력해 주세요. \t\n A1, 이미 등록된 이메일입니다. \t\n A2, 이미 사용 중인 닉네임입니다."
, description = "V1, 이름은 필수 입력 값입니다. \t\n V1, 이메일 형식에 맞지 않습니다. \t\n V1, 휴대전화 번호는 필수 입력 값입니다. \t\n V1, 유효하지 않은 휴대전화 번호입니다. \t\n " +
"V1, 이메일은 필수 입력 값입니다. \t\n V1, 영문+숫자 10자 이상 또는 영문+숫자+특수기호 8자 이상을 입력해 주세요. \t\n " +
"V1, 닉네임은 한글, 숫자만 사용 가능합니다. \t\n V1, 닉네임은 필수 입력 값입니다. \t\n V1, 닉네임은 2~10자로 입력해 주세요. \t\n A1, 이미 등록된 이메일입니다. \t\n A2, 이미 사용 중인 닉네임입니다. \t\n A8, 이미 등록된 전화번호입니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PostMapping("/volunteers/sign-up")
Expand All @@ -47,8 +48,9 @@ public ResponseEntity<Void> volunteerSignUp(@RequestBody @Valid VolunteerSignUpR
@Operation(summary = "이동봉사 중개 자체 회원가입", description = "이동봉사 중개 자체 회원가입을 합니다.",
responses = {@ApiResponse(responseCode = "204", description = "이동봉사 중개 자체 회원가입 성공")
, @ApiResponse(responseCode = "400"
, description = "V1, 이메일 형식에 맞지 않습니다. \t\n V1, 이메일은 필수 입력 값입니다. \t\n " +
"V1, 영문+숫자 10자 이상 또는 영문+숫자+특수기호 8자 이상을 입력해 주세요. \t\n V1, 이름/단체명은 필수 입력 값입니다. \t\n V1, url 형식을 입력해 주세요. \t\n " +
, description = "V1, 이름은 필수 입력 값입니다 \t\n V1, 휴대전화 번호는 필수 입력 값입니다. \t\n V1, 유효하지 않은 휴대전화 번호입니다. \t\n " +
"V1, 이메일 형식에 맞지 않습니다. \t\n V1, 이메일은 필수 입력 값입니다. \t\n " +
"V1, 영문+숫자 10자 이상 또는 영문+숫자+특수기호 8자 이상을 입력해 주세요. \t\n V1, 모집자명은 필수 입력 값입니다. \t\n V1, url 형식을 입력해 주세요. \t\n " +
"V1, 한줄 소개는 50자 이하로 입력해 주세요. \t\n A1, 이미 등록된 이메일입니다. \t\n F1, 파일이 존재하지 않습니다. \t\n F2, 파일 업로드에 실패했습니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,32 @@
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;

public record IntermediarySignUpRequest(@Email(message="이메일 형식에 맞지 않습니다.")
@NotBlank(message = "이메일은 필수 입력 값입니다.") String email,
public record IntermediarySignUpRequest(Boolean isOptionAgr,
@NotBlank(message = "이름은 필수 입력 값입니다.")
String realName,
@NotBlank(message = "휴대전화 번호는 필수 입력 값입니다.")
@Pattern(regexp = "^010[0-9]{8}$", message = "유효하지 않은 휴대전화 번호입니다.")
String phone,
@Email(message="이메일 형식에 맞지 않습니다.")
@NotBlank(message = "이메일은 필수 입력 값입니다.")
String email,
@Pattern(regexp = "^(?=.*[a-zA-Z])(?=.*\\d).{10,}$|^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[~!@#$%^&*()+|=?]).{8,}$",
message = "영문+숫자 10자 이상 또는 영문+숫자+특수기호 8자 이상을 입력해 주세요.") String password,
@NotBlank(message = "이름/단체명은 필수 입력 값입니다.")
message = "영문+숫자 10자 이상 또는 영문+숫자+특수기호 8자 이상을 입력해 주세요.")
String password,
@NotBlank(message = "모집자명은 필수 입력 값입니다.")
String name,
@Pattern(regexp = "^(http|https)://[a-zA-Z0-9-.]+\\.[a-zA-Z]{2,}(/\\S*)?$",
message = "url 형식을 입력해 주세요.") String url,
@Size(max=50, message = "한줄 소개는 50자 이하로 입력해 주세요.")
String intro,
String contact,
Boolean isOptionAgr) {
@Pattern(regexp = "^(http|https)://[a-zA-Z0-9-.]+\\.[a-zA-Z]{2,}(/\\S*)?$",
message = "url 형식을 입력해 주세요.")
String url,
String contact) {

public static Intermediary toEntity(IntermediarySignUpRequest request, String authImage, String profileImage) {
return Intermediary.builder()
.isOptionAgr(request.isOptionAgr)
.realName(request.realName)
.phone(request.phone)
.email(request.email)
.password(request.password)
.name(request.name)
Expand All @@ -30,7 +41,6 @@ public static Intermediary toEntity(IntermediarySignUpRequest request, String au
.profileImage(profileImage)
.intro(request.intro)
.contact(request.contact)
.isOptionAgr(request.isOptionAgr)
.role(IntermediaryRole.INTERMEDIARY)
.notification(true)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,35 @@
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;

public record VolunteerSignUpRequest(@Email(message="이메일 형식에 맞지 않습니다.")
@NotBlank(message = "이메일은 필수 입력 값입니다.") String email,
public record VolunteerSignUpRequest(Boolean isOptionAgr,
@NotBlank(message = "이름은 필수 입력 값입니다.")
String name,
@NotBlank(message = "휴대전화 번호는 필수 입력 값입니다.")
@Pattern(regexp = "^010[0-9]{8}$", message = "유효하지 않은 휴대전화 번호입니다.")
String phone,
@Email(message="이메일 형식에 맞지 않습니다.")
@NotBlank(message = "이메일은 필수 입력 값입니다.")
String email,
@Pattern(regexp = "^(?=.*[a-zA-Z])(?=.*\\d).{10,}$|^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[~!@#$%^&*()+|=?]).{8,}$",
message = "영문+숫자 10자 이상 또는 영문+숫자+특수기호 8자 이상을 입력해 주세요.") String password,
message = "영문+숫자 10자 이상 또는 영문+숫자+특수기호 8자 이상을 입력해 주세요.")
String password,
@Pattern(regexp = "^[가-힣0-9]*$", message = "닉네임은 한글, 숫자만 사용 가능합니다.")
@NotBlank(message = "닉네임은 필수 입력 값입니다.")
@Size(min=2, max=10, message = "닉네임은 2~10자로 입력해 주세요.")
String nickname,
Integer profileImageNum,
Boolean isOptionAgr) {
Integer profileImageNum) {

public Volunteer toEntity() {
return Volunteer.builder()
.isOptionAgr(isOptionAgr)
.name(name)
.phone(phone)
.email(email)
.password(password)
.nickname(nickname)
.profileImageNum(profileImageNum)
.isOptionAgr(isOptionAgr)
.notification(true)
.role(VolunteerRole.VOLUNTEER)
.role(VolunteerRole.AUTH_VOLUNTEER)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class AuthService {

public void volunteerSignUp(VolunteerSignUpRequest request) {

if (volunteerRepository.existsByPhone(request.phone())) {
throw new BadRequestException(ALREADY_EXIST_PHONE);
}
if (volunteerRepository.existsByEmail(request.email())) {
throw new BadRequestException(ALREADY_EXIST_EMAIL);
}
Expand All @@ -58,6 +61,9 @@ public void volunteerSignUp(VolunteerSignUpRequest request) {

public void intermediarySignUp(IntermediarySignUpRequest request, MultipartFile authFile, MultipartFile profileFile) {

if (intermediaryRepository.existsByPhone(request.phone())) {
throw new BadRequestException(ALREADY_EXIST_PHONE);
}
if (intermediaryRepository.existsByEmail(request.email())) {
throw new BadRequestException(ALREADY_EXIST_EMAIL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ public class Intermediary extends BaseTimeEntity {
private Boolean notification; // 알림 true, false
@Column(length = 200)
private String guide; // 안내사항 (프로필 수정에서 입력)
@Column(length = 10)
private String realName;
private String phone;

@Builder
public Intermediary(String email, String password, String name, String url, String authImage, String profileImage, String intro, String contact, IntermediaryRole role, Boolean isOptionAgr, Boolean notification) {
public Intermediary(String realName, String phone, String email, String password, String name, String url, String authImage, String profileImage, String intro, String contact, IntermediaryRole role, Boolean isOptionAgr, Boolean notification) {
this.realName = realName;
this.phone = phone;
this.email = email;
this.password = password;
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface IntermediaryRepository extends JpaRepository<Intermediary, Long
Boolean existsByEmail(String email);
Boolean existsByName(String name);
Optional<Intermediary> findByEmail(String email);
Boolean existsByPhone(String phone);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ public class Volunteer extends BaseTimeEntity {
private Boolean notification; // 알림 true, false

@Builder
public Volunteer(String email, String password, String nickname, Integer profileImageNum, VolunteerRole role, Boolean isOptionAgr, Boolean notification) {
public Volunteer(Boolean isOptionAgr, String name, String phone, String email, String password, String nickname, Integer profileImageNum, VolunteerRole role, Boolean notification) {
this.isOptionAgr = isOptionAgr;
this.name = name;
this.phone = phone;
this.email = email;
this.password = password;
this.nickname = nickname;
this.profileImageNum = profileImageNum;
this.role = role;
this.isOptionAgr = isOptionAgr;
this.notification = notification;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public interface VolunteerRepository extends JpaRepository<Volunteer, Long> {
Boolean existsByEmail(String email);
Boolean existsByNickname(String nickname);
Optional<Volunteer> findByEmail(String email);
Boolean existsByPhone(String phone);

}
1 change: 1 addition & 0 deletions src/main/java/com/pawwithu/connectdog/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum ErrorCode {
UNKNOWN_PROVIDER("A5", "provider 값이 KAKAO 또는 NAVER가 아닙니다."),
NOT_ALLOWED_MEMBER("A6", "해당 요청에 대한 권한이 없습니다."),
NOT_AUTHENTICATED_REQUEST("A7", "유효한 JWT 토큰이 없습니다."),
ALREADY_EXIST_PHONE("A8", "이미 등록된 전화번호입니다."),


VOLUNTEER_NOT_FOUND("M1", "해당 이동봉사자를 찾을 수 없습니다."), // Member -> M (이동봉사자, 이동봉사 중개 통일)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ void setUp() {
@Test
void 이동봉사자_자체_회원입() throws Exception{
//given
VolunteerSignUpRequest request = new VolunteerSignUpRequest("[email protected]",
"pasword12345",
"코넥독",
3,
false);
VolunteerSignUpRequest request = new VolunteerSignUpRequest(true, "한호정", "01011112222",
"[email protected]", "pasword12345", "코넥독", 3);
//when
ResultActions result = mockMvc.perform(
post("/volunteers/sign-up")
Expand All @@ -90,13 +87,12 @@ void setUp() {
@Test
void 이동봉사_중개_자체_회원입() throws Exception{
//given
IntermediarySignUpRequest request = new IntermediarySignUpRequest("[email protected]",
IntermediarySignUpRequest request = new IntermediarySignUpRequest(true, "한호정", "01011112222", "[email protected]",
"pasword12345",
"이동봉사 단체",
"https://connectdog.site",
"안녕하세요 코넥독입니다.",
"인스타그램",
false);
"https://connectdog.site",
"인스타그램");

MockMultipartFile authImage = new MockMultipartFile("authImage", "authImage.png", "multipart/form-data", "uploadFile".getBytes(StandardCharsets.UTF_8));
MockMultipartFile profileImage = new MockMultipartFile("profileImage", "profileImage.png", "multipart/form-data", "uploadFile".getBytes(StandardCharsets.UTF_8));
Expand Down

0 comments on commit 2e5ccf4

Please sign in to comment.