Skip to content

Commit

Permalink
feat: 프로필 수정 비즈니스 로직 구현 (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckkim817 committed Feb 17, 2025
1 parent 2fb8c6f commit ad54d13
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public enum ErrorType {
ALREADY_VERIFIED_AREA_ERROR(HttpStatus.BAD_REQUEST, 40032, "이미 인증된 동네가 존재합니다."),
INVALID_IMAGE_TYPE_ERROR(HttpStatus.BAD_REQUEST, 40045, "유효하지 않은 imageType입니다."),
INVALID_NICKNAME_ERROR(HttpStatus.BAD_REQUEST, 40051, "닉네임이 조건을 만족하지 않습니다."),
INVALID_BIRTH_DATE_ERROR(HttpStatus.BAD_REQUEST, 40053, "유효하지 않은 생년월일입니다."),

/* 409 Conflict */
DUPLICATED_NICKNAME_ERROR(HttpStatus.CONFLICT, 40901, "이미 사용 중인 닉네임입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
import com.acon.server.spot.infra.repository.SpotRepository;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.format.ResolverStyle;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -315,6 +318,54 @@ private void validateNicknameDuplication(String nickname) {
}
}

@Transactional
public void updateProfile(String profileImage, String nickname, String birthDate
) {
MemberEntity memberEntity = memberRepository.findByIdOrElseThrow(principalHandler.getUserIdFromPrincipal());
Member member = memberMapper.toDomain(memberEntity);

if (profileImage != null) {
if (profileImage.isEmpty()) {
String basicProfileImageUrl = s3Adapter.getBasicProfileImageUrl();
member.setProfileImage(basicProfileImageUrl);
} else {
String fileName = s3Adapter.getFileName(profileImage);
s3Adapter.validateImageExists(fileName);
String imageUrl = s3Adapter.getImageUrl(fileName);
member.setProfileImage(imageUrl);
}
}

if (nickname != null) {
validateNickname(nickname);
member.setNickname(nickname);
}

if (birthDate != null) {
LocalDate parsedBirthDate = validateAndParseBirthDate(birthDate);
member.setBirthDate(parsedBirthDate);
}

memberRepository.save(memberMapper.toEntity(member));
}

private LocalDate validateAndParseBirthDate(String birthDate) {
try {
LocalDate parsedDate = LocalDate.parse(
birthDate,
DateTimeFormatter.ofPattern("yyyy.MM.dd").withResolverStyle(ResolverStyle.STRICT)
);

if (parsedDate.isAfter(LocalDate.now())) {
throw new BusinessException(ErrorType.INVALID_BIRTH_DATE_ERROR);
}

return parsedDate;
} catch (DateTimeParseException e) {
throw new BusinessException(ErrorType.INVALID_BIRTH_DATE_ERROR);
}
}

@Transactional
public void logout(String refreshToken) {
MemberEntity memberEntity = memberRepository.findByIdOrElseThrow(principalHandler.getUserIdFromPrincipal());
Expand Down

0 comments on commit ad54d13

Please sign in to comment.