Skip to content

Commit

Permalink
Merge pull request #6 from Capstone-Walking/feat/refactor-data-entity
Browse files Browse the repository at this point in the history
Refactor: #4의 DataEntity 구현을 수정합니다
  • Loading branch information
belljun3395 authored May 8, 2024
2 parents 7df6f92 + 68f99fa commit 39c5bfb
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 169 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.walking.api.web.repository.member;
package com.walking.api.repository.member;

import com.walking.data.entity.member.MemberEntity;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.walking.api.web.repository.member;
package com.walking.api.repository.member;

import com.walking.data.entity.member.PathFavoritesEntity;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.walking.api.web.repository.member;
package com.walking.api.repository.member;

import com.walking.data.entity.member.TrafficFavoritesEntity;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.walking.api.web.repository.traffic;
package com.walking.api.repository.traffic;

import com.walking.data.entity.traffic.TrafficEntity;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
142 changes: 0 additions & 142 deletions api/src/test/java/com/walking/api/RepoTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.walking.api;
package com.walking.api.repository;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.walking.api.config.ApiDataSourceConfig;
Expand Down Expand Up @@ -38,4 +38,4 @@
ObjectMapper.class,
})
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
class RepositoryTest {}
abstract class RepositoryTest {}
2 changes: 1 addition & 1 deletion data/src/main/java/com/walking/data/entity/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public abstract class BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, updatable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.walking.data.entity.member;

public enum CertificationSubject {
KAKAO,
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import com.walking.data.entity.BaseEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
Expand All @@ -20,9 +23,32 @@
@SQLDelete(sql = "UPDATE member SET deleted=true where id=?")
public class MemberEntity extends BaseEntity {

/* 소셜 로그인을 통해 가입한 회원의 닉네임 */
@Column(nullable = false, unique = true, length = 50)
private String nickName;

/* 소셜 로그인을 통해 가입한 회원의 프로필 이미지 URL */
@Column(nullable = false)
private String memberId;
private String profile;

/* 소셜 로그인을 통해 가입한 회원의 식별자 */
@Column(nullable = false, unique = true)
private String certificationId;

/* 소셜 로그인을 통해 가입한 회원의 인증 주체 */
@SuppressWarnings("FieldMayBeFinal")
@Enumerated(EnumType.STRING)
@Builder.Default
@Column(nullable = false)
private String password;
private CertificationSubject certificationSubject = CertificationSubject.KAKAO;

@SuppressWarnings("FieldMayBeFinal")
@Enumerated(EnumType.STRING)
@Builder.Default
@Column(nullable = false)
private MemberStatus status = MemberStatus.REGULAR;

@Builder.Default
@Column(nullable = false, columnDefinition = "json")
private String resource = "{}";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.walking.data.entity.member;

import lombok.ToString;

@ToString
public enum MemberStatus {
REGULAR("정회원"),
ASSOCIATE("준회원"),
SEPARATE("장기미이용 회원"),
WITHDRAWN("탈퇴회원"),
;

private final String description;

MemberStatus(String description) {
this.description = description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@
public class PathFavoritesEntity extends BaseEntity {

@ManyToOne(fetch = FetchType.LAZY)
private MemberEntity memberEntity;
@JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
private MemberEntity memberFk;

@Column(columnDefinition = "POINT")
@Column(nullable = false, columnDefinition = "POINT SRID 4326")
private Point startPoint;

@Column(columnDefinition = "POINT")
@Column(nullable = false, columnDefinition = "POINT SRID 4326")
private Point endPoint;

@Column(columnDefinition = "LINESTRING")
@Column(nullable = false, columnDefinition = "LINESTRING SRID 4326")
private LineString path;

@Column(nullable = false)
@Column(nullable = false, length = 50)
private String startAlias;

@Column(nullable = false)
@Column(nullable = false, length = 50)
private String endAlias;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
public class TrafficFavoritesEntity extends BaseEntity {

@ManyToOne(fetch = FetchType.LAZY)
private MemberEntity memberEntity;
@JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
private MemberEntity memberFk;

@OneToOne(fetch = FetchType.LAZY)
private TrafficEntity trafficEntity;
@JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
private TrafficEntity trafficFk;

@Column(nullable = false)
@Column(nullable = false, length = 50)
private String alias;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.walking.data.entity.support.listener;

import com.walking.data.entity.traffic.TrafficEntity;
import javax.persistence.PreRemove;

public class TrafficEntitySoftDeleteListener {

@PreRemove
private void preRemove(TrafficEntity entity) {
entity.delete();
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,61 @@
package com.walking.data.entity.traffic;

import com.walking.data.entity.BaseEntity;
import com.walking.data.entity.support.listener.TrafficEntitySoftDeleteListener;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.locationtech.jts.geom.Point;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Entity
@SuperBuilder(toBuilder = true)
@EntityListeners({AuditingEntityListener.class, TrafficEntitySoftDeleteListener.class})
@Builder(toBuilder = true)
@Table(name = "traffic")
@SQLDelete(sql = "UPDATE traffic SET deleted=true where id=?")
public class TrafficEntity extends BaseEntity {
public class TrafficEntity {

@Column(nullable = false, updatable = false)
private String detail;

@Column(nullable = false)
private String name;

@Column(columnDefinition = "POINT SRID 4326", nullable = false)
@Column(nullable = false, columnDefinition = "POINT SRID 4326")
private Point point;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;

@Column(nullable = false, updatable = false)
@CreatedDate
private LocalDateTime createdAt;

@Column(nullable = false)
@LastModifiedDate
private LocalDateTime updatedAt;

@Builder.Default
@Column(nullable = false)
private Boolean deleted = false;

public void delete() {
this.deleted = true;
}
}
7 changes: 6 additions & 1 deletion data/src/main/resources/application-data-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ spring:
ddl-auto: validate
properties:
hibernate:
format_sql: true
format_sql: true
dialect: org.hibernate.spatial.dialect.mysql.MySQL8SpatialDialect
order_inserts: true
order_updates: true
jdbc:
batch_size: ${JDBC_BATCH_SIZE:50}
Loading

0 comments on commit 39c5bfb

Please sign in to comment.