diff --git a/build/classes/java/main/com/sunjoo/auth/domain/User.class b/build/classes/java/main/com/sunjoo/auth/domain/User.class index f23fb9b..9dd6f22 100644 Binary files a/build/classes/java/main/com/sunjoo/auth/domain/User.class and b/build/classes/java/main/com/sunjoo/auth/domain/User.class differ diff --git a/build/classes/java/main/com/sunjoo/auth/domain/controller/UserController.class b/build/classes/java/main/com/sunjoo/auth/domain/controller/UserController.class index 84fce54..472a28a 100644 Binary files a/build/classes/java/main/com/sunjoo/auth/domain/controller/UserController.class and b/build/classes/java/main/com/sunjoo/auth/domain/controller/UserController.class differ diff --git a/build/classes/java/main/com/sunjoo/auth/domain/security/JwtAuthenticationProcessingFilter.class b/build/classes/java/main/com/sunjoo/auth/domain/security/JwtAuthenticationProcessingFilter.class index 4b0772f..0fc53e9 100644 Binary files a/build/classes/java/main/com/sunjoo/auth/domain/security/JwtAuthenticationProcessingFilter.class and b/build/classes/java/main/com/sunjoo/auth/domain/security/JwtAuthenticationProcessingFilter.class differ diff --git a/build/classes/java/main/com/sunjoo/auth/domain/security/UserDetailsImpl.class b/build/classes/java/main/com/sunjoo/auth/domain/security/UserDetailsImpl.class index ebefb04..6d50a8b 100644 Binary files a/build/classes/java/main/com/sunjoo/auth/domain/security/UserDetailsImpl.class and b/build/classes/java/main/com/sunjoo/auth/domain/security/UserDetailsImpl.class differ diff --git a/build/classes/java/main/com/sunjoo/auth/domain/service/UserService.class b/build/classes/java/main/com/sunjoo/auth/domain/service/UserService.class index 4635cf0..7237ad7 100644 Binary files a/build/classes/java/main/com/sunjoo/auth/domain/service/UserService.class and b/build/classes/java/main/com/sunjoo/auth/domain/service/UserService.class differ diff --git a/build/classes/java/main/com/sunjoo/auth/domain/service/UserServiceImpl.class b/build/classes/java/main/com/sunjoo/auth/domain/service/UserServiceImpl.class index df82846..ed45f8c 100644 Binary files a/build/classes/java/main/com/sunjoo/auth/domain/service/UserServiceImpl.class and b/build/classes/java/main/com/sunjoo/auth/domain/service/UserServiceImpl.class differ diff --git a/build/classes/java/main/com/sunjoo/auth/global/exception/ErrorCode.class b/build/classes/java/main/com/sunjoo/auth/global/exception/ErrorCode.class index 9b1151b..b705b66 100644 Binary files a/build/classes/java/main/com/sunjoo/auth/global/exception/ErrorCode.class and b/build/classes/java/main/com/sunjoo/auth/global/exception/ErrorCode.class differ diff --git a/build/resources/main/application.yml b/build/resources/main/application.yml index 1882def..8959960 100644 --- a/build/resources/main/application.yml +++ b/build/resources/main/application.yml @@ -35,4 +35,4 @@ eureka: register-with-eureka: true fetch-registry: true service-url: - defaultZone: http://localhost:8761/ \ No newline at end of file + defaultZone: http://sunjoo-server-eureka-eureka-1:8761/eureka/ \ No newline at end of file diff --git a/src/main/java/com/sunjoo/auth/domain/User.java b/src/main/java/com/sunjoo/auth/domain/User.java index 4981939..2d02156 100644 --- a/src/main/java/com/sunjoo/auth/domain/User.java +++ b/src/main/java/com/sunjoo/auth/domain/User.java @@ -7,7 +7,7 @@ import java.time.LocalDate; @Entity -@Getter +@Getter @Setter @Builder @AllArgsConstructor @Table(name="user") diff --git a/src/main/java/com/sunjoo/auth/domain/controller/UserController.java b/src/main/java/com/sunjoo/auth/domain/controller/UserController.java index cf077e2..3fb8439 100644 --- a/src/main/java/com/sunjoo/auth/domain/controller/UserController.java +++ b/src/main/java/com/sunjoo/auth/domain/controller/UserController.java @@ -1,9 +1,7 @@ package com.sunjoo.auth.domain.controller; -import com.sunjoo.auth.domain.dto.KakaoLoginRequestDto; -import com.sunjoo.auth.domain.dto.KakaoLoginResponseDto; -import com.sunjoo.auth.domain.dto.UserRegisterRequestDto; -import com.sunjoo.auth.domain.dto.UserRegisterResponseDto; +import com.sunjoo.auth.domain.dto.*; +import com.sunjoo.auth.domain.security.UserDetailsImpl; import com.sunjoo.auth.domain.service.JwtService; import com.sunjoo.auth.domain.service.RedisService; import com.sunjoo.auth.domain.service.UserService; @@ -13,10 +11,12 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.security.Principal; import java.sql.SQLException; import java.util.HashMap; @@ -57,4 +57,17 @@ public ResponseEntity kakaoLogin(@RequestParam(required = false) String token, H return ResponseEntity.internalServerError().build(); } } -} \ No newline at end of file + + @GetMapping("/userinfo") + public ResponseEntity getUserInfo(@AuthenticationPrincipal UserDetailsImpl userDetails) { + log.info("정보 조회 요청 회원 번호 : " + userDetails.getUserNo()); + UserInfoResponseDto userInfoResponseDto = userService.getUserInfo(userDetails.getUserNo()); + return ResponseEntity.ok(Response.success(userInfoResponseDto)); + } + + @PutMapping("/nickname") + public ResponseEntity updateUserNickname(@AuthenticationPrincipal UserDetailsImpl userDetails, @RequestBody NickNameRequestDto requestDto) { + NickNameResponseDto nickNameResponseDto = userService.updateNickName(userDetails.getUserNo(), requestDto.getNewNickName()); + return ResponseEntity.ok(Response.success(nickNameResponseDto)); + } +}; \ No newline at end of file diff --git a/src/main/java/com/sunjoo/auth/domain/dto/NickNameRequestDto.java b/src/main/java/com/sunjoo/auth/domain/dto/NickNameRequestDto.java new file mode 100644 index 0000000..a74ad3b --- /dev/null +++ b/src/main/java/com/sunjoo/auth/domain/dto/NickNameRequestDto.java @@ -0,0 +1,13 @@ +package com.sunjoo.auth.domain.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter @Setter +@AllArgsConstructor +@NoArgsConstructor +public class NickNameRequestDto { + String newNickName; +} diff --git a/src/main/java/com/sunjoo/auth/domain/dto/NickNameResponseDto.java b/src/main/java/com/sunjoo/auth/domain/dto/NickNameResponseDto.java new file mode 100644 index 0000000..ac189fa --- /dev/null +++ b/src/main/java/com/sunjoo/auth/domain/dto/NickNameResponseDto.java @@ -0,0 +1,22 @@ +package com.sunjoo.auth.domain.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter @Setter +@AllArgsConstructor +@NoArgsConstructor +public class NickNameResponseDto { + long userNo; + String id; + String nickname; // 닉네임 + String type; + + public NickNameResponseDto(long userNo, String nickname, String type) { + this.userNo = userNo; + this.nickname = nickname; + this.type = type; + } +} diff --git a/src/main/java/com/sunjoo/auth/domain/dto/UserInfoResponseDto.java b/src/main/java/com/sunjoo/auth/domain/dto/UserInfoResponseDto.java new file mode 100644 index 0000000..ab11cc8 --- /dev/null +++ b/src/main/java/com/sunjoo/auth/domain/dto/UserInfoResponseDto.java @@ -0,0 +1,19 @@ +package com.sunjoo.auth.domain.dto; + +import lombok.*; + +@Getter @Setter +@AllArgsConstructor +@NoArgsConstructor +public class UserInfoResponseDto { + long userNo; + String id; + String name; + String type; + + public UserInfoResponseDto(long userNo, String name, String type) { + this.userNo = userNo; + this.name = name; + this.type = type; + } +} diff --git a/src/main/java/com/sunjoo/auth/domain/security/JwtAuthenticationProcessingFilter.java b/src/main/java/com/sunjoo/auth/domain/security/JwtAuthenticationProcessingFilter.java index 08e3cb4..d569e5f 100644 --- a/src/main/java/com/sunjoo/auth/domain/security/JwtAuthenticationProcessingFilter.java +++ b/src/main/java/com/sunjoo/auth/domain/security/JwtAuthenticationProcessingFilter.java @@ -71,7 +71,7 @@ private void checkRefreshTokenAndReIssueAccessToken(HttpServletResponse response private void checkAcceessTokenAndAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { jwtService.extractAccessToken(request).filter(jwtService::isTokenValid).ifPresent( accessToken -> jwtService.extractUserNo(accessToken).ifPresent( - id -> userRepository.findById(id).ifPresent( + userNo -> userRepository.findByUserNo(userNo).ifPresent( user -> saveAuthentication(user) ) ) diff --git a/src/main/java/com/sunjoo/auth/domain/security/UserDetailsImpl.java b/src/main/java/com/sunjoo/auth/domain/security/UserDetailsImpl.java index e2d6864..4f55744 100644 --- a/src/main/java/com/sunjoo/auth/domain/security/UserDetailsImpl.java +++ b/src/main/java/com/sunjoo/auth/domain/security/UserDetailsImpl.java @@ -27,7 +27,7 @@ public String getPassword() { } @Override - public String getUsername() { - return user.getId(); - } + public String getUsername() { return user.getId(); } + + public long getUserNo() {return user.getUserNo();} } diff --git a/src/main/java/com/sunjoo/auth/domain/service/UserService.java b/src/main/java/com/sunjoo/auth/domain/service/UserService.java index ae69d04..f274f03 100644 --- a/src/main/java/com/sunjoo/auth/domain/service/UserService.java +++ b/src/main/java/com/sunjoo/auth/domain/service/UserService.java @@ -1,9 +1,6 @@ package com.sunjoo.auth.domain.service; -import com.sunjoo.auth.domain.dto.KakaoLoginRequestDto; -import com.sunjoo.auth.domain.dto.KakaoLoginResponseDto; -import com.sunjoo.auth.domain.dto.UserRegisterRequestDto; -import com.sunjoo.auth.domain.dto.UserRegisterResponseDto; +import com.sunjoo.auth.domain.dto.*; import java.util.HashMap; @@ -11,4 +8,6 @@ public interface UserService { public UserRegisterResponseDto register(UserRegisterRequestDto registerRequestDto); public KakaoLoginRequestDto getKakaoUserInfo(String accessToken); public KakaoLoginResponseDto kakaoLogin(KakaoLoginRequestDto kakaoRequest); + public UserInfoResponseDto getUserInfo(long userNo); + public NickNameResponseDto updateNickName(long userNo, String nickName); } diff --git a/src/main/java/com/sunjoo/auth/domain/service/UserServiceImpl.java b/src/main/java/com/sunjoo/auth/domain/service/UserServiceImpl.java index 1f65ac6..430f1f4 100644 --- a/src/main/java/com/sunjoo/auth/domain/service/UserServiceImpl.java +++ b/src/main/java/com/sunjoo/auth/domain/service/UserServiceImpl.java @@ -5,26 +5,19 @@ import com.nimbusds.jose.shaded.gson.JsonParser; import com.sunjoo.auth.domain.User; import com.sunjoo.auth.domain.UserRepository; -import com.sunjoo.auth.domain.dto.KakaoLoginRequestDto; -import com.sunjoo.auth.domain.dto.KakaoLoginResponseDto; -import com.sunjoo.auth.domain.dto.UserRegisterRequestDto; -import com.sunjoo.auth.domain.dto.UserRegisterResponseDto; +import com.sunjoo.auth.domain.dto.*; import com.sunjoo.auth.global.exception.AppException; import com.sunjoo.auth.global.exception.ErrorCode; +import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import java.io.BufferedReader; -import java.io.BufferedWriter; import java.io.InputStreamReader; -import java.io.OutputStreamWriter; import java.net.HttpURLConnection; -import java.net.MalformedURLException; import java.net.URL; import java.time.LocalDate; -import java.util.HashMap; -import java.util.Optional; @RequiredArgsConstructor @Service @@ -109,6 +102,39 @@ public KakaoLoginResponseDto kakaoLogin(KakaoLoginRequestDto kakaoRequest) { return kakaoResponse; } + @Override + public UserInfoResponseDto getUserInfo(long userNo) { + UserInfoResponseDto userInfoResponseDto = new UserInfoResponseDto(); + userRepository.findByUserNo(userNo).ifPresentOrElse( + user->{ + if(user.getType().equals("DEFAULT")) userInfoResponseDto.setId(user.getId()); + userInfoResponseDto.setUserNo(user.getUserNo()); + userInfoResponseDto.setName(user.getName()); + userInfoResponseDto.setType(user.getType()); + }, () -> {throw new AppException(ErrorCode.USER_NOT_FOUND);} + ); + return userInfoResponseDto; + } + + @Transactional + @Override + public NickNameResponseDto updateNickName(long userNo, String nickName) { + NickNameResponseDto nickNameResponseDto = new NickNameResponseDto(); + User user = userRepository.findByUserNo(userNo).orElseThrow(() -> { + throw new AppException(ErrorCode.USER_NOT_FOUND); + }); + + user.setName(nickName); + nickNameResponseDto.setNickname(user.getName()); + nickNameResponseDto.setUserNo(user.getUserNo()); + nickNameResponseDto.setType(user.getType()); + + if(user.getType().equals("DEFAULT")) { + nickNameResponseDto.setId(user.getId()); + } + return nickNameResponseDto; + } + private void userJoinValid(String id) { userRepository.findById(id) .ifPresent(user -> {throw new AppException(ErrorCode.DUPLICATED_USER_ID);}); diff --git a/src/main/java/com/sunjoo/auth/global/exception/ErrorCode.java b/src/main/java/com/sunjoo/auth/global/exception/ErrorCode.java index 0a096ff..eb48b9d 100644 --- a/src/main/java/com/sunjoo/auth/global/exception/ErrorCode.java +++ b/src/main/java/com/sunjoo/auth/global/exception/ErrorCode.java @@ -8,6 +8,7 @@ @Getter public enum ErrorCode { DUPLICATED_USER_ID(HttpStatus.CONFLICT, "아이디가 중복됩니다."), + USER_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 유저 정보를 찾을 수 없습니다."), DATABASE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "DB 에러"); private HttpStatus httpStatus;