-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: 리뷰 반영 2 - Favorite 메서드명 수정 * refactor: JPA 수정 전 Interceptor 수정 * feat: JPA Domain feature & Context Load * refactor: properties, query * feat: LineStation 정상화 - 정상적으로 동작하도록 메서드 수정 - data.sql 오류 제거 * refactor: 전체 테스트 수정 * refactor: 다양한 리팩터링 - EnableJdbcAuditingConfig.java 클래스 명 수정 - Favorite 생성자 파라미터명 수정 - 불필요한 fetchType 제거 - 불필요한 메서드 제거 * refactor: 리뷰 반영 - JpaAuditing - equals & hashcode * refactor: BaseEntity 필드 삭제 - createdBy, updatedBy 삭제 * refactor: equals 메서드 수정
- Loading branch information
Showing
104 changed files
with
2,592 additions
and
2,374 deletions.
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
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
9 changes: 0 additions & 9 deletions
9
src/main/java/wooteco/subway/config/EnableJdbcAuditingConfig.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
src/main/java/wooteco/subway/domain/common/BaseEntity.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,47 @@ | ||
package wooteco.subway.domain.common; | ||
|
||
import static javax.persistence.GenerationType.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Objects; | ||
|
||
import javax.persistence.EntityListeners; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.MappedSuperclass; | ||
|
||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@MappedSuperclass | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EntityListeners(AuditingEntityListener.class) | ||
public abstract class BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
protected Long id; | ||
|
||
@CreatedDate | ||
private LocalDateTime createdAt; | ||
|
||
@LastModifiedDate | ||
private LocalDateTime updatedAt; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
BaseEntity that = (BaseEntity)o; | ||
return getId().equals(that.getId()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getId()); | ||
} | ||
} |
96 changes: 49 additions & 47 deletions
96
src/main/java/wooteco/subway/domain/favorite/Favorite.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,51 +1,53 @@ | ||
package wooteco.subway.domain.favorite; | ||
|
||
import java.util.Objects; | ||
|
||
import org.springframework.data.annotation.Id; | ||
|
||
public class Favorite { | ||
@Id | ||
private Long id; | ||
private Long memberId; | ||
private Long sourceId; | ||
private Long targetId; | ||
|
||
protected Favorite() { | ||
} | ||
|
||
public Favorite(Long id, Long memberId, Long sourceId, Long targetId) { | ||
this.id = id; | ||
this.memberId = memberId; | ||
this.sourceId = sourceId; | ||
this.targetId = targetId; | ||
} | ||
|
||
public static Favorite of(Long id, Long memberId, Long sourceId, Long targetId) { | ||
return new Favorite(id, memberId, sourceId, targetId); | ||
} | ||
|
||
public static Favorite of(Long memberId, Long sourceId, Long targetId) { | ||
return new Favorite(null, memberId, sourceId, targetId); | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public Long getMemberId() { | ||
return memberId; | ||
} | ||
|
||
public Long getSourceId() { | ||
return sourceId; | ||
} | ||
|
||
public Long getTargetId() { | ||
return targetId; | ||
} | ||
|
||
public boolean isSameId(Long id) { | ||
return Objects.equals(this.id, id); | ||
import static javax.persistence.FetchType.*; | ||
|
||
import javax.persistence.AttributeOverride; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import wooteco.subway.domain.common.BaseEntity; | ||
import wooteco.subway.domain.member.Member; | ||
import wooteco.subway.domain.station.Station; | ||
import wooteco.subway.web.exception.AuthenticationException; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@AttributeOverride(name = "id", column = @Column(name = "FAVORITE_ID")) | ||
public class Favorite extends BaseEntity { | ||
|
||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "MEMBER_ID") | ||
private Member member; | ||
|
||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "SOURCE_STATION_ID") | ||
private Station sourceStation; | ||
|
||
@ManyToOne(fetch = LAZY) | ||
@JoinColumn(name = "TARGET_STATION_ID") | ||
private Station targetStation; | ||
|
||
public Favorite(Long id, Member member, Station source, Station target) { | ||
this(member, source, target); | ||
super.id = id; | ||
} | ||
|
||
public static Favorite of(Member member, Station sourceStation, Station targetStation) { | ||
return new Favorite(member, sourceStation, targetStation); | ||
} | ||
|
||
public void validateMember(Member member) { | ||
if (!this.member.equals(member)) { | ||
throw new AuthenticationException(); | ||
} | ||
} | ||
} |
12 changes: 3 additions & 9 deletions
12
src/main/java/wooteco/subway/domain/favorite/FavoriteRepository.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,16 +1,10 @@ | ||
package wooteco.subway.domain.favorite; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.data.jdbc.repository.query.Query; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FavoriteRepository extends CrudRepository<Favorite, Long> { | ||
@Query("select * from favorite where (id = :id) and (member_id = :memberId)") | ||
Optional<Favorite> findByIdAndMemberId(@Param("id") Long id, @Param("memberId") Long memberId); | ||
public interface FavoriteRepository extends JpaRepository<Favorite, Long> { | ||
|
||
@Query("select * from favorite where member_id = :memberId") | ||
List<Favorite> findAllByMemberId(@Param("memberId") Long memberId); | ||
List<Favorite> findAllByMemberId(Long id); | ||
} |
Oops, something went wrong.