Skip to content

Commit

Permalink
chore: UserInfo 응답 데이터 변경
Browse files Browse the repository at this point in the history
기존 문자열 응답이 아닌 UserInfo DTO 객체에 담겨 반환
  • Loading branch information
zzdh8 committed Jun 28, 2024
1 parent c3d363c commit bfc9593
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.skhuton.skhudebug.member.dto.response.UserInfo;
import org.skhuton.skhudebug.member.service.UserService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -23,9 +24,8 @@ public class UserController {
*/
@Operation(summary = "로그인 확인", description = "해당 클라이언트의 로그인 확인")
@GetMapping("/user/confirm")
public ResponseEntity<String> confirm(HttpServletRequest request){
String loginId = String.valueOf(userService.loginConfirmUserID(request));
return new ResponseEntity<>(loginId, HttpStatus.OK);
public ResponseEntity<UserInfo> confirm(HttpServletRequest request){
return new ResponseEntity<>(userService.loginConfirmUserID(request), HttpStatus.OK);
}

@GetMapping("/test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.skhuton.skhudebug.member.dto.JoinRequestDto;
import org.skhuton.skhudebug.member.dto.request.JoinRequestDto;
import org.skhuton.skhudebug.member.service.UserJoinService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down

This file was deleted.

18 changes: 0 additions & 18 deletions src/main/java/org/skhuton/skhudebug/member/dto/JoinRequestDto.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.skhuton.skhudebug.member.dto.request;

public record JoinRequestDto(

String loginId,

String password,

String nickname
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.skhuton.skhudebug.member.dto.response;

import lombok.Builder;

@Builder
public record UserInfo(
String loginId,
String nickname
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import org.skhuton.skhudebug.member.domain.Role;
import org.skhuton.skhudebug.member.domain.User;
import org.skhuton.skhudebug.member.dto.JoinRequestDto;
import org.skhuton.skhudebug.member.dto.request.JoinRequestDto;
import org.skhuton.skhudebug.member.execption.InvalidUserException;
import org.skhuton.skhudebug.member.repository.UserRepository;
import org.springframework.security.crypto.password.PasswordEncoder;
Expand All @@ -26,12 +26,12 @@ public UserJoinService(PasswordEncoder passwordEncoder, UserRepository userRepos
@Transactional
public void join(JoinRequestDto joinRequestDto) {
// 비밀번호를 암호화
String encodedPassword = passwordEncoder.encode(joinRequestDto.getPassword());
validateDuplicateLoginId(joinRequestDto.getLoginId());
String encodedPassword = passwordEncoder.encode(joinRequestDto.password());
validateDuplicateLoginId(joinRequestDto.loginId());
User user = User.builder()
.loginId(joinRequestDto.getLoginId())
.loginId(joinRequestDto.loginId())
.password(encodedPassword)
.nickname(joinRequestDto.getNickname())
.nickname(joinRequestDto.nickname())
.role(Role.ROLE_USER)
.build();
// 회원 정보 저장
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.RequiredArgsConstructor;
import org.skhuton.skhudebug.member.domain.PrincipalDetail;
import org.skhuton.skhudebug.member.domain.User;
import org.skhuton.skhudebug.member.dto.response.UserInfo;
import org.skhuton.skhudebug.member.execption.InvalidUserException;
import org.skhuton.skhudebug.member.repository.UserRepository;
import org.springframework.security.core.userdetails.UserDetails;
Expand All @@ -29,13 +30,15 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx
}

//로그인 상태 확인 메서드
//로그인 상태면 로그인한 유저아이디를 반환하고, 로그인 상태 확인 결과을 반환.

public String loginConfirmUserID(HttpServletRequest request) throws InvalidUserException {
//로그인 상태면 로그인한 유저아이디와 닉네임을 반환하고, 로그인 상태 확인 결과을 반환.
public UserInfo loginConfirmUserID(HttpServletRequest request) throws InvalidUserException {
Principal user = request.getUserPrincipal();
if (user != null) {
User loginUser = userRepository.findByLoginId(user.getName()).orElseThrow(() -> new InvalidUserException("로그인 상태가 아닙니다."));
return loginUser.getLoginId();
return UserInfo.builder()
.loginId(loginUser.getLoginId())
.nickname(loginUser.getNickname())
.build();
}
throw new InvalidUserException("not login");
}
Expand Down

0 comments on commit bfc9593

Please sign in to comment.