Compare commits
2 commits
28f7b15d4c
...
30b4cd4d8d
Author | SHA1 | Date | |
---|---|---|---|
30b4cd4d8d | |||
f2d447abeb |
14 changed files with 605 additions and 764 deletions
|
@ -39,7 +39,7 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.stripe:stripe-java:29.0.0")
|
||||
implementation("com.stripe:stripe-java:20.136.0")
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
compileOnly("org.projectlombok:lombok")
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
GET http://localhost:8080/lootboxes
|
||||
Authorization: Bearer {{token}}
|
||||
Content-Type: application/json
|
||||
|
||||
###
|
||||
|
||||
POST http://localhost:8080/lootboxes/2
|
||||
Authorization: Bearer {{token}}
|
||||
Content-Type: application/json
|
|
@ -1,20 +1,10 @@
|
|||
package de.szut.casino;
|
||||
|
||||
import de.szut.casino.lootboxes.LootBoxEntity;
|
||||
import de.szut.casino.lootboxes.LootBoxRepository;
|
||||
import de.szut.casino.lootboxes.RewardEntity;
|
||||
import de.szut.casino.lootboxes.RewardRepository;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootApplication
|
||||
public class CasinoApplication {
|
||||
|
||||
|
@ -26,65 +16,4 @@ public class CasinoApplication {
|
|||
public static RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner initData(LootBoxRepository lootBoxRepository, RewardRepository rewardRepository) {
|
||||
return _ -> {
|
||||
if (lootBoxRepository.count() == 0) {
|
||||
LootBoxEntity basicLootBox = new LootBoxEntity();
|
||||
basicLootBox.setName("Basic LootBox");
|
||||
basicLootBox.setPrice(new BigDecimal("2"));
|
||||
basicLootBox.setRewards(new ArrayList<>()); // Initialize the list
|
||||
|
||||
LootBoxEntity premiumLootBox = new LootBoxEntity();
|
||||
premiumLootBox.setName("Premium LootBox");
|
||||
premiumLootBox.setPrice(new BigDecimal("5"));
|
||||
premiumLootBox.setRewards(new ArrayList<>()); // Initialize the list
|
||||
|
||||
lootBoxRepository.saveAll(Arrays.asList(basicLootBox, premiumLootBox));
|
||||
|
||||
RewardEntity commonReward = new RewardEntity();
|
||||
commonReward.setValue(new BigDecimal("0.50"));
|
||||
commonReward.setProbability(new BigDecimal("0.7"));
|
||||
|
||||
RewardEntity rareReward = new RewardEntity();
|
||||
rareReward.setValue(new BigDecimal("2.00"));
|
||||
rareReward.setProbability(new BigDecimal("0.25"));
|
||||
|
||||
RewardEntity epicReward = new RewardEntity();
|
||||
epicReward.setValue(new BigDecimal("5.00"));
|
||||
epicReward.setProbability(new BigDecimal("0.5"));
|
||||
|
||||
RewardEntity premiumCommon = new RewardEntity();
|
||||
premiumCommon.setValue(new BigDecimal("2.00"));
|
||||
premiumCommon.setProbability(new BigDecimal("0.6"));
|
||||
|
||||
RewardEntity premiumRare = new RewardEntity();
|
||||
premiumRare.setValue(new BigDecimal("5.00"));
|
||||
premiumRare.setProbability(new BigDecimal("0.3"));
|
||||
|
||||
RewardEntity legendaryReward = new RewardEntity();
|
||||
legendaryReward.setValue(new BigDecimal("15.00"));
|
||||
legendaryReward.setProbability(new BigDecimal("0.10"));
|
||||
|
||||
rewardRepository.saveAll(Arrays.asList(
|
||||
commonReward, rareReward, epicReward,
|
||||
premiumCommon, premiumRare, legendaryReward
|
||||
));
|
||||
|
||||
basicLootBox.getRewards().add(commonReward);
|
||||
basicLootBox.getRewards().add(premiumRare);
|
||||
|
||||
premiumLootBox.getRewards().add(premiumCommon);
|
||||
premiumLootBox.getRewards().add(premiumRare);
|
||||
premiumLootBox.getRewards().add(legendaryReward);
|
||||
|
||||
lootBoxRepository.saveAll(Arrays.asList(basicLootBox, premiumLootBox));
|
||||
|
||||
System.out.println("Initial LootBoxes and rewards created successfully");
|
||||
} else {
|
||||
System.out.println("LootBoxes already exist, skipping initialization");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,14 +52,10 @@ public class DepositController {
|
|||
|
||||
SessionCreateParams params = SessionCreateParams.builder()
|
||||
.addLineItem(SessionCreateParams.LineItem.builder()
|
||||
.setPriceData(SessionCreateParams.LineItem.PriceData.builder()
|
||||
.setCurrency("EUR")
|
||||
.setUnitAmount((long) amountDto.getAmount() * 100)
|
||||
.setProductData(SessionCreateParams.LineItem.PriceData.ProductData.builder()
|
||||
.setName("Einzahlung")
|
||||
.build())
|
||||
.build())
|
||||
.setAmount((long) amountDto.getAmount() * 100)
|
||||
.setCurrency("EUR")
|
||||
.setQuantity(1L)
|
||||
.setName("Einzahlung")
|
||||
.build())
|
||||
.setSuccessUrl(frontendHost+"/home?success=true")
|
||||
.setCancelUrl(frontendHost+"/home?success=false")
|
||||
|
|
|
@ -40,7 +40,7 @@ public class TransactionService {
|
|||
.build();
|
||||
Session checkoutSession = Session.retrieve(sessionID, params, null);
|
||||
|
||||
if (!"paid".equals(checkoutSession.getPaymentStatus())) {
|
||||
if (!Objects.equals(checkoutSession.getPaymentStatus(), "paid")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -53,12 +53,10 @@ public class TransactionService {
|
|||
transaction.setStatus(TransactionStatus.SUCCEEDED);
|
||||
|
||||
UserEntity user = transaction.getUser();
|
||||
Long amountTotal = checkoutSession.getAmountTotal();
|
||||
if (amountTotal != null) {
|
||||
user.addBalance(amountTotal);
|
||||
}
|
||||
user.addBalance(checkoutSession.getAmountTotal());
|
||||
|
||||
userRepository.save(user);
|
||||
transactionRepository.save(transaction);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,18 +51,12 @@ public class WebhookController {
|
|||
switch (event.getType()) {
|
||||
case "checkout.session.completed":
|
||||
case "checkout.session.async_payment_succeeded":
|
||||
EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();
|
||||
|
||||
if (dataObjectDeserializer.getObject().isPresent()) {
|
||||
Session session = (Session) dataObjectDeserializer.getObject().get();
|
||||
this.transactionService.fulfillCheckout(session.getId());
|
||||
} else {
|
||||
logger.error("Failed to deserialize webhook event data");
|
||||
}
|
||||
Session session = (Session) event.getData().getObject();
|
||||
|
||||
this.transactionService.fulfillCheckout(session.getId());
|
||||
break;
|
||||
default:
|
||||
// No action needed for other event types
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return ResponseEntity.ok().body(null);
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
package de.szut.casino.lootboxes;
|
||||
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import de.szut.casino.user.UserRepository;
|
||||
import de.szut.casino.user.UserService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
public class LootBoxController {
|
||||
private final LootBoxRepository lootBoxRepository;
|
||||
private final UserService userService;
|
||||
private final LootBoxService lootBoxService;
|
||||
|
||||
public LootBoxController(LootBoxRepository lootBoxRepository, UserRepository userRepository, UserService userService, LootBoxService lootBoxService) {
|
||||
this.lootBoxRepository = lootBoxRepository;
|
||||
this.userService = userService;
|
||||
this.lootBoxService = lootBoxService;
|
||||
}
|
||||
|
||||
@GetMapping("/lootboxes")
|
||||
public List<LootBoxEntity> getAllLootBoxes() {
|
||||
return lootBoxRepository.findAll();
|
||||
}
|
||||
|
||||
@PostMapping("/lootboxes/{id}")
|
||||
public ResponseEntity<Object> purchaseLootBox(@PathVariable Long id, @RequestHeader("Authorization") String token) {
|
||||
Optional<LootBoxEntity> optionalLootBox = lootBoxRepository.findById(id);
|
||||
if (optionalLootBox.isEmpty()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
LootBoxEntity lootBox = optionalLootBox.get();
|
||||
|
||||
Optional<UserEntity> optionalUser = userService.getCurrentUser(token);
|
||||
if (optionalUser.isEmpty()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
||||
if (lootBoxService.hasSufficientBalance(user, lootBox.getPrice())) {
|
||||
Map<String, String> errorResponse = new HashMap<>();
|
||||
errorResponse.put("error", "Insufficient balance");
|
||||
return ResponseEntity.badRequest().body(errorResponse);
|
||||
}
|
||||
|
||||
RewardEntity reward = lootBoxService.determineReward(lootBox);
|
||||
lootBoxService.handleBalance(user, lootBox, reward);
|
||||
|
||||
return ResponseEntity.ok(reward);
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package de.szut.casino.lootboxes;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import de.szut.casino.blackjack.CardEntity;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.SQLRestriction;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LootBoxEntity {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Column(precision = 19, scale = 2)
|
||||
private BigDecimal price;
|
||||
|
||||
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
|
||||
@JoinTable(
|
||||
name = "lootbox_reward",
|
||||
joinColumns = @JoinColumn(name = "lootbox_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "reward_id")
|
||||
)
|
||||
private List<RewardEntity> rewards = new ArrayList<>();
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package de.szut.casino.lootboxes;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface LootBoxRepository extends JpaRepository<LootBoxEntity, Long> {
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package de.szut.casino.lootboxes;
|
||||
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import de.szut.casino.user.UserRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Service
|
||||
public class LootBoxService {
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public LootBoxService(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
public boolean hasSufficientBalance(UserEntity user, BigDecimal price) {
|
||||
return user.getBalance().compareTo(price) < 0;
|
||||
}
|
||||
|
||||
public RewardEntity determineReward(LootBoxEntity lootBox) {
|
||||
double randomValue = Math.random();
|
||||
BigDecimal cumulativeProbability = BigDecimal.ZERO;
|
||||
|
||||
for (RewardEntity reward : lootBox.getRewards()) {
|
||||
cumulativeProbability = cumulativeProbability.add(reward.getProbability());
|
||||
if (randomValue <= cumulativeProbability.doubleValue()) {
|
||||
return reward;
|
||||
}
|
||||
}
|
||||
|
||||
return lootBox.getRewards().getLast();
|
||||
}
|
||||
|
||||
public void handleBalance(UserEntity user, LootBoxEntity lootBox, RewardEntity reward) {
|
||||
user.setBalance(user.getBalance().subtract(lootBox.getPrice()));
|
||||
user.setBalance(user.getBalance().add(reward.getValue()));
|
||||
userRepository.save(user);
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package de.szut.casino.lootboxes;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
public class RewardEntity {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Column(precision = 19, scale = 2)
|
||||
private BigDecimal value;
|
||||
|
||||
@Column(precision = 5, scale = 2)
|
||||
private BigDecimal probability;
|
||||
|
||||
@ManyToMany(mappedBy = "rewards")
|
||||
@JsonBackReference
|
||||
private List<LootBoxEntity> lootBoxes = new ArrayList<>();
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package de.szut.casino.lootboxes;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface RewardRepository extends JpaRepository<RewardEntity, Long> {
|
||||
}
|
1029
frontend/bun.lock
1029
frontend/bun.lock
File diff suppressed because it is too large
Load diff
|
@ -9,42 +9,40 @@
|
|||
"test": "bunx @angular/cli test",
|
||||
"format": "prettier --write \"src/**/*.{ts,html,css,scss}\"",
|
||||
"format:check": "prettier --check \"src/**/*.{ts,html,css,scss}\"",
|
||||
"lint": "bunx @angular/cli lint"
|
||||
"lint": "ng lint"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^19.0.0",
|
||||
"@angular/cdk": "~19.2.0",
|
||||
"@angular/common": "^19.0.0",
|
||||
"@angular/compiler": "^19.2.4",
|
||||
"@angular/core": "^19.0.0",
|
||||
"@angular/forms": "^19.0.0",
|
||||
"@angular/platform-browser": "^19.0.0",
|
||||
"@angular/platform-browser-dynamic": "^19.0.0",
|
||||
"@angular/router": "^19.0.0",
|
||||
"@angular/animations": "^18.2.0",
|
||||
"@angular/cdk": "~18.2.14",
|
||||
"@angular/common": "^18.2.0",
|
||||
"@angular/compiler": "^18.2.0",
|
||||
"@angular/core": "^18.2.0",
|
||||
"@angular/forms": "^18.2.0",
|
||||
"@angular/platform-browser": "^18.2.0",
|
||||
"@angular/platform-browser-dynamic": "^18.2.0",
|
||||
"@angular/router": "^18.2.0",
|
||||
"@fortawesome/angular-fontawesome": "^1.0.0",
|
||||
"@fortawesome/fontawesome-svg-core": "^6.7.2",
|
||||
"@fortawesome/free-brands-svg-icons": "^6.7.2",
|
||||
"@fortawesome/free-solid-svg-icons": "^6.7.2",
|
||||
"@stripe/stripe-js": "^7.0.0",
|
||||
"@stripe/stripe-js": "^5.6.0",
|
||||
"@tailwindcss/postcss": "^4.0.3",
|
||||
"ajv": "8.17.1",
|
||||
"ajv-formats": "3.0.1",
|
||||
"countup.js": "^2.8.0",
|
||||
"gsap": "^3.12.7",
|
||||
"keycloak-angular": "^19.0.0",
|
||||
"keycloak-js": "^26.0.0",
|
||||
"keycloak-angular": "^16.0.1",
|
||||
"keycloak-js": "^25.0.5",
|
||||
"postcss": "^8.5.1",
|
||||
"rxjs": "~7.8.2",
|
||||
"rxjs": "~7.8.0",
|
||||
"tailwindcss": "^4.0.3",
|
||||
"tslib": "^2.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "^19.0.0",
|
||||
"@angular/cli": "^19.2.5",
|
||||
"@angular/compiler-cli": "^19.0.0",
|
||||
"@angular-devkit/build-angular": "^18.2.2",
|
||||
"@angular/cli": "^18.2.2",
|
||||
"@angular/compiler-cli": "^18.2.0",
|
||||
"@types/jasmine": "~5.1.0",
|
||||
"angular-eslint": "19.3.0",
|
||||
"angular-eslint": "19.2.1",
|
||||
"eslint": "^9.20.0",
|
||||
"jasmine-core": "~5.6.0",
|
||||
"karma": "~6.4.0",
|
||||
|
@ -53,7 +51,7 @@
|
|||
"karma-jasmine": "~5.1.0",
|
||||
"karma-jasmine-html-reporter": "~2.1.0",
|
||||
"prettier": "^3.4.2",
|
||||
"typescript": "~5.8.0",
|
||||
"typescript-eslint": "8.29.0"
|
||||
"typescript": "~5.5.0",
|
||||
"typescript-eslint": "8.26.1"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue