Skip to content

Commit

Permalink
[디디] JPA 미션 제출합니다. (#58)
Browse files Browse the repository at this point in the history
* 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
fucct authored Jun 19, 2020
1 parent 40c254d commit 47caadd
Show file tree
Hide file tree
Showing 104 changed files with 2,592 additions and 2,374 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'net.rakugakibox.spring.boot:logback-access-spring-boot-starter:2.7.1'
implementation 'pl.allegro.tech.boot:handlebars-spring-boot-starter:0.3.0'
implementation 'org.jgrapht:jgrapht-core:1.0.1'
implementation 'io.jsonwebtoken:jjwt:0.9.1'
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.12'
testImplementation 'io.rest-assured:rest-assured:3.3.0'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc:2.0.4.RELEASE'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
Expand Down
21 changes: 18 additions & 3 deletions src/docs/asciidoc/api-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,84 +21,94 @@ endif::[]

[[resources-members-create-success]]
===== 성공
operation::members/create[snippets='http-request,http-response,request-fields']

operation::members/create[snippets='http-request,http-response,request-fields']

[[resources-members-create-fail]]
==== 실패

[[resources-members-create-fail-duplicated-email]]
===== 이메일 중복
operation::members/duplicate-create[snippets='http-request,http-response,request-fields']

operation::members/duplicate-create[snippets='http-request,http-response,request-fields']

[[resources-members-create-fail-not-match-password]]
===== 패스워드 불일치

operation::members/not-match-password-create[snippets='http-request,http-response,request-fields']

[[resources-members-login]]
=== 로그인

[[resources-members-login-successful]]
===== 성공

operation::members/login[snippets='http-request,http-response,request-fields']

[[resources-members-login-fail]]
==== 실패

[[resources-members-login-fail-not-exist-email]]
===== 존재하지 않는 이메일

operation::members/login-with-not-exist-email[snippets='http-request,http-response,request-fields']

[[resources-members-login-fail-not-match-password]]
===== 비밀번호 불일치

operation::members/login-with-wrong-password[snippets='http-request,http-response,request-fields']

[[resources-members-get]]
=== 회원 정보 조회

[[resources-members-get-successful]]
===== 성공

operation::members/get[snippets='http-request,http-response']

[[resources-members-get-fail]]
==== 실패

[[resources-members-get-fail-not-login]]
===== 토큰이 존재하지 않음
operation::members/not-exist-get[snippets='http-request,http-response']

operation::members/not-exist-get[snippets='http-request,http-response']

[[resources-members-update]]
=== 회원 정보 수정

[[resources-members-update-successful]]
===== 성공

operation::members/update[snippets='http-request,http-response,request-fields']

[[resources-members-update-fail]]
==== 실패

[[resources-members-update-fail-not-login]]
===== 토큰이 존재하지 않음

operation::members/not-exist-token-update[snippets='http-request,http-response,request-fields,response-fields']

[[resources-members-update-fail-not-match-password]]
===== 비밀번호가 올바르지 않

operation::members/not-match-password-update[snippets='http-request,http-response,request-fields,response-fields']

[[resources-members-delete]]
=== 회원 탈퇴

[[resources-members-delete-successful]]
===== 성공

operation::members/delete[snippets='http-request,http-response']

[[resources-members-delete-fail]]
==== 실패

[[resources-members-delete-not-login]]
===== 토큰이 존재하지 않음

operation::members/delete-not-exist-token[snippets='http-request,http-response,response-fields']

[[resources-favorites]]
Expand All @@ -109,30 +119,35 @@ operation::members/delete-not-exist-token[snippets='http-request,http-response,r

[[resources-favorites-create-successful]]
===== 성공

operation::favorites/create[snippets='http-request,http-response,request-fields']

[[resources-favorites-create-fail]]
==== 실패

[[resources-favorites-create-fail-no-login]]
===== 토큰이 존재하지 않음

operation::favorites/create-no-login[snippets='http-request,http-response,request-fields,response-fields']

===== 즐겨찾기 중복

operation::favorites/create-duplicated[snippets='http-request,http-response,request-fields,response-fields']

[[resources-favorites-delete]]
=== 즐겨찾기 삭제

[[resources-favorites-delete-successful]]
===== 성공

operation::favorites/delete[snippets='http-request,http-response']

[[resources-favorites-delete-fail]]
==== 실패

[[resources-favorites-delete-fail-not-login]]
===== 토큰이 존재하지 않음

operation::favorites/delete-not-login[snippets='http-request,http-response, response-fields']


Expand Down
8 changes: 5 additions & 3 deletions src/main/java/wooteco/subway/SubwayAdminApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
public class SubwayAdminApplication {

public static void main(String[] args) {
SpringApplication.run(SubwayAdminApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(SubwayAdminApplication.class, args);
}
}
3 changes: 2 additions & 1 deletion src/main/java/wooteco/subway/config/ETagHeaderFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
public class ETagHeaderFilter {
@Bean
public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() {
FilterRegistrationBean<ShallowEtagHeaderFilter> filterRegistrationBean = new FilterRegistrationBean<>(new ShallowEtagHeaderFilter());
FilterRegistrationBean<ShallowEtagHeaderFilter> filterRegistrationBean = new FilterRegistrationBean<>(
new ShallowEtagHeaderFilter());
filterRegistrationBean.addUrlPatterns("/lines/detail");
filterRegistrationBean.setName("etagFilter");
return filterRegistrationBean;
Expand Down

This file was deleted.

47 changes: 47 additions & 0 deletions src/main/java/wooteco/subway/domain/common/BaseEntity.java
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 src/main/java/wooteco/subway/domain/favorite/Favorite.java
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();
}
}
}
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);
}
Loading

0 comments on commit 47caadd

Please sign in to comment.