Skip to content

Commit

Permalink
Merge pull request #86 from sh1220/dev
Browse files Browse the repository at this point in the history
feat: User Exception add
  • Loading branch information
sh1220 authored Aug 13, 2024
2 parents 052b2a4 + 1fd13a5 commit 9bf5100
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public enum BaseExceptionResponseStatus implements ResponseStatus {
INVALID_PROFILE_IMG(5012,HttpStatus.BAD_REQUEST.value(), "잘못된 이미지 파일입니다."),
UPLOAD_FAIL(5013,HttpStatus.BAD_REQUEST.value(), "파일 업로드에 실패했습니다. 인터넷 연결을 확인하거나, 나중에 다시 시도해 주세요."),
INVALID_USER_DB_VALUE(5014,HttpStatus.BAD_REQUEST.value(), "유저 정보에 오류가 발생했습니다. 관리자에게 문의해주세요."),
NULL_USER_VALUE(5015,HttpStatus.BAD_REQUEST.value(), "요청에 필요한 값이 존재하지 않습니다."),
EMPTY_USER_VALUE(5016,HttpStatus.BAD_REQUEST.value(), "요청에 필요한 값이 비어있습니다.."),

/**
* 6000: Debate 오류
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public String saveDebateImg(MultipartFile uploadFile){

// 프로필 이미지 업로드
public String saveProfileImg(MultipartFile uploadFile) {
validateIsNull(uploadFile);
validateIsEmpty(uploadFile);
// img url 반환
return saveImg(uploadFile, PROFILE_IMG_DIR);
}
Expand Down Expand Up @@ -111,4 +113,15 @@ private String extractFileNameFromUrl(String fileNameOrUrl) {
}
}

public void validateIsNull(Object value){
if (value == null) {
throw new UserException(NULL_USER_VALUE);
}
}
public void validateIsEmpty(MultipartFile value) {
if (value.isEmpty()) {
throw new UserException(EMPTY_USER_VALUE);
}
}

}
20 changes: 20 additions & 0 deletions src/main/java/store/itpick/backend/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import store.itpick.backend.common.exception.UserException;
import store.itpick.backend.dto.auth.JwtDTO;
import store.itpick.backend.jwt.JwtProvider;
import store.itpick.backend.model.LikedTopic;
Expand All @@ -16,6 +17,8 @@
import java.util.*;
import java.util.stream.Collectors;

import static store.itpick.backend.common.response.status.BaseExceptionResponseStatus.EMPTY_USER_VALUE;
import static store.itpick.backend.common.response.status.BaseExceptionResponseStatus.NULL_USER_VALUE;
import static store.itpick.backend.util.UserUtils.getUser;

@Slf4j
Expand All @@ -30,6 +33,7 @@ public class UserService {


public void changeNickname(long userId, String nickname) {
validateIsNull(userId);
User user = getUser(userId, userRepository);
user.setNickname(nickname);
user.setUpdateAt(new Timestamp(System.currentTimeMillis()));
Expand All @@ -47,6 +51,10 @@ public void changeBirthDate(long userId, String birth_date) {
public void changeLikedTopics(long userId, List<String> likedTopicList) {
User user = getUser(userId, userRepository);

validateIsNull(likedTopicList);
validateIsEmpty(likedTopicList);


// 기존 LikedTopic 목록을 맵으로 변환
Map<String, LikedTopic> existingLikedTopicsMap = user.getLikedTopics()
.stream()
Expand Down Expand Up @@ -100,6 +108,7 @@ public JwtDTO changeEmail(long userId, String email, String accessToken, String
}

public void changePassword(long userId, String password) {
validateIsNull(password);
User user = getUser(userId, userRepository);
// Encrypt password
user.setPassword(passwordEncoder.encode(password));
Expand All @@ -122,4 +131,15 @@ public String getProfileImgUrl(long userId) {
User user = getUser(userId, userRepository);
return user.getImageUrl();
}

public void validateIsNull(Object value){
if (value == null) {
throw new UserException(NULL_USER_VALUE);
}
}
public void validateIsEmpty(List<String> value) {
if (value.isEmpty()) {
throw new UserException(EMPTY_USER_VALUE);
}
}
}

0 comments on commit 9bf5100

Please sign in to comment.