Merge pull request 'refactor: Change balance type to BigDecimal for better precision' (!43) from refactor/money-precision into main

Reviewed-on: https://git.simonis.lol/projects/casino/pulls/43
Reviewed-by: Constantin Simonis <constantin@simonis.lol>
Reviewed-by: Kjan Jattenhoff <jan@kjan.email>
This commit is contained in:
Huy 2025-02-26 11:10:25 +00:00
commit 0100df89f5
4 changed files with 20 additions and 5 deletions

View file

@ -16,3 +16,12 @@ Authorization: Bearer {{token}}
"username": "john.doe"
}
### Deposit
POST http://localhost:8080/deposit/checkout
Content-Type: application/json
Origin: http://localhost:8080
Authorization: Bearer {{token}}
{
"amount": 60.12
}

View file

@ -8,6 +8,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.math.BigDecimal;
@Setter
@Getter
@ -20,9 +21,11 @@ public class UserEntity {
@Column(unique = true)
private String keycloakId;
private String username;
private float balance;
public UserEntity(String keycloakId, String username, float balance) {
@Column(precision = 19, scale = 2)
private BigDecimal balance;
public UserEntity(String keycloakId, String username, BigDecimal balance) {
this.keycloakId = keycloakId;
this.username = username;
this.balance = balance;

View file

@ -4,6 +4,8 @@ import de.szut.casino.user.dto.CreateUserDto;
import de.szut.casino.user.dto.GetUserDto;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
@Service
public class UserMappingService {
public GetUserDto mapToGetUserDto(UserEntity user) {
@ -11,7 +13,6 @@ public class UserMappingService {
}
public UserEntity mapToUserEntity(CreateUserDto createUserDto) {
return new UserEntity(createUserDto.getKeycloakId(), createUserDto.getUsername(), 0);
}
return new UserEntity(createUserDto.getKeycloakId(), createUserDto.getUsername(), BigDecimal.ZERO); }
}

View file

@ -5,6 +5,8 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.math.BigDecimal;
@Getter
@Setter
@AllArgsConstructor
@ -12,5 +14,5 @@ import lombok.Setter;
public class GetUserDto {
private String keycloakId;
private String username;
private float balance;
private BigDecimal balance;
}