-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/java/HeyPorori/transaction/config/BaseTimeEntity.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,23 @@ | ||
package HeyPorori.transaction.config; | ||
|
||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.EntityListeners; | ||
import javax.persistence.MappedSuperclass; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class BaseTimeEntity { | ||
@CreatedDate | ||
@Column(updatable = false) | ||
private LocalDateTime createdAt; | ||
|
||
@LastModifiedDate | ||
private LocalDateTime updatedAt; | ||
} |
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,23 @@ | ||
package HeyPorori.transaction.domain; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum Category { | ||
ELECTRONICS("전자제품", "스마트폰, 컴퓨터, 태블릿, TV, 오디오 기기 등"), | ||
CLOTHING_ACCESSORIES("의류 및 액세서리", "옷, 신발, 가방, 모자, 보석 등"), | ||
FURNITURE_HOME_GOODS("가구 및 가정용품", "테이블, 의자, 침대, 조명, 주방 용품 등"), | ||
SPORTS_LEISURE("스포츠 및 레저", "운동기구, 캠핑 용품, 자전거, 낚시 용품 등"), | ||
CARS_MOTORCYCLES("자동차 및 오토바이", "중고차, 오토바이, 자동차 부품, 액세서리 등"), | ||
BOOKS_MUSIC("도서 및 음악", "소설, 교육자료, CD, LP, 악기 등"), | ||
BABY_KIDS("아기 및 어린이 용품", "아기 의류, 장난감, 유모차, 아기 침대 등"), | ||
ETC("기타", ""); | ||
|
||
private final String name; | ||
private final String description; | ||
|
||
Category(String name, String description) { | ||
this.name = name; | ||
this.description = description; | ||
} | ||
} |
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,31 @@ | ||
package HeyPorori.transaction.domain; | ||
|
||
import HeyPorori.transaction.config.BaseTimeEntity; | ||
import lombok.*; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "recommend") | ||
public class Recommend extends BaseTimeEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "recommend_id") | ||
private Long recommendId; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY, optional = false) | ||
@JoinColumn(name = "transaction_id") | ||
private Transaction transactionId; | ||
|
||
@Column(name = "user_id", nullable = false) | ||
private Long userId; | ||
|
||
@Builder | ||
public Recommend(Transaction transactionId, Long userId){ | ||
this.transactionId = transactionId; | ||
this.userId = userId; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/HeyPorori/transaction/domain/Transaction.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,75 @@ | ||
package HeyPorori.transaction.domain; | ||
|
||
import HeyPorori.transaction.config.BaseTimeEntity; | ||
import lombok.*; | ||
import org.hibernate.annotations.ColumnDefault; | ||
import org.hibernate.annotations.DynamicInsert; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
|
||
import javax.persistence.*; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "transaction") | ||
@DynamicInsert | ||
@DynamicUpdate | ||
public class Transaction extends BaseTimeEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "transaction_id") | ||
private Long transactionId; | ||
|
||
@Column(nullable = false, name = "user_id") | ||
private Long userId; | ||
|
||
@Column(nullable = false, columnDefinition = "varchar(20)") | ||
private String title; | ||
|
||
@Column(nullable = false, columnDefinition = "varchar(200)") | ||
private String content; | ||
|
||
@ColumnDefault("0") | ||
private int recommend; | ||
|
||
@Column(nullable = false) | ||
private String address; | ||
|
||
@Column(nullable = false) | ||
private Double latitude; | ||
|
||
@Column(nullable = false) | ||
private Double longitude; | ||
|
||
@Column(nullable = false) | ||
private Category category; | ||
|
||
@ColumnDefault("'ACTIVE'") | ||
private String status; | ||
|
||
@OneToMany(mappedBy = "transactionId", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST) | ||
private List<TransactionAttach> attachList = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "transactionId", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST) | ||
private List<Recommend> recommendList = new ArrayList<>(); | ||
|
||
@Builder | ||
public Transaction(Long userId, String title, String content, int recommend, String address, Double latitude, Double longitude, Category category, String status){ | ||
this.userId = userId; | ||
this.title = title; | ||
this.content = content; | ||
this.recommend = recommend; | ||
this.address = address; | ||
this.latitude = latitude; | ||
this.longitude = longitude; | ||
this.category = category; | ||
this.status = status; | ||
} | ||
|
||
public void changeStatus(String status) { | ||
this.status = status; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/HeyPorori/transaction/domain/TransactionAttach.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,33 @@ | ||
package HeyPorori.transaction.domain; | ||
|
||
import HeyPorori.transaction.config.BaseTimeEntity; | ||
import lombok.*; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "transaction_attach") | ||
@DynamicUpdate | ||
public class TransactionAttach extends BaseTimeEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "attach_id") | ||
private Long attachId; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY, optional = false) | ||
@JoinColumn(name = "transaction_id") | ||
private Transaction transactionId; | ||
|
||
@Column(name = "image_url", nullable = false) | ||
private String imageUrl; | ||
|
||
@Builder | ||
public TransactionAttach(Transaction transactionId, String imageUrl){ | ||
this.transactionId = transactionId; | ||
this.imageUrl = imageUrl; | ||
} | ||
} |