Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…GING-BE into bugfix/#438/content-detail-user-null-check
  • Loading branch information
mooncw committed Nov 25, 2024
2 parents cdc5a5a + 9eadee8 commit c472697
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ public class BadRequestMessageConstant {
public static final String MAX_CATEGORY_SELECTION_ERROR_MESSAGE = "카테고리 목록은 최대 5개 선택 가능";
public static final String BLANK_CONTENT_KEYWORD_ERROR_MESSAGE = "컨테츠 검색 키워드 blank 허용 불가";
public static final String NULL_MISSION_LIST_ERROR_MESSAGE = "미션 체크 목록 null 허용 불가";
public static final String MIN_POINT_AMOUNT_ERROR_MESSAGE = "총 포인트 음수 불가";
public static final String DATE_PATTERN_MISMATCH = "입력된 날짜가 잘못된 형식";
public static final String NULL_CONTENT_ID_ERROR_MESSAGE = "컨텐츠 Id는 null 허용 불가";
public static final String NULL_CONTENT_LEVEL_ERROR_MESSAGE = "컨텐츠 level은 null 허용 불가";
public static final String NICKNAME_SIZE_LIMIT_ERROR_MESSAGE = "닉네임 길이는 4~12 사이의 값만 가능";
public static final String NICKNAME_PATTERN_ERROR_MESSAGE = "닉네임에는 특수문자 혹은 두 번 이상의 연속 띄어쓰기 불가";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public class RestrictionConstant {
public static final int MAX_QUIZ_SIZE = 4;
public static final int MINIMUM_CONTENT_LEVEL_FEEDBACK_COUNT = 5;
public static final double CONTENT_LEVEL_DETERMINATION_THRESHOLD = 0.85;
public static final int MIN_NICKNAME_SIZE = 4;
public static final int MAX_NICKNAME_SIZE = 12;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class UserEntity extends BaseEntity {
@Column(nullable = false, columnDefinition = "varchar(255)")
private String username;

@Column(nullable = false, columnDefinition = "varchar(255)")
@Column(nullable = false, columnDefinition = "varchar(12)")
private String nickname;

@Column(columnDefinition = "varchar(255)")
Expand Down Expand Up @@ -129,10 +129,7 @@ public static UserEntity createByOAuthUser(
}

// 본인 정보 수정
public void updateMyInfo(
String username, String nickname, String phoneNumber, LocalDate birth, Gender gender
) {
this.username = StringUtils.defaultIfBlank(username, this.username);
public void updateMyInfo(String nickname, String phoneNumber, LocalDate birth, Gender gender) {
this.nickname = StringUtils.defaultIfBlank(nickname, this.nickname);
this.phoneNumber = StringUtils.defaultIfBlank(phoneNumber, this.phoneNumber);
this.birth = Optional.ofNullable(birth).orElse(this.birth);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public enum UserErrorCode implements ErrorCode {
),
USER_PERMISSION_DENIED(
HttpStatus.FORBIDDEN, UserServiceStatus.USER_PERMISSION_DENIED, "잘못된 접근 권한"
);
)
;

private final HttpStatus httpStatus;
private final ServiceStatus serviceStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public enum UserServiceStatus implements ServiceStatus{
USER_NOT_FOUND("U-U-901"),
USER_FAIL_DEACTIVATE("U-U-902"),
USER_FAIL_SUSPEND("U-U-903"),
USER_PERMISSION_DENIED("U-U-904");
USER_PERMISSION_DENIED("U-U-904")
;

private final String code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ public class UserStoreImpl implements UserStore {
// 본인 정보 수정
@Override
public void updateMyInfo(UserCommand.UpdateMyInfo command) {

UserEntity user = userRepository.findByIdAndEmail(command.userId(), command.email())
.orElseThrow(() -> new CommonException(USER_NOT_FOUND));

// UserEntity Dirty Checking
user.updateMyInfo(
command.username(), command.nickname(), command.phoneNumber(), command.birth(), command.gender()
);
user.updateMyInfo(command.nickname(), command.phoneNumber(), command.birth(), command.gender());
userRepository.save(user);

if (command.categoryIds() != null) {
// user가 이미 관심 카테고리로 등록한 CategoryIds List
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@

import com.biengual.core.enums.Gender;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;


public class UserRequestDto {

// 본인 정보 수정
public record UpdateMyInfoReq(
String username,
String nickname,
String phoneNumber,
LocalDate birth,
Gender gender,
@Size(max = MAX_CATEGORY_SELECTION_LIMIT, message = MAX_CATEGORY_SELECTION_ERROR_MESSAGE)
List<Long> categories
) {

}
// 본인 정보 수정
public record UpdateMyInfoReq(
String username,
@Size(min = MIN_NICKNAME_SIZE, max = MAX_NICKNAME_SIZE, message = NICKNAME_SIZE_LIMIT_ERROR_MESSAGE)
@Pattern(regexp = "^[a-zA-Z가-힣0-9]+( [a-zA-Z가-힣0-9]+)*$", message = NICKNAME_PATTERN_ERROR_MESSAGE)
String nickname,
String phoneNumber,
LocalDate birth,
Gender gender,
@Size(max = MAX_CATEGORY_SELECTION_LIMIT, message = MAX_CATEGORY_SELECTION_ERROR_MESSAGE)
List<Long> categories
) {
}

}
15 changes: 15 additions & 0 deletions user-api/src/main/resources/db/migration/V1.17.0__update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
UPDATE user
SET nickname = CONCAT(
CASE
WHEN RAND() < 0.2 THEN '용감한 강아지 '
WHEN RAND() < 0.4 THEN '빠른 고양이 '
WHEN RAND() < 0.6 THEN '행복한 도마뱀 '
WHEN RAND() < 0.8 THEN '친절한 다람쥐 '
ELSE '빛나는 여우 '
END,
LPAD(FLOOR(RAND() * 10000), 4, '0')
)
WHERE CHAR_LENGTH(nickname) < 4 || CHAR_LENGTH(nickname) > 12;

ALTER TABLE `user`
MODIFY COLUMN nickname VARCHAR(12) NOT NULL;

0 comments on commit c472697

Please sign in to comment.