feat: Add user relation to black jack game entity
This commit is contained in:
parent
64e41b663e
commit
85d2b218aa
4 changed files with 10 additions and 6 deletions
|
@ -57,6 +57,7 @@ public class BlackJackGameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
BlackJackGameEntity game = new BlackJackGameEntity();
|
BlackJackGameEntity game = new BlackJackGameEntity();
|
||||||
|
game.setUser(user);
|
||||||
game.setBet(betAmount);
|
game.setBet(betAmount);
|
||||||
|
|
||||||
user.setBalance(user.getBalance().subtract(betAmount));
|
user.setBalance(user.getBalance().subtract(betAmount));
|
||||||
|
@ -64,5 +65,6 @@ public class BlackJackGameController {
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
blackJackGameRepository.save(game);
|
blackJackGameRepository.save(game);
|
||||||
|
|
||||||
return ResponseEntity.ok(game); }
|
return ResponseEntity.ok(game);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package de.szut.casino.blackjack;
|
package de.szut.casino.blackjack;
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import de.szut.casino.user.UserEntity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.*;
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
@ -20,6 +19,9 @@ public class BlackJackGameEntity {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
private Long id;
|
private Long id;
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "user_id", nullable = false)
|
||||||
|
private UserEntity user;
|
||||||
private String state;
|
private String state;
|
||||||
private BigDecimal bet;
|
private BigDecimal bet;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ package de.szut.casino.blackjack;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class Card {
|
public class CardEntity {
|
||||||
private final Suit suit;
|
private final Suit suit;
|
||||||
private final Rank rank;
|
private final Rank rank;
|
||||||
|
|
||||||
public Card(Suit suit, Rank rank) {
|
public CardEntity(Suit suit, Rank rank) {
|
||||||
this.suit = suit;
|
this.suit = suit;
|
||||||
this.rank = rank;
|
this.rank = rank;
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue