Skip to content

Commit

Permalink
#33 [feat] : 유저 거래 로그 엔터티 & 레포지토리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 committed Jun 17, 2024
1 parent 3c6e6b6 commit b634d7b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
50 changes: 50 additions & 0 deletions backend/src/main/java/org/dgu/backend/domain/UserTradingLog.java
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;
}
}
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);
}

0 comments on commit b634d7b

Please sign in to comment.