We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package com.fs.filemarket.api.domain.user.service; import com.fs.filemarket.api.domain.user.User; import com.fs.filemarket.api.domain.user.repository.UserRepository; import jakarta.servlet.http.HttpServletRequest; import org.springframework.http.HttpStatus; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; @Service public class UserDebugService extends UserService{ private final HttpServletRequest request; public UserDebugService(UserRepository userRepository, PasswordEncoder passwordEncoder, HttpServletRequest request) { super(userRepository, passwordEncoder); this.request = request; } private Integer getUserIdInHeader() { String userIdString = request.getHeader("userId"); if (userIdString == null) throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Unauthorized"); try { return Integer.parseInt(userIdString); } catch (NumberFormatException e) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "userID를 파싱할 수 없습니다."); } } @Override public User getCurrentUser() { return userRepository.getById(getUserIdInHeader()); } }
이렇게 하면, PostMan에서 Hedars에 userId 값을 통해 현재 유저 설정이 가능합니다.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
해당 코드 파일(UserDebugService.java를 commit, push하지 마세요)
repository에서의 코드는 UserService.java만 존재해야 하며, @service 어노테이션 역시 UserService에 붙어 있어야 합니다.
이렇게 하면, PostMan에서 Hedars에 userId 값을 통해 현재 유저 설정이 가능합니다.
The text was updated successfully, but these errors were encountered: