Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : 전화번호 형식 변경 및 validation 적용 #745

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
package net.causw.adapter.persistence.repository.user;

import net.causw.adapter.persistence.user.UserAdmission;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface UserAdmissionRepository extends JpaRepository<UserAdmission, String> {
Optional<UserAdmission> findByUser_Id(String userId);

Boolean existsByUser_Id(String userId);

@Query(value = "SELECT * " +
"FROM tb_user_admission AS ua " +
"LEFT JOIN tb_user AS u ON ua.user_id = u.id " +
"WHERE u.state = :user_state ORDER BY ua.created_at DESC", nativeQuery = true)
Page<UserAdmission> findAll(@Param("user_state") String userState, Pageable pageable);

@Query(value = "SELECT ua.id AS id, ua.user_id,ua.image,ua.reject_reason,ua.description,ua.updated_at,ua.created_at, u.name, u.state " +
"FROM tb_user_admission AS ua " +
"LEFT JOIN tb_user AS u ON ua.user_id = u.id " +
"WHERE u.state = :user_state AND (:name IS NULL OR u.name LIKE %:name%) ORDER BY ua.created_at DESC", nativeQuery = true)
Page<UserAdmission> findAllWithName(@Param("user_state") String userState, @Param("name") String name, Pageable pageable);
package net.causw.adapter.persistence.repository.user;

import net.causw.adapter.persistence.user.UserAdmission;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface UserAdmissionRepository extends JpaRepository<UserAdmission, String> {
Optional<UserAdmission> findByUser_Id(String userId);

Boolean existsByUser_Id(String userId);

@Query(value = "SELECT * " +
"FROM tb_user_admission AS ua " +
"LEFT JOIN tb_user AS u ON ua.user_id = u.id " +
"WHERE u.state = :user_state ORDER BY ua.created_at DESC", nativeQuery = true)
Page<UserAdmission> findAll(@Param("user_state") String userState, Pageable pageable);

@Query(value = "SELECT ua.id AS id, ua.user_id,uai.uuid_file_id AS user_admission_attach_image ,ua.description,ua.updated_at,ua.created_at, u.name, u.state " +
"FROM tb_user_admission AS ua " +
"LEFT JOIN tb_user AS u ON ua.user_id = u.id " +
"LEFT JOIN tb_user_admission_attach_image_uuid_file AS uai ON ua.id = uai.user_admission_id " +
"WHERE u.state = :user_state AND (:name IS NULL OR u.name LIKE %:name%) ORDER BY ua.created_at DESC", nativeQuery = true)
Page<UserAdmission> findAllWithName(@Param("user_state") String userState, @Param("name") String name, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class UserCreateRequestDto {
private String major;

@Schema(description = "전화번호", example = "01012345678", requiredMode = Schema.RequiredMode.REQUIRED)
@Pattern(regexp = "^01(?:0|1|[6-9])(\\d{3}|\\d{4})\\d{4}$", message = "전화번호 형식에 맞지 않습니다.")
@Pattern(regexp = "^01(?:0|1|[6-9])-(\\d{3}|\\d{4})-\\d{4}$", message = "전화번호 형식에 맞지 않습니다.")
private String phoneNumber;

}
2 changes: 2 additions & 0 deletions src/main/java/net/causw/application/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import net.causw.domain.validation.UserStateIsDropOrIsInActiveValidator;
import net.causw.domain.validation.UserStateIsNotDropAndActiveValidator;
import net.causw.domain.validation.UserStateValidator;
import net.causw.domain.validation.PhoneNumberFormatValidator;
import net.causw.domain.validation.ValidatorBucket;
import net.causw.infrastructure.GoogleMailSender;
import net.causw.infrastructure.PasswordGenerator;
Expand Down Expand Up @@ -576,6 +577,7 @@ public UserResponseDto signUp(UserCreateRequestDto userCreateRequestDto) {
.consistOf(ConstraintValidator.of(user, this.validator))
.consistOf(PasswordFormatValidator.of(userCreateRequestDto.getPassword()))
.consistOf(AdmissionYearValidator.of(userCreateRequestDto.getAdmissionYear()))
.consistOf(PhoneNumberFormatValidator.of(userCreateRequestDto.getPhoneNumber()))
.validate();

return UserDtoMapper.INSTANCE.toUserResponseDto(user, null, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.causw.domain.validation;

import net.causw.domain.exceptions.BadRequestException;
import net.causw.domain.exceptions.ErrorCode;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PhoneNumberFormatValidator extends AbstractValidator {

private final String phoneNumber;

private PhoneNumberFormatValidator(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public static PhoneNumberFormatValidator of(String phoneNumber) {
return new PhoneNumberFormatValidator(phoneNumber);
}

@Override
public void validate() {
if (!this.validatePhoneNumber()) {
throw new BadRequestException(
ErrorCode.INVALID_USER_DATA_REQUEST,
"전화번호 형식이 잘못되었습니다."
);
}
}

public boolean validatePhoneNumber() {
String phoneNumberPolicy = "^01(?:0|1|[6-9])-(\\d{3}|\\d{4})-\\d{4}$";
Pattern pattern_phoneNumber = Pattern.compile(phoneNumberPolicy);
Matcher matcher_phoneNumber = pattern_phoneNumber.matcher(this.phoneNumber);

return matcher_phoneNumber.matches();
}
}
Loading