-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
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
[Spring Data JPA] 안금서 미션 제출합니다. #110
Open
goldm0ng
wants to merge
50
commits into
next-step:goldm0ng
Choose a base branch
from
goldm0ng:spring-data-jpa
base: goldm0ng
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
5913de1
<ADD> gradle 의존성 추가
goldm0ng 67da617
<ADD> 토큰 기반 인증 방식 jwt 관련 기능 추가
goldm0ng 53828d8
<FIX> MemberRequest DTO를 record 형식으로 변경
goldm0ng 0ec5186
<ADD> jwt를 사용한 로그인 및 인증 정보 조회 기능 구현
goldm0ng ebf6407
<ADD> 로그인 사용자 정보인 MemberAuthInfo를 조회하는 HandlerMethodArgumentResolver 구현
goldm0ng 22f9e30
<FIX> HandlerMethodArgumentResolver 구현에 따른 예약 API 및 기능 리팩터링
goldm0ng 347d0c7
<ADD> 관리자 기능 구현
goldm0ng 2a96836
<ADD> 사용자의 정보를 조회하는 ArgumentResolver와 관리자만 해당 경로에 접근할 수 있도록 하는 Interc…
goldm0ng 91bf7bf
<ADD> 예외처리 추가
goldm0ng 16e217b
<ADD> 1 ~ 3단계 미션 테스트 추가
goldm0ng 4a9ff8c
<FIX> DTO record 타입으로 변경
goldm0ng a5e8d66
<FIX> DTO record 타입으로 변경에 따른 수정
goldm0ng e027b31
<FIX> 응답 바디 타입 수정
goldm0ng c7a1875
<FIX> 인증 패키지 구조 변경
goldm0ng 2358568
<FIX> JwtUtils 관련 수정 (멤버 변수 및 메서드)
goldm0ng b44dab1
<FIX> 에러 추적 용이하도록 에러 포함
goldm0ng 330b40c
<FIX> gradle 의존성 jdbc -> jpa로 대체
goldm0ng 7a7ed55
<ADD> JPA 관련 설정 추가
goldm0ng c5f4f97
<ADD> 초기 데이터베이스 seed 데이터 추가 및 기존 스키마 삭제
goldm0ng 580c6ab
<FIX> Time 도메인 엔티티 매핑 및 JPA 전환
goldm0ng edfbc2c
<FIX> Theme 도메인 엔티티 매핑 및 JPA 전환
goldm0ng 312bdea
<FIX> Reservation 도메인 엔티티 매핑 및 JPA 전환
goldm0ng bef9160
<FIX> Member 도메인 엔티티 매핑 및 JPA 전환
goldm0ng f164ce0
<FIX> JPA 전환에 따른 LoginService 수정 및 예외처리 방식 변경
goldm0ng e2a32bc
<ADD> 4단계 테스트 코드 추가
goldm0ng 9c5e253
<FIX> Spring MVC (인증) 미션 테스트 이름 수정
goldm0ng 0840983
<FIX> 초기값 설정을 위한 쿼리 수정
goldm0ng da71532
<FIX> 회원 인증 정보 DTO 수정 (id 정보 추가)
goldm0ng 84f4e41
<ADD> 내 예약 목록 응답 DTO 추가
goldm0ng fd7a976
<FIX> Reservation - Member 추가 연관관계 매핑
goldm0ng fcf74d3
<FIX> Reservation DTO를 record 타입으로 변경
goldm0ng 54d412e
<ADD> 내 예약 목록 조회 기능 구현
goldm0ng a4b3705
<FIX> JwtUtils id 추출 코드 수정
goldm0ng b8d792b
<ADD> 사용자 정의 예외 생성 및 핸들러에 추가
goldm0ng aba712d
<ADD> 5단계 테스트 코드 추가 및 전 단계 테스트 수정
goldm0ng d472034
<ADD> 예약 대기 요청 및 취소 기능 구현
goldm0ng 751587d
<ADD> 예약 중복 방지 및 내 예약 조회 시 예약 대기 목록까지 보이도록 구현
goldm0ng e963234
<ADD> 중복 예약 관련 커스텀 예외 추가
goldm0ng 8b292c3
<ADD> 6단계 테스트 코드 추가 및 테스트 깨지는 부분 수정
goldm0ng 39a0f7d
<FIX> 예약 대기 취소 구현 오류 해결
goldm0ng e7e5c7b
<FIX> 공통 예외 처리 핸들러 중복 코드 제거
goldm0ng a80573b
<FIX> 예외 처리 오류 2차 해결 및 로깅 방식 수정
goldm0ng 08017a7
<FIX> JPA 쿼리 메소드 적용
goldm0ng 35ec5f7
<FIX> 기본 생성자 접근지정자 변경 및 생성 어노테이션 추가
goldm0ng 1959159
<ADD> 변경에 유연하도록 인터페이스 추가 및 jwt 인증 구현체 추가
goldm0ng b4bf7fb
<FIX> 기존 JwtUtils를 클래스 속성에 맞도록 이름 수정
goldm0ng c74ea76
<ADD> jwt 인증 로직을 모아놓은 service 추가
goldm0ng c4d0384
<FIX> 인증 응답 이름 더 포괄적으로 수정
goldm0ng a25995f
<FIX> jwt 패키지와의 강한 결합 분리
goldm0ng 4c8b450
Merge branch 'goldm0ng' into spring-data-jpa
goldm0ng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package roomescape.authentication; | ||
|
||
public record MemberAuthInfo( | ||
Long id, | ||
String name, | ||
String role) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/roomescape/exception/DuplicateReservationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package roomescape.exception; | ||
|
||
public class DuplicateReservationException extends RuntimeException { | ||
public DuplicateReservationException(String message) { | ||
super(message); | ||
} | ||
} |
20 changes: 11 additions & 9 deletions
20
src/main/java/roomescape/exception/GeneralExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
package roomescape.exception; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class GeneralExceptionHandler { | ||
|
||
@ExceptionHandler(MemberNotFoundException.class) | ||
public ResponseEntity<String> handleMemberNotFound(MemberNotFoundException e) { | ||
@ExceptionHandler({MemberNotFoundException.class, JwtValidationException.class, JwtProviderException.class}) | ||
public ResponseEntity<String> handleMemberNotFound(Exception e) { | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.getMessage()); | ||
} | ||
|
||
@ExceptionHandler(JwtValidationException.class) | ||
public ResponseEntity<String> handleJwtValidationException(JwtValidationException e) { | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.getMessage()); | ||
@ExceptionHandler({TimeNotFoundException.class, ThemeNotFoundException.class}) | ||
public ResponseEntity<String> handleTimeNotFound(Exception e) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage()); | ||
} | ||
|
||
@ExceptionHandler(JwtProviderException.class) | ||
public ResponseEntity<String> handleJwtProviderException(JwtProviderException e) { | ||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.getMessage()); | ||
@ExceptionHandler(DuplicateReservationException.class) | ||
public ResponseEntity<String> handleDuplicatedReservation(DuplicateReservationException e) { | ||
return ResponseEntity.status(HttpStatus.CONFLICT).body(e.getMessage()); | ||
} | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<String> handleGeneralException(Exception e) { | ||
e.printStackTrace(); | ||
log.error("Exception [Err_Location] : {}", e.getStackTrace()[0]); | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage()); | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
src/main/java/roomescape/exception/MemberNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package roomescape.exception; | ||
|
||
public class MemberNotFoundException extends RuntimeException { | ||
public MemberNotFoundException(String message, Throwable cause) { | ||
super(message, cause); | ||
|
||
public MemberNotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/roomescape/exception/ThemeNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package roomescape.exception; | ||
|
||
public class ThemeNotFoundException extends RuntimeException { | ||
public ThemeNotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/roomescape/exception/TimeNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package roomescape.exception; | ||
|
||
public class TimeNotFoundException extends RuntimeException { | ||
public TimeNotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
package roomescape.login; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.dao.EmptyResultDataAccessException; | ||
import org.springframework.stereotype.Service; | ||
import roomescape.authentication.MemberAuthInfo; | ||
import roomescape.authentication.AuthenticationResponse; | ||
import roomescape.authentication.AuthenticationService; | ||
import roomescape.member.Member; | ||
import roomescape.member.MemberDao; | ||
|
||
import roomescape.exception.MemberNotFoundException; | ||
import roomescape.member.MemberRepository; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class LoginService { | ||
|
||
private final MemberDao memberDao; | ||
|
||
private final MemberRepository memberRepository; | ||
private final AuthenticationService authenticationService; | ||
|
||
public AuthenticationResponse login(LoginRequest loginRequest) { | ||
|
||
try { | ||
Member member = memberDao.findByEmailAndPassword(loginRequest.email(), loginRequest.password()); | ||
Member member = memberRepository.findByEmailAndPassword(loginRequest.email(), loginRequest.password()) | ||
.orElseThrow(() -> new MemberNotFoundException("입력한 이메일 혹은 비밀번호로 가입한 회원을 찾을 수 없습니다.")); | ||
|
||
return authenticationService.createToken(member); | ||
} catch (EmptyResultDataAccessException e) { | ||
throw new MemberNotFoundException("이메일 혹은 비밀번호가 맞지 않습니다.", e); | ||
} | ||
} | ||
|
||
public LoginCheckResponse checkLogin(MemberAuthInfo memberAuthInfo) { | ||
|
||
try { | ||
Member member = memberDao.findByName(memberAuthInfo.name()); | ||
return new LoginCheckResponse(member.getName()); | ||
} catch (EmptyResultDataAccessException e) { | ||
throw new MemberNotFoundException("로그인이 되지 않은 상태입니다.", e); | ||
} | ||
Member member= memberRepository.findByName(memberAuthInfo.name()) | ||
.orElseThrow(() -> new MemberNotFoundException("로그인 된 회원이 아닙니다.")); | ||
|
||
return new LoginCheckResponse(member.getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package roomescape.member; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
|
||
Optional<Member> findByEmailAndPassword(String email, String password); | ||
|
||
Optional<Member> findByName(String name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package roomescape.member; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MemberService { | ||
private MemberDao memberDao; | ||
|
||
public MemberService(MemberDao memberDao) { | ||
this.memberDao = memberDao; | ||
} | ||
private final MemberRepository memberRepository; | ||
|
||
public MemberResponse createMember(MemberRequest memberRequest) { | ||
Member member = memberDao.save(new Member(memberRequest.name(), memberRequest.email(), memberRequest.password(), "USER")); | ||
Member member = memberRepository.save(new Member(memberRequest.name(), memberRequest.email(), memberRequest.password(), "USER")); | ||
return new MemberResponse(member.getId(), member.getName(), member.getEmail()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/roomescape/reservation/MyReservationResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package roomescape.reservation; | ||
|
||
public record MyReservationResponse( | ||
Long reservationId, | ||
String theme, | ||
String date, | ||
String time, | ||
String status | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
보통
ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
와 같은 진짜 뭔지 모르는 곳에서 터지는 에러의 경우에는 e.getMessage() 가 서버의 중요한 부분을 담고 있을 수도 있어서 이런 케이스에서는 그냥 body 에 "잠깐 문제가 생겼어요. 다음에 다시 시도해주세요" 같은 문구를 내려주는 편입니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하 그렇군요!
Q1. 예를 들면 어떤 중요한 부분 말씀이신가요? 감이 잘 잡히지 않네요!
Q2. 그리고 누누님은 예외 응답을 내려줄 때 중대한 문제를 일으킨 경험이 있으신가요? 있다면 어떤 문제였고, 어떻게 해결하셨는지도 궁금합니다! (꼭 예외 응답을 내려줄 때가 아니어도 예외처리 관련한 경험이 있으시다면 말씀해주세요!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q1 > 서버에 어떤 라이브러리를 사용하고 있는지와 같은 정보들이 전달되는 것 자체가 문제가 될 수 있어요!
Q2 > 저는 예외 응답을 만들다가 예외가 터졌던 기억이 나네요
근데, 예외 응답을 만드는 곳도(catch 문) 다시 한번 감싸져서 기본 응답을 주도록 되어있어서 문제 없이 동작했던 경험이 있어요!