-
Notifications
You must be signed in to change notification settings - Fork 240
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
🐷 step3 : 즐겨찾기 기능 구현 #241
base: minyul
Are you sure you want to change the base?
🐷 step3 : 즐겨찾기 기능 구현 #241
Changes from 6 commits
ba01b3c
bc0773b
d6285c7
93395aa
ff5dd75
d838e0a
a21678b
0c52d1a
b20453e
cc6bcd8
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package nextstep.auth.authentication; | ||
|
||
import nextstep.auth.User; | ||
import nextstep.auth.UserDetailsService; | ||
import nextstep.auth.context.Authentication; | ||
import org.springframework.util.ObjectUtils; | ||
|
||
public class Authorizer { | ||
|
||
private UserDetailsService userDetailsService; | ||
|
||
public Authorizer(UserDetailsService userDetailsService) { | ||
this.userDetailsService = userDetailsService; | ||
} | ||
|
||
public void checkAuthentication(User userDetails, AuthenticationToken token) { | ||
if (ObjectUtils.isEmpty(userDetails)) { | ||
throw new AuthenticationException(); | ||
} | ||
|
||
if (!userDetails.checkPassword(token.getCredentials())) { | ||
throw new AuthenticationException(); | ||
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.
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 Authentication authenticate(AuthenticationToken authenticationToken) { | ||
final String principal = authenticationToken.getPrincipal(); | ||
final User userDetails = userDetailsService.loadUserByUsername(principal); | ||
checkAuthentication(userDetails, authenticationToken); | ||
|
||
return new Authentication(userDetails); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package nextstep.member.application.dto; | ||
|
||
public class FavoriteRequest { | ||
|
||
private Long source; | ||
private Long target; | ||
|
||
public Long getSource() { | ||
return source; | ||
} | ||
|
||
public Long getTarget() { | ||
return target; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package nextstep.member.application.dto; | ||
|
||
import nextstep.member.domain.Favorite; | ||
import nextstep.subway.applicaion.dto.StationResponse; | ||
|
||
public class FavoriteResponse { | ||
|
||
private Long id; | ||
private StationResponse source; | ||
private StationResponse target; | ||
|
||
public static FavoriteResponse of(Favorite favorite) { | ||
|
||
return new FavoriteResponse( | ||
favorite.getId(), | ||
StationResponse.of(favorite.getSource()), | ||
StationResponse.of(favorite.getTarget())); | ||
} | ||
|
||
public FavoriteResponse(Long id, StationResponse source, StationResponse target) { | ||
this.id = id; | ||
this.source = source; | ||
this.target = target; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public StationResponse getSource() { | ||
return source; | ||
} | ||
|
||
public StationResponse getTarget() { | ||
return target; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package nextstep.member.domain; | ||
|
||
import nextstep.subway.domain.Station; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
public class Favorite { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(cascade = CascadeType.PERSIST) | ||
@JoinColumn(name = "member_id") | ||
private Member 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. 객체 직접 참조를 사용해주셨네요 👍 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. 과거 신입 프로젝트로 로그인쪽을 구현하고 코드리뷰를 받았을 때, 사용자와 관련된 부분은 직접참조, 아닌 경우에는 간접 참조를 하라고 피드백을 받았었는데요! 어떻게 생각하시나요? 그리고 준우님 말씀대로 직접 -> 간접으로 객체참조를 바꿨습니다. 감사합니다. |
||
|
||
@ManyToOne(cascade = CascadeType.PERSIST) | ||
@JoinColumn(name = "up_station_id") | ||
private Station source; | ||
|
||
@ManyToOne(cascade = CascadeType.PERSIST) | ||
@JoinColumn(name = "down_station_id") | ||
private Station target; | ||
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. Favorite이 저장될 때, Member, source, target들이 함께 저장되는게 의도하신 바가 맞을까요? 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. 음..... 이부분은 기존에 더 나아가서 이 부분이 진짜 계속 멤돌았는데.. Section 에서 Upstation, DownStation. 이부분에서 음.. 구간(Section) 에 역 2개 (Upstation, DownStation) 이 있으며 결국엔 같지만 왜
Comment on lines
+17
to
+23
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. cascade는 없이 하는게 더 좋을 것 같아요. 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.
요 질문의 요지를 제가 잘 이해하지 못하겠습니다....... 😭 |
||
|
||
protected Favorite() {} | ||
|
||
public Favorite(Member member, Station source, Station target) { | ||
this.member = member; | ||
this.source = source; | ||
this.target = target; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public Member getMember() { | ||
return member; | ||
} | ||
|
||
public Station getSource() { | ||
return source; | ||
} | ||
|
||
public Station getTarget() { | ||
return target; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package nextstep.member.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FavoriteRepository extends JpaRepository<Favorite, Long> { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package nextstep.member.domain; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Embeddable; | ||
import javax.persistence.OneToMany; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Embeddable | ||
public class Favorites { | ||
|
||
@OneToMany(mappedBy = "member", cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true) | ||
private List<Favorite> favorites = new ArrayList<>(); | ||
|
||
public void add(Favorite favorite) { | ||
this.favorites.add(favorite); | ||
} | ||
|
||
public void remove(Favorite favorite) { | ||
this.favorites.remove(favorite); | ||
} | ||
|
||
public List<Favorite> getFavorites() { | ||
return Collections.unmodifiableList(favorites); | ||
} | ||
Comment on lines
+10
to
+26
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. 더이상 쓰이지 않는 객체라 제거해도 좋을 것 같습니다 :) |
||
} |
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.
private으로 선언해볼 수 있겠네요 :)
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.
리뷰는 천천히 해주셔도 됩니다! 이미 시간이 지나버렸는걸요! 천천히 해주셔도 괜찮습니다. 해주시는것만으로도 정말 감사하구요! 감사합니다!