-
Notifications
You must be signed in to change notification settings - Fork 97
[그리디] 이채현 JPA 6단계 제출합니다 #267
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
base: chaehyunl
Are you sure you want to change the base?
Changes from 98 commits
d0eac68
53bba1c
24ee8ee
54aee6d
0365054
143eb7d
ecc8025
80053ba
ab18aef
66728ba
74f36bd
f0ce4c0
44ad820
c5ae254
05a06d3
7e0c71b
95f915d
165b552
40aff17
578d9a3
af5ff58
b0692c5
d87a302
4836e92
d808ed6
4c1ffe7
f77ce23
0de02ba
2e26756
4730128
0eae6c3
653e960
8bb5385
488f861
aa2b5fa
8895666
4184b79
3bd4251
ec8004e
8957601
20a948c
f948434
93465ad
2fba555
49b6d7f
13b8925
715960c
a272863
cee6ff6
9fda054
767742f
a3eebbe
262a651
c5cc7a3
6fff1f3
4518389
b9cc04b
31d685e
9c9ae75
e3f65ef
35ebc38
0f3d928
77abb17
cae9a52
dd40b5a
07c4f55
1ff8645
1373c71
3db99b7
80797fa
cd1a819
74c0595
313e5ee
fd3e903
12e9014
7bb3fe5
72b8311
63b2eb1
13f3d39
5405303
6c6a2e9
e52407f
cb1863e
2fb95bf
afcde38
a6013d1
7be91b0
235214c
8fca327
a610636
f188d27
aabe511
b930ef6
10eb09f
129ab0d
bcc5974
9e41a00
315b5ae
1c74bc1
0b719fd
4d167b5
6c2cee4
e152c74
7477b48
d6e9530
1cc41fb
418bb7c
415b116
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,48 @@ | ||
| package roomescape.login; | ||
|
|
||
| public record LoginMember( | ||
| Long id, | ||
| String name, | ||
| String email, | ||
| String role | ||
| ) { | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
|
|
||
|
|
||
| public class LoginMember { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
| private String name; | ||
| private String email; | ||
| private String password; | ||
| private String role; | ||
|
|
||
| protected LoginMember() { | ||
|
|
||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DTO의 역할을 하는 객체인 거 같은 데 ID를 붙여준 이유가 있나요?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. entity라고 착각해서,id를 붙여준 것 같습니다. |
||
|
|
||
| public LoginMember(Long id, String name, String email, String password, String role) { | ||
| this.id = id; | ||
| this.name = name; | ||
| this.email = email; | ||
| this.password = password; | ||
| this.role = role; | ||
| } | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public String getEmail() { | ||
| return email; | ||
| } | ||
|
|
||
| public String getPassword() { | ||
| return password; | ||
| } | ||
|
|
||
| public String getRole() { | ||
| return role; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,15 +11,15 @@ | |
| import roomescape.CookieManager; | ||
| import roomescape.JwtProvider; | ||
| import roomescape.member.Member; | ||
| import roomescape.member.MemberDao; | ||
| import roomescape.member.MemberRepository; | ||
|
|
||
| @Component | ||
| public class LoginMemberArgumentResolver implements HandlerMethodArgumentResolver { | ||
| private final MemberDao memberDao; | ||
|
Comment on lines
17
to
-18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ArgumentResolver를 만드신 이유가 무엇인가요?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로그인하는 멤버를 잡아서, 로그인을 확인하고 admin 권한을 가지고 있는 사람에게 권한을 부여해줍니다 |
||
| private final MemberRepository memberRepository; | ||
| private final JwtProvider jwtProvider; | ||
| private final CookieManager cookieManager; | ||
| public LoginMemberArgumentResolver(JwtProvider jwtProvider, MemberDao memberDao,CookieManager cookieManager) { | ||
| this.memberDao = memberDao; | ||
| public LoginMemberArgumentResolver(JwtProvider jwtProvider, MemberRepository memberRepository,CookieManager cookieManager) { | ||
| this.memberRepository = memberRepository; | ||
| this.jwtProvider = jwtProvider; | ||
| this.cookieManager=cookieManager; | ||
| } | ||
|
|
@@ -38,9 +38,10 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m | |
|
|
||
| Long memberId = jwtProvider.getMemberId(token); | ||
|
|
||
| Member member = memberDao.findById(memberId); | ||
| Member member = memberRepository.findById(memberId) | ||
| .orElseThrow(); | ||
|
|
||
| return new LoginMember(member.getId(), member.getName(), member.getEmail(), member.getRole()); | ||
| return new LoginMember(memberId, member.getName(), member.getEmail(), member.getPassword(),member.getRole()); | ||
| } | ||
|
|
||
| private HttpServletRequest getRequest(NativeWebRequest nativeWebRequest) { | ||
|
|
@@ -58,5 +59,4 @@ private Cookie[] getCookies(HttpServletRequest httpServletRequest) { | |
| } | ||
| return cookies; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,31 @@ | ||
| package roomescape.member; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
|
|
||
| @Entity | ||
| public class Member { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| private String name; | ||
| private String email; | ||
| private String password; | ||
| private String role; | ||
|
Comment on lines
+17
to
27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DB 안에는 email의 unique 제약이 있는 데 엔티티에는 따로 제약사항이 없네요. 이렇게 DB와 엔티티에 제약사항이 다를 경우 생길 수 있는 문제들은 어떤 것들이 있을까요?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Member Entity에서는 여러개의 email을 넣었을때는 비즈니스적으로는 문제가 발생하지 DB 내에서는 unique 제약이 걸려있어서 그 부분에서 충돌이 일어날 수 있을 것 같습니다. DB안에 unique 제약이 걸려있다고 하셨는데, 어떤 패키지를 통해 확인할 수 있나요? |
||
|
|
||
| public Member(Long id, String name, String email, String role) { | ||
| this.id = id; | ||
| this.name = name; | ||
| this.email = email; | ||
| this.role = role; | ||
| protected Member(){ | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 생성자 메서드를 대신할 수 있는 어노테이션을 사용해볼까요? |
||
|
|
||
| public Member(String name, String email, String password, String role) { | ||
| this.name = name; | ||
| this.email = email; | ||
| this.password = password; | ||
| this.role = role; | ||
| } | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
| public Long getId() { return id; } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package roomescape.member; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| @Repository | ||
| public interface MemberRepository extends JpaRepository<Member, Long> { | ||
|
|
||
| Optional<Member> findByEmailAndPassword(String email, String password); | ||
|
|
||
| Optional<Member> findByName(String name); | ||
| } |
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.
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.
필터(Filter)
스프링 외부에서 관리
웹 애플리케이션 전체 적용
주요 용도. 인코딩 변환, xss 방어, cors 설정 등
인터셉터
스프링 컨테이너 내부
특정 url 및 컨트롤러 기준
주요 용도. 로그인 체크, 권한 부여,api 호출 로깅, 실행시간 계산 등..
admin 관리자임을 확인하고 권한 부여한다고 생각해서
인터셉터가 더 적합하다고 생각되었습니다.