Skip to content
Merged
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
Expand Up @@ -38,6 +38,11 @@ public enum ErrorCode implements ResponseCode {
*/
USER_NOT_FOUND(HttpStatus.NOT_FOUND, 70000, "존재하지 않는 USER 입니다."),
USER_ALREADY_FOLLOWED(HttpStatus.BAD_REQUEST, 70001, "이미 팔로우한 사용자입니다."),
USER_NICKNAME_TOO_LONG(HttpStatus.BAD_REQUEST, 70002, "사용자 닉네임은 10자 이하여야 합니다."),
USER_NICKNAME_CANNOT_BE_BLANK(HttpStatus.BAD_REQUEST, 70003, "사용자 닉네임은 비어있을 수 없습니다."),
USER_NICKNAME_CANNOT_BE_SAME(HttpStatus.BAD_REQUEST, 70004, "사용자 닉네임은 이전과 동일할 수 없습니다."),
USER_NICKNAME_UPDATE_TOO_FREQUENT(HttpStatus.BAD_REQUEST, 70005, "사용자 닉네임은 6개월에 한번 변경할 수 있습니다."),
USER_NICKNAME_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, 70006, "다른 사용자가 이미 사용중인 닉네임입니다."),

/**
* 75000 : follow error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public enum SwaggerResponseDescription {
USER_SEARCH(new LinkedHashSet<>(Set.of(
USER_NOT_FOUND
))),
USER_UPDATE(new LinkedHashSet<>(Set.of(
USER_NOT_FOUND,
ALIAS_NAME_NOT_MATCH,
USER_NICKNAME_TOO_LONG,
USER_NICKNAME_CANNOT_BE_BLANK,
USER_NICKNAME_CANNOT_BE_SAME,
USER_NICKNAME_UPDATE_TOO_FREQUENT,
USER_NICKNAME_ALREADY_EXISTS
))),


// Follow
CHANGE_FOLLOW_STATE(new LinkedHashSet<>(Set.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@
import konkuk.thip.common.swagger.annotation.ExceptionDescription;
import konkuk.thip.user.adapter.in.web.request.UserFollowRequest;
import konkuk.thip.user.adapter.in.web.request.UserSignupRequest;
import konkuk.thip.user.adapter.in.web.request.UserUpdateRequest;
import konkuk.thip.user.adapter.in.web.response.UserFollowResponse;
import konkuk.thip.user.adapter.in.web.response.UserSignupResponse;
import konkuk.thip.user.application.port.in.UserFollowUsecase;
import konkuk.thip.user.application.port.in.UserSignupUseCase;
import konkuk.thip.user.application.port.in.UserUpdateUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import static konkuk.thip.common.security.constant.AuthParameters.JWT_HEADER_KEY;
import static konkuk.thip.common.security.constant.AuthParameters.JWT_PREFIX;
import static konkuk.thip.common.swagger.SwaggerResponseDescription.CHANGE_FOLLOW_STATE;
import static konkuk.thip.common.swagger.SwaggerResponseDescription.USER_SIGNUP;
import static konkuk.thip.common.swagger.SwaggerResponseDescription.*;

@Tag(name = "User Command API", description = "사용자가 주체가 되는 정보 수정")
@RestController
Expand All @@ -34,6 +32,8 @@ public class UserCommandController {

private final UserSignupUseCase userSignupUseCase;
private final UserFollowUsecase userFollowUsecase;
private final UserUpdateUseCase userUpdateUseCase;

private final JwtUtil jwtUtil;

@Operation(
Expand All @@ -60,9 +60,22 @@ public BaseResponse<UserSignupResponse> signup(@Valid @RequestBody final UserSig
public BaseResponse<UserFollowResponse> followUser(
@Parameter(hidden = true) @UserId final Long userId,
@Parameter(description = "팔로우/언팔로우할 사용자 ID") @PathVariable final Long followingUserId,
@RequestBody @Valid final UserFollowRequest request) {
@RequestBody @Valid final UserFollowRequest userFollowRequest) {
return BaseResponse.ok(UserFollowResponse.of(userFollowUsecase.changeFollowingState(
UserFollowRequest.toCommand(userId, followingUserId, request.type())
userFollowRequest.toCommand(userId, followingUserId)
)));
}

@Operation(
summary = "사용자 정보 수정",
description = "사용자가 자신의 정보를 수정합니다. 닉네임과 칭호(Alias)를 수정할 수 있습니다."
)
@ExceptionDescription(USER_UPDATE)
@PatchMapping("/users")
public BaseResponse<Void> updateUser(
@Parameter(hidden = true) @UserId final Long userId,
@RequestBody @Valid final UserUpdateRequest userUpdateRequest) {
userUpdateUseCase.updateUser(userUpdateRequest.toCommand(userId));
return BaseResponse.ok(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public record UserFollowRequest(
@NotNull(message = "type은 필수 파라미터입니다.")
Boolean type
) {
public static UserFollowCommand toCommand(Long userId, Long targetUserId, Boolean type) {
public UserFollowCommand toCommand(Long userId, Long targetUserId) {
return new UserFollowCommand(userId, targetUserId, type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package konkuk.thip.user.adapter.in.web.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import konkuk.thip.user.application.port.in.dto.UserUpdateCommand;

@Schema(description = "사용자 정보 수정 요청 DTO")
public record UserUpdateRequest(

@Schema(description = "사용자 수정 칭호", example = "문학가")
@NotBlank(message = "칭호는 필수입니다.")
String aliasName,

@Schema(description = "사용자 수정 닉네임", example = "thip")
Comment on lines +7 to +14

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3 : 이렇게 @Schema 어노테이션을 추가하면 스웨거 상에서도 request dto의 description을 확인할 수 있는건가요?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3 : 추가로 nickname 이 10자 이하여야 한다는 것을 request dto 단에서 수행하는 것이 아니라, User 도메인 내부에서 수행하신 이유가 있을까요?? 닉네임이 10자 이하여야 한다 라는 도메인 규칙을 맞추기 위함인가요?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3 : 이렇게 @Schema 어노테이션을 추가하면 스웨거 상에서도 request dto의 description을 확인할 수 있는건가요?

넵 확인 가능합니다!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3 : 추가로 nickname 이 10자 이하여야 한다는 것을 request dto 단에서 수행하는 것이 아니라, User 도메인 내부에서 수행하신 이유가 있을까요?? 닉네임이 10자 이하여야 한다 라는 도메인 규칙을 맞추기 위함인가요?

현재 nickname은 pr 설명에서도 적어놓으셨듯이, null로 오는 경우가 존재해서 그 경우를 핸들링하기 위해 도메인에서 처리해주었습니다!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3 : 이렇게 @Schema 어노테이션을 추가하면 스웨거 상에서도 request dto의 description을 확인할 수 있는건가요?

넵 확인 가능합니다!

오 좋습니다! 저도 적용해보겠습니다!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3 : 추가로 nickname 이 10자 이하여야 한다는 것을 request dto 단에서 수행하는 것이 아니라, User 도메인 내부에서 수행하신 이유가 있을까요?? 닉네임이 10자 이하여야 한다 라는 도메인 규칙을 맞추기 위함인가요?

현재 nickname은 pr 설명에서도 적어놓으셨듯이, null로 오는 경우가 존재해서 그 경우를 핸들링하기 위해 도메인에서 처리해주었습니다!

넵넵 아무래도 도메인 규칙이 맞으니, 도메인 레벨에 검증하는 로직이 있는게 맞는거 같네요.

현재 request 에서 수행하는 bean validation 중 도메인 규칙에 해당하는 친구들은 도메인 레이어로 옮기는 것 또한 리펙토링 포인트로 생각해봐도 좋을 것 같네요! (수정해야하는게 도대체 몇개죠 허허)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅋㅋㅋㅋ좋습니다! 그 부분은 급한건 아니니 일단 미뤄보죠 🥲

String nickname
Comment on lines +14 to +15

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

닉네임 필드 검증 누락

aliasName에는 @notblank 검증이 있지만, nickname 필드에는 검증 어노테이션이 없습니다. 도메인 로직에서 닉네임 길이와 공백을 검증하고 있지만, API 레벨에서도 기본적인 검증을 추가하는 것이 좋겠습니다.

  @Schema(description = "사용자 수정 닉네임", example = "thip")
+ @Size(max = 10, message = "닉네임은 10자 이하여야 합니다.")
  String nickname
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Schema(description = "사용자 수정 닉네임", example = "thip")
String nickname
@Schema(description = "사용자 수정 닉네임", example = "thip")
@Size(max = 10, message = "닉네임은 10자 이하여야 합니다.")
String nickname
🤖 Prompt for AI Agents
In src/main/java/konkuk/thip/user/adapter/in/web/request/UserUpdateRequest.java
at lines 14-15, the nickname field lacks validation annotations unlike
aliasName. Add a @NotBlank annotation to the nickname field to ensure it is not
empty or null at the API level, providing basic validation before domain logic
checks.

) {
public UserUpdateCommand toCommand(Long userId) {
return new UserUpdateCommand(aliasName, nickname, userId);
}
}
16 changes: 14 additions & 2 deletions src/main/java/konkuk/thip/user/adapter/out/jpa/UserJpaEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import konkuk.thip.common.entity.BaseJpaEntity;
import konkuk.thip.user.domain.User;
import lombok.*;
import org.springframework.util.Assert;

import java.time.LocalDate;

@Entity
@Table(name = "users")
Expand All @@ -23,6 +24,9 @@ public class UserJpaEntity extends BaseJpaEntity {
@Column(length = 60, nullable = false)
private String nickname;

@Column(name = "nickname_updated_at", nullable = false)
private LocalDate nicknameUpdatedAt; // 날짜 형식으로 저장 (예: "2023-10-01")

Comment on lines +27 to +29

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요구사항을 구현하려면 이게 있어야 하겠네요. 확인했습니다

@Column(name = "oauth2_id", length = 50, nullable = false)
private String oauth2Id;

Expand All @@ -37,9 +41,17 @@ public class UserJpaEntity extends BaseJpaEntity {
@JoinColumn(name = "user_alias_id", nullable = false)
private AliasJpaEntity aliasForUserJpaEntity;

public void updateIncludeAliasFrom(User user, AliasJpaEntity aliasJpaEntity) {
this.nickname = user.getNickname();
this.nicknameUpdatedAt = user.getNicknameUpdatedAt();
this.role = UserRole.from(user.getUserRole());
this.followerCount = user.getFollowerCount();
this.aliasForUserJpaEntity = aliasJpaEntity;
}

public void updateFrom(User user) {
this.nickname = user.getNickname();
Assert.notNull(user.getAlias(), "Alias must not be null");
this.nicknameUpdatedAt = user.getNicknameUpdatedAt();
this.role = UserRole.from(user.getUserRole());
this.followerCount = user.getFollowerCount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class UserMapper {
public UserJpaEntity toJpaEntity(User user, AliasJpaEntity aliasJpaEntity) {
return UserJpaEntity.builder()
.nickname(user.getNickname())
.nicknameUpdatedAt(user.getNicknameUpdatedAt())
.role(UserRole.from(user.getUserRole()))
.oauth2Id(user.getOauth2Id())
.followerCount(user.getFollowerCount())
Expand All @@ -24,6 +25,7 @@ public User toDomainEntity(UserJpaEntity userJpaEntity) {
return User.builder()
.id(userJpaEntity.getUserId())
.nickname(userJpaEntity.getNickname())
.nicknameUpdatedAt(userJpaEntity.getNicknameUpdatedAt())
.userRole(userJpaEntity.getRole().getType())
.oauth2Id(userJpaEntity.getOauth2Id())
.followerCount(userJpaEntity.getFollowerCount())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,20 @@ public Map<Long, User> findByIds(List<Long> userIds) {
.map(userMapper::toDomainEntity)
.collect(Collectors.toMap(User::getId, Function.identity()));
}

@Override
public void update(User user) {
UserJpaEntity userJpaEntity = userJpaRepository.findById(user.getId()).orElseThrow(
() -> new EntityNotFoundException(USER_NOT_FOUND)
);

aliasJpaRepository.findByValue(user.getAlias().getValue()).ifPresentOrElse(
aliasJpaEntity -> userJpaEntity.updateIncludeAliasFrom(user, aliasJpaEntity),
() -> {
throw new EntityNotFoundException(ALIAS_NOT_FOUND);
}
);

userJpaRepository.save(userJpaEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public boolean existsByNickname(String nickname) {
return userJpaRepository.existsByNickname(nickname);
}

@Override
public boolean existsByNicknameAndUserIdNot(String nickname, Long userId) {
return userJpaRepository.existsByNicknameAndUserIdNot(nickname, userId);
}

@Override
public Set<Long> findUserIdsParticipatedInRoomsByBookId(Long bookId) {
return userJpaRepository.findUserIdsByBookId(bookId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public interface UserJpaRepository extends JpaRepository<UserJpaEntity, Long>, U
Optional<UserJpaEntity> findByOauth2Id(String oauth2Id);
boolean existsByNickname(String nickname);
Optional<UserJpaEntity> findById(Long userId);

boolean existsByNicknameAndUserIdNot(String nickname, Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package konkuk.thip.user.application.port.in;

import konkuk.thip.user.application.port.in.dto.UserUpdateCommand;

public interface UserUpdateUseCase {
void updateUser(UserUpdateCommand command);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package konkuk.thip.user.application.port.in.dto;

public record UserUpdateCommand(
String aliasName,
String nickname,
Long userId
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public interface UserCommandPort {
Long save(User user);
User findById(Long userId);
Map<Long, User> findByIds(List<Long> userIds);
void update(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

public interface UserQueryPort {
boolean existsByNickname(String nickname);

boolean existsByNicknameAndUserIdNot(String nickname, Long userId);

Set<Long> findUserIdsParticipatedInRoomsByBookId(Long bookId);

UserViewAliasChoiceResult getAllAliasesAndCategories();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

import static konkuk.thip.user.adapter.out.jpa.UserRole.USER;


Expand All @@ -23,7 +25,7 @@ public class UserSignupService implements UserSignupUseCase {
public Long signup(UserSignupCommand command) {
Alias alias = Alias.from(command.aliasName());
User user = User.withoutId(
command.nickname(), USER.getType(), command.oauth2Id(), alias
command.nickname(), LocalDate.now(), USER.getType(), command.oauth2Id(), alias
);

return userCommandPort.save(user);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package konkuk.thip.user.application.service;

import konkuk.thip.common.exception.BusinessException;
import konkuk.thip.common.exception.code.ErrorCode;
import konkuk.thip.user.application.port.in.UserUpdateUseCase;
import konkuk.thip.user.application.port.in.dto.UserUpdateCommand;
import konkuk.thip.user.application.port.out.UserCommandPort;
import konkuk.thip.user.application.port.out.UserQueryPort;
import konkuk.thip.user.domain.Alias;
import konkuk.thip.user.domain.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class UserUpdateService implements UserUpdateUseCase {

private final UserCommandPort userCommandPort;
private final UserQueryPort userQueryPort;

@Override
@Transactional
public void updateUser(UserUpdateCommand command) {
Alias alias = Alias.from(command.aliasName());
boolean isNicknameUpdateRequest = command.nickname() != null; // 닉네임이 null이 아니면 닉네임 업데이트 요청

User user = userCommandPort.findById(command.userId());
user.updateUserInfo(command.nickname(), alias, isNicknameUpdateRequest);

if(isNicknameUpdateRequest && userQueryPort.existsByNicknameAndUserIdNot(command.nickname(), command.userId())) {
throw new BusinessException(ErrorCode.USER_NICKNAME_ALREADY_EXISTS);
}
Comment on lines +31 to +33

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

닉네임 중복 검사 순서 개선 필요

닉네임 중복 검사가 도메인 객체 검증 이후에 수행되고 있습니다. 하지만 도메인 검증에서 예외가 발생하면 중복 검사가 실행되지 않습니다. 논리적으로는 중복 검사를 먼저 수행하는 것이 더 효율적입니다.

  User user = userCommandPort.findById(command.userId());
+ 
+ if(isNicknameUpdateRequest && userQueryPort.existsByNicknameAndUserIdNot(command.nickname(), command.userId())) {
+     throw new BusinessException(ErrorCode.USER_NICKNAME_ALREADY_EXISTS);
+ }
+ 
  user.updateUserInfo(command.nickname(), alias, isNicknameUpdateRequest);

- if(isNicknameUpdateRequest && userQueryPort.existsByNicknameAndUserIdNot(command.nickname(), command.userId())) {
-     throw new BusinessException(ErrorCode.USER_NICKNAME_ALREADY_EXISTS);
- }
🤖 Prompt for AI Agents
In src/main/java/konkuk/thip/user/application/service/UserUpdateService.java
around lines 31 to 33, the nickname duplication check is currently performed
after domain object validation, which can skip the duplication check if domain
validation fails. To fix this, reorder the logic to perform the nickname
duplication check before any domain validation to ensure it always runs first
and improves efficiency.

userCommandPort.update(user);
}
}
32 changes: 31 additions & 1 deletion src/main/java/konkuk/thip/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import lombok.Getter;
import lombok.experimental.SuperBuilder;

import java.time.LocalDate;

@Getter
@SuperBuilder
public class User extends BaseDomainEntity {
Expand All @@ -14,6 +16,8 @@ public class User extends BaseDomainEntity {

private String nickname;

private LocalDate nicknameUpdatedAt;

private String userRole;

private String oauth2Id;
Expand All @@ -22,10 +26,11 @@ public class User extends BaseDomainEntity {

private Alias alias;

public static User withoutId(String nickname, String userRole, String oauth2Id, Alias alias) {
public static User withoutId(String nickname, LocalDate nicknameUpdatedAt, String userRole, String oauth2Id, Alias alias) {
return User.builder()
.id(null)
.nickname(nickname)
.nicknameUpdatedAt(nicknameUpdatedAt)
.userRole(userRole)
.oauth2Id(oauth2Id)
.followerCount(0)
Expand All @@ -44,4 +49,29 @@ public void decreaseFollowerCount() {
followerCount--;
}

public void updateUserInfo(String nickname, Alias alias, boolean isNicknameUpdateRequest) {
if(isNicknameUpdateRequest) {
validateCanUpdateNickname(nickname);
this.nickname = nickname;
this.nicknameUpdatedAt = LocalDate.now();
}
this.alias = alias;
}

private void validateCanUpdateNickname(String nickname) {
if(nickname.isBlank()) { // 빈칸 불가
throw new InvalidStateException(ErrorCode.USER_NICKNAME_CANNOT_BE_BLANK);
}
if(nickname.length() > 10) { // 10자 이상 불가
throw new InvalidStateException(ErrorCode.USER_NICKNAME_TOO_LONG);
}
// 닉네임을 변경한지 6개월이 지나지 않았으면 닉네임 업데이트 불가
if(nicknameUpdatedAt != null && nicknameUpdatedAt.isAfter(LocalDate.now().minusMonths(6))) {
throw new InvalidStateException(ErrorCode.USER_NICKNAME_UPDATE_TOO_FREQUENT);
}
if(nickname.equals(this.nickname)) { // 현재 닉네임과 같으면 업데이트 불가
throw new InvalidStateException(ErrorCode.USER_NICKNAME_CANNOT_BE_SAME);
}
}
Comment on lines +61 to +75

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

닉네임 검증 로직에서 null 체크를 강화해주세요.

현재 nicknameUpdatedAt가 null인 경우에 대한 처리가 있지만, 새로 생성되는 사용자의 경우를 더 명확하게 처리하는 것이 좋겠습니다.

다음과 같이 수정을 고려해보세요:

private void validateCanUpdateNickname(String nickname) {
    if(nickname.isBlank()) {
        throw new InvalidStateException(ErrorCode.USER_NICKNAME_CANNOT_BE_BLANK);
    }
    if(nickname.length() > 10) {
        throw new InvalidStateException(ErrorCode.USER_NICKNAME_TOO_LONG);
    }
    if(nickname.equals(this.nickname)) {
        throw new InvalidStateException(ErrorCode.USER_NICKNAME_CANNOT_BE_SAME);
    }
    // 닉네임을 변경한지 6개월이 지나지 않았으면 닉네임 업데이트 불가
    // null인 경우는 최초 생성 시점이므로 업데이트 허용
    if(nicknameUpdatedAt != null && nicknameUpdatedAt.isAfter(LocalDate.now().minusMonths(6))) {
        throw new InvalidStateException(ERROR.USER_NICKNAME_UPDATE_TOO_FREQUENT);
    }
}

또한 검증 순서를 재고려해보세요. 같은 닉네임 체크를 더 빠른 시점에 하는 것이 효율적일 수 있습니다.

🤖 Prompt for AI Agents
In src/main/java/konkuk/thip/user/domain/User.java around lines 61 to 75,
improve the nickname validation by moving the check for the nickname being the
same as the current one before the nicknameUpdatedAt check, and ensure the null
check for nicknameUpdatedAt remains after that. This change clarifies that if
nicknameUpdatedAt is null (new user), the update is allowed, and avoids
unnecessary date checks when the nickname hasn't changed. Adjust the order of
validations accordingly to enhance efficiency and clarity.

Comment on lines +61 to +75

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import konkuk.thip.user.adapter.out.jpa.AliasJpaEntity;
import konkuk.thip.user.adapter.out.jpa.UserJpaEntity;
import konkuk.thip.user.adapter.out.jpa.UserRole;
import konkuk.thip.user.adapter.out.persistence.repository.alias.AliasJpaRepository;
import konkuk.thip.user.adapter.out.persistence.repository.UserJpaRepository;
import konkuk.thip.user.adapter.out.persistence.repository.alias.AliasJpaRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -26,6 +26,7 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;

import java.time.LocalDate;
import java.util.Optional;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
Expand Down Expand Up @@ -72,6 +73,7 @@ void setUp() {
UserJpaEntity user = userJpaRepository.save(UserJpaEntity.builder()
.oauth2Id("kakao_432708231")
.nickname("User1")
.nicknameUpdatedAt(LocalDate.now().minusMonths(7))
.role(UserRole.USER)
.aliasForUserJpaEntity(alias)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void setup() {
UserJpaEntity user = userJpaRepository.save(UserJpaEntity.builder()
.oauth2Id("kakao_432708231")
.nickname("User1")
.nicknameUpdatedAt(LocalDate.now().minusMonths(7))
.role(UserRole.USER)
.aliasForUserJpaEntity(alias)
.build());
Expand Down
Loading