-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#33 [feat] : 유저 거래 로그 엔터티 & 레포지토리 추가
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
backend/src/main/java/org/dgu/backend/domain/UserTradingLog.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,50 @@ | ||
package org.dgu.backend.domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.dgu.backend.common.BaseEntity; | ||
|
||
import java.math.BigDecimal; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@Table(name = "users_trading_logs") | ||
public class UserTradingLog extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "trading_logs_id") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "users_id", foreignKey = @ForeignKey(name = "users_trading_logs_fk_portfolios_id")) | ||
private User user; | ||
|
||
@Column(name = "type", nullable = false) | ||
private String type; | ||
|
||
@Column(name = "capital", nullable = false) | ||
private Long capital; | ||
|
||
@Column(name = "coin", nullable = false, precision = 30, scale = 15) | ||
private BigDecimal coin; | ||
|
||
@Column(name = "coin_price", nullable = false) | ||
private Double coinPrice; | ||
|
||
@Column(name = "rate", nullable = false) | ||
private Double rate; | ||
|
||
@Builder | ||
public UserTradingLog(User user, String type, Long capital, BigDecimal coin, Double coinPrice, Double rate){ | ||
this.user = user; | ||
this.type = type; | ||
this.capital = capital; | ||
this.coin = coin; | ||
this.coinPrice = coinPrice; | ||
this.rate = rate; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/org/dgu/backend/repository/UserTradingLogRepository.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,15 @@ | ||
package org.dgu.backend.repository; | ||
|
||
import io.lettuce.core.dynamic.annotation.Param; | ||
import org.dgu.backend.domain.User; | ||
import org.dgu.backend.domain.UserTradingLog; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.List; | ||
|
||
public interface UserTradingLogRepository extends JpaRepository<UserTradingLog,Long> { | ||
@Query("SELECT utl FROM UserTradingLog utl WHERE utl.user = :user " + | ||
"AND utl.createdAt > (SELECT MAX(utl2.createdAt) FROM UserTradingLog utl2 WHERE utl2.user = :user AND utl2.type = 'SELL')") | ||
List<UserTradingLog> findRecentLogsAfterLastSell(@Param("user") User user); | ||
} |