From aef0f09d09fc935d98c6ada158bf9344634c110f Mon Sep 17 00:00:00 2001
From: Phan Huy Tran
Date: Wed, 26 Feb 2025 11:03:12 +0100
Subject: [PATCH 1/2] refactor: Change balance type to bigdecimal for better
precision
---
backend/requests/user.http | 9 +++++++++
.../src/main/java/de/szut/casino/user/UserEntity.java | 7 +++++--
.../java/de/szut/casino/user/UserMappingService.java | 5 +++--
.../main/java/de/szut/casino/user/dto/GetUserDto.java | 4 +++-
frontend/src/app/service/user.service.ts | 5 +++--
5 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/backend/requests/user.http b/backend/requests/user.http
index 3d466be..5e7aa5c 100644
--- a/backend/requests/user.http
+++ b/backend/requests/user.http
@@ -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
+}
\ No newline at end of file
diff --git a/backend/src/main/java/de/szut/casino/user/UserEntity.java b/backend/src/main/java/de/szut/casino/user/UserEntity.java
index f6c1a5b..42b08ce 100644
--- a/backend/src/main/java/de/szut/casino/user/UserEntity.java
+++ b/backend/src/main/java/de/szut/casino/user/UserEntity.java
@@ -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;
diff --git a/backend/src/main/java/de/szut/casino/user/UserMappingService.java b/backend/src/main/java/de/szut/casino/user/UserMappingService.java
index e0183ec..80f5546 100644
--- a/backend/src/main/java/de/szut/casino/user/UserMappingService.java
+++ b/backend/src/main/java/de/szut/casino/user/UserMappingService.java
@@ -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); }
}
diff --git a/backend/src/main/java/de/szut/casino/user/dto/GetUserDto.java b/backend/src/main/java/de/szut/casino/user/dto/GetUserDto.java
index fb690af..8521029 100644
--- a/backend/src/main/java/de/szut/casino/user/dto/GetUserDto.java
+++ b/backend/src/main/java/de/szut/casino/user/dto/GetUserDto.java
@@ -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;
}
diff --git a/frontend/src/app/service/user.service.ts b/frontend/src/app/service/user.service.ts
index ba6bead..caa9bf9 100644
--- a/frontend/src/app/service/user.service.ts
+++ b/frontend/src/app/service/user.service.ts
@@ -21,10 +21,11 @@ export class UserService {
});
}
- public async getOrCreateUser(userProfile: KeycloakProfile) {
+ public async getOrCreateUser(userProfile: KeycloakProfile): Promise {
if (userProfile.id == null) {
- return;
+ return null;
}
+
return await this.getUser(userProfile.id)
.toPromise()
.then(async (user) => {
From aa6ec4397ff7fd2b3d38589a8f571177ddaca8ef Mon Sep 17 00:00:00 2001
From: Phan Huy Tran
Date: Wed, 26 Feb 2025 11:06:40 +0100
Subject: [PATCH 2/2] revert: revert
---
frontend/src/app/service/user.service.ts | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/frontend/src/app/service/user.service.ts b/frontend/src/app/service/user.service.ts
index caa9bf9..ba6bead 100644
--- a/frontend/src/app/service/user.service.ts
+++ b/frontend/src/app/service/user.service.ts
@@ -21,11 +21,10 @@ export class UserService {
});
}
- public async getOrCreateUser(userProfile: KeycloakProfile): Promise {
+ public async getOrCreateUser(userProfile: KeycloakProfile) {
if (userProfile.id == null) {
- return null;
+ return;
}
-
return await this.getUser(userProfile.id)
.toPromise()
.then(async (user) => {