Skip to content

Commit

Permalink
HOTFIX: 커스텀 id 중복 체크 및 커스텀 id로 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
hyxklee committed Nov 13, 2024
1 parent 8e62134 commit 51ccb0f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public ResponseDto<String> initUserProfile(@RequestBody @Valid UserInitializeReq
return ResponseDto.response(INIT_PROFILE_SUCCESS.getCode(), INIT_PROFILE_SUCCESS.getMessage());
}

@GetMapping("/profile/{userId}")
@GetMapping("/profile/{customId}")
@Operation(summary = "유저 기본 프로필 조회")
public ResponseDto<UserProfileResponse> getUserProfile(@PathVariable Long userId, @AuthenticationPrincipal @Parameter(hidden = true) String email) {
return ResponseDto.response(GET_PROFILE_SUCCESS.getCode(), GET_PROFILE_SUCCESS.getMessage(), userService.getProfile(userId, email));
public ResponseDto<UserProfileResponse> getUserProfile(@PathVariable String customId, @AuthenticationPrincipal @Parameter(hidden = true) String email) {
return ResponseDto.response(GET_PROFILE_SUCCESS.getCode(), GET_PROFILE_SUCCESS.getMessage(), userService.getProfile(customId, email));
}

@PatchMapping(value="/profile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.leets.X.domain.user.exception;

import com.leets.X.global.common.exception.BaseException;

import static com.leets.X.domain.user.exception.ErrorMessage.*;

public class DuplicateCustomIdException extends BaseException {
public DuplicateCustomIdException() {
super(DUPLICATE_CUSTOMID.getCode(), DUPLICATE_CUSTOMID.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public enum ErrorMessage {

USER_NOT_FOUND(404,"존재하지 않는 유저입니다."),
USER1_NOT_FOUND(404, "유저1은 존재하지 않습니다."),
USER2_NOT_FOUND(404, "유저2는 존재하지 않습니다.");
USER2_NOT_FOUND(404, "유저2는 존재하지 않습니다."),
DUPLICATE_CUSTOMID(400, "중복된 CustomId입니다.");

// 송우석 추가 내용

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
public interface UserRepository extends JpaRepository<User, Long> {
Boolean existsByEmail(String email);

boolean existsByCustomId(String customId);

Optional<User> findByEmail(String email);

Optional<User> findByCustomId(String customId);

}
13 changes: 10 additions & 3 deletions src/main/java/com/leets/X/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.leets.X.domain.user.dto.request.UserUpdateRequest;
import com.leets.X.domain.user.dto.response.UserProfileResponse;
import com.leets.X.domain.user.dto.response.UserSocialLoginResponse;
import com.leets.X.domain.user.exception.DuplicateCustomIdException;
import com.leets.X.domain.user.exception.UserNotFoundException;
import com.leets.X.domain.user.repository.UserRepository;
import com.leets.X.global.auth.google.AuthService;
Expand Down Expand Up @@ -62,7 +63,7 @@ public UserSocialLoginResponse authenticate(String authCode) {
@Transactional
public void initProfile(UserInitializeRequest dto, String email){
User user = find(email);

valid(dto.customId());
user.initProfile(dto);
}

Expand All @@ -84,8 +85,8 @@ public void updateProfile(UserUpdateRequest dto, MultipartFile image, String ema
user.update(dto, savedImage);
}

public UserProfileResponse getProfile(Long userId, String email){
User user = userRepository.findById(userId)
public UserProfileResponse getProfile(String customId, String email){
User user = userRepository.findByCustomId(customId)
.orElseThrow(UserNotFoundException::new);
boolean isMyProfile = user.getEmail().equals(email);
boolean isFollowing = checkFollowing(user, email);
Expand Down Expand Up @@ -138,6 +139,12 @@ private ImageDto getImage(User user){
return null;
}

private void valid(String customId) {
if(userRepository.existsByCustomId(customId)) {
throw new DuplicateCustomIdException();
}
}

/*
* userRepository에서 사용자를 검색하는 메서드
* 공통으로 사용되는 부분이 많기 때문에 별도로 분리
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public CorsConfigurationSource corsConfigurationSource() {

configuration.addAllowedOriginPattern("http://localhost:3000");
configuration.addAllowedOriginPattern("https://43.203.226.98.nip.io");
configuration.addAllowedOriginPattern("https://main.dr9bfn52wjqx9.amplifyapp.com");
configuration.addAllowedOriginPattern("http://127.0.0.1:5500"); // HTML Live Server CORS 설정
configuration.addAllowedMethod("*");
configuration.addAllowedHeader("*");
Expand Down

0 comments on commit 51ccb0f

Please sign in to comment.