refactor: Change balance type to bigdecimal for better precision
This commit is contained in:
parent
9c5e05f29d
commit
aef0f09d09
5 changed files with 23 additions and 7 deletions
|
@ -16,3 +16,12 @@ Authorization: Bearer {{token}}
|
||||||
"username": "john.doe"
|
"username": "john.doe"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
### Deposit
|
||||||
|
POST http://localhost:8080/deposit/checkout
|
||||||
|
Content-Type: application/json
|
||||||
|
Origin: http://localhost:8080
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"amount": 60.12
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
|
@ -20,9 +21,11 @@ public class UserEntity {
|
||||||
@Column(unique = true)
|
@Column(unique = true)
|
||||||
private String keycloakId;
|
private String keycloakId;
|
||||||
private String username;
|
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.keycloakId = keycloakId;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.balance = balance;
|
this.balance = balance;
|
||||||
|
|
|
@ -4,6 +4,8 @@ import de.szut.casino.user.dto.CreateUserDto;
|
||||||
import de.szut.casino.user.dto.GetUserDto;
|
import de.szut.casino.user.dto.GetUserDto;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserMappingService {
|
public class UserMappingService {
|
||||||
public GetUserDto mapToGetUserDto(UserEntity user) {
|
public GetUserDto mapToGetUserDto(UserEntity user) {
|
||||||
|
@ -11,7 +13,6 @@ public class UserMappingService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserEntity mapToUserEntity(CreateUserDto createUserDto) {
|
public UserEntity mapToUserEntity(CreateUserDto createUserDto) {
|
||||||
return new UserEntity(createUserDto.getKeycloakId(), createUserDto.getUsername(), 0);
|
return new UserEntity(createUserDto.getKeycloakId(), createUserDto.getUsername(), BigDecimal.ZERO); }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -12,5 +14,5 @@ import lombok.Setter;
|
||||||
public class GetUserDto {
|
public class GetUserDto {
|
||||||
private String keycloakId;
|
private String keycloakId;
|
||||||
private String username;
|
private String username;
|
||||||
private float balance;
|
private BigDecimal balance;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,11 @@ export class UserService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getOrCreateUser(userProfile: KeycloakProfile) {
|
public async getOrCreateUser(userProfile: KeycloakProfile): Promise<User | undefined | null> {
|
||||||
if (userProfile.id == null) {
|
if (userProfile.id == null) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.getUser(userProfile.id)
|
return await this.getUser(userProfile.id)
|
||||||
.toPromise()
|
.toPromise()
|
||||||
.then(async (user) => {
|
.then(async (user) => {
|
||||||
|
|
Reference in a new issue