From c0b4d1c46e50c6d43446680c426732c639726048 Mon Sep 17 00:00:00 2001 From: Jan K9f Date: Wed, 2 Apr 2025 08:57:00 +0200 Subject: [PATCH 01/12] refactor: update import paths for better readability --- frontend/src/app/feature/deposit/deposit.component.ts | 6 +++--- .../src/app/feature/game/blackjack/blackjack.component.ts | 4 ++-- .../components/dealer-hand/dealer-hand.component.ts | 2 +- .../components/game-controls/game-controls.component.ts | 2 +- .../components/player-hand/player-hand.component.ts | 2 +- .../components/playing-card/playing-card.component.ts | 4 ++-- .../feature/game/blackjack/services/blackjack.service.ts | 2 +- frontend/tsconfig.json | 7 +++++++ 8 files changed, 18 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/feature/deposit/deposit.component.ts b/frontend/src/app/feature/deposit/deposit.component.ts index bb38fc9..6cbae07 100644 --- a/frontend/src/app/feature/deposit/deposit.component.ts +++ b/frontend/src/app/feature/deposit/deposit.component.ts @@ -16,12 +16,12 @@ import { } from '@angular/core'; import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; import { loadStripe, Stripe } from '@stripe/stripe-js'; -import { DepositService } from '../../service/deposit.service'; import { debounceTime } from 'rxjs'; -import { environment } from '../../../environments/environment'; import { NgIf } from '@angular/common'; -import { ModalAnimationService } from '../../shared/services/modal-animation.service'; import gsap from 'gsap'; +import { DepositService } from '@service/deposit.service'; +import { environment } from '@environments/environment'; +import { ModalAnimationService } from '@shared/services/modal-animation.service'; @Component({ selector: 'app-deposit', diff --git a/frontend/src/app/feature/game/blackjack/blackjack.component.ts b/frontend/src/app/feature/game/blackjack/blackjack.component.ts index 5b5ad42..ab34438 100644 --- a/frontend/src/app/feature/game/blackjack/blackjack.component.ts +++ b/frontend/src/app/feature/game/blackjack/blackjack.component.ts @@ -1,8 +1,6 @@ import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { NavbarComponent } from '../../../shared/components/navbar/navbar.component'; import { Router } from '@angular/router'; -import { UserService } from '../../../service/user.service'; import { PlayingCardComponent } from './components/playing-card/playing-card.component'; import { DealerHandComponent } from './components/dealer-hand/dealer-hand.component'; import { PlayerHandComponent } from './components/player-hand/player-hand.component'; @@ -12,6 +10,8 @@ import { Card, BlackjackGame } from './models/blackjack.model'; import { BlackjackService } from './services/blackjack.service'; import { HttpErrorResponse } from '@angular/common/http'; import { GameResultComponent } from './components/game-result/game-result.component'; +import { NavbarComponent } from '@shared/components/navbar/navbar.component'; +import { UserService } from '@service/user.service'; @Component({ selector: 'app-blackjack', diff --git a/frontend/src/app/feature/game/blackjack/components/dealer-hand/dealer-hand.component.ts b/frontend/src/app/feature/game/blackjack/components/dealer-hand/dealer-hand.component.ts index 50ff0cf..45174ca 100644 --- a/frontend/src/app/feature/game/blackjack/components/dealer-hand/dealer-hand.component.ts +++ b/frontend/src/app/feature/game/blackjack/components/dealer-hand/dealer-hand.component.ts @@ -1,7 +1,7 @@ import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core'; import { CommonModule } from '@angular/common'; +import { Card } from '@blackjack/models/blackjack.model'; import { PlayingCardComponent } from '../playing-card/playing-card.component'; -import { Card } from '../../models/blackjack.model'; @Component({ selector: 'app-dealer-hand', diff --git a/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts b/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts index 9922309..69ce817 100644 --- a/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts +++ b/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts @@ -1,6 +1,6 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { Card } from '../../models/blackjack.model'; +import { Card } from '@blackjack/models/blackjack.model'; @Component({ selector: 'app-game-controls', diff --git a/frontend/src/app/feature/game/blackjack/components/player-hand/player-hand.component.ts b/frontend/src/app/feature/game/blackjack/components/player-hand/player-hand.component.ts index d47114f..b921a3c 100644 --- a/frontend/src/app/feature/game/blackjack/components/player-hand/player-hand.component.ts +++ b/frontend/src/app/feature/game/blackjack/components/player-hand/player-hand.component.ts @@ -1,7 +1,7 @@ import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core'; import { CommonModule } from '@angular/common'; import { PlayingCardComponent } from '../playing-card/playing-card.component'; -import { Card } from '../../models/blackjack.model'; +import { Card } from '@blackjack/models/blackjack.model'; @Component({ selector: 'app-player-hand', diff --git a/frontend/src/app/feature/game/blackjack/components/playing-card/playing-card.component.ts b/frontend/src/app/feature/game/blackjack/components/playing-card/playing-card.component.ts index 662ddc6..a367a39 100644 --- a/frontend/src/app/feature/game/blackjack/components/playing-card/playing-card.component.ts +++ b/frontend/src/app/feature/game/blackjack/components/playing-card/playing-card.component.ts @@ -8,8 +8,8 @@ import { SimpleChanges, } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { suitSymbols, Suit } from '../../models/blackjack.model'; import { gsap } from 'gsap'; +import { Suit, suitSymbols } from '@blackjack/models/blackjack.model'; @Component({ selector: 'app-playing-card', @@ -58,7 +58,7 @@ export class PlayingCardComponent implements AfterViewInit, OnChanges { @Input({ required: true }) hidden!: boolean; @Input() isNew = false; - constructor(private elementRef: ElementRef) {} + constructor(private elementRef: ElementRef) { } get isRedSuit(): boolean { return this.suit === 'HEARTS' || this.suit === 'DIAMONDS'; diff --git a/frontend/src/app/feature/game/blackjack/services/blackjack.service.ts b/frontend/src/app/feature/game/blackjack/services/blackjack.service.ts index eecaf45..ca3f218 100644 --- a/frontend/src/app/feature/game/blackjack/services/blackjack.service.ts +++ b/frontend/src/app/feature/game/blackjack/services/blackjack.service.ts @@ -1,7 +1,7 @@ import { Injectable, inject } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable, catchError } from 'rxjs'; -import { BlackjackGame } from '../models/blackjack.model'; +import { BlackjackGame } from '@blackjack/models/blackjack.model'; @Injectable({ providedIn: 'root', diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index a8bb65b..efb8a7f 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -3,6 +3,13 @@ { "compileOnSave": false, "compilerOptions": { + "baseUrl": "./src", + "paths": { + "@service/*": ["app/service/*"] + "@environments/*": ["environments/*"] + "@shared/*": ["app/shared/*"] + "@blackjack/*": ["app/feature/game/blackjack/*"] + }, "outDir": "./dist/out-tsc", "strict": true, "noImplicitOverride": true, From 01989ae5bcfbe12985baf88f0bea022b012bac14 Mon Sep 17 00:00:00 2001 From: Jan K9f Date: Wed, 2 Apr 2025 09:02:14 +0200 Subject: [PATCH 02/12] refactor: update imports to use absolute paths --- frontend/src/app/feature/home/home.component.ts | 10 +++++----- frontend/src/app/feature/landing/landing.component.ts | 1 - .../feature/login-success/login-success.component.ts | 2 +- .../components/confirmation/confirmation.component.ts | 4 ++-- .../app/shared/components/navbar/navbar.component.ts | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/feature/home/home.component.ts b/frontend/src/app/feature/home/home.component.ts index b3237ee..3104b53 100644 --- a/frontend/src/app/feature/home/home.component.ts +++ b/frontend/src/app/feature/home/home.component.ts @@ -1,11 +1,11 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; -import { NavbarComponent } from '../../shared/components/navbar/navbar.component'; import { CurrencyPipe, NgFor } from '@angular/common'; -import { Game } from '../../model/Game'; -import { Transaction } from '../../model/Transaction'; import { DepositComponent } from '../deposit/deposit.component'; -import { ConfirmationComponent } from '../../shared/components/confirmation/confirmation.component'; import { ActivatedRoute, Router } from '@angular/router'; +import { ConfirmationComponent } from '@shared/components/confirmation/confirmation.component'; +import { Transaction } from 'app/model/Transaction'; +import { NavbarComponent } from '@shared/components/navbar/navbar.component'; +import { Game } from 'app/model/Game'; @Component({ selector: 'app-homepage', @@ -21,7 +21,7 @@ export default class HomeComponent implements OnInit { constructor( public route: ActivatedRoute, public router: Router - ) {} + ) { } ngOnInit() { this.isDepositSuccessful = this.route.snapshot.queryParams['success'] == 'true'; diff --git a/frontend/src/app/feature/landing/landing.component.ts b/frontend/src/app/feature/landing/landing.component.ts index 7fa92b6..5e3f747 100644 --- a/frontend/src/app/feature/landing/landing.component.ts +++ b/frontend/src/app/feature/landing/landing.component.ts @@ -1,5 +1,4 @@ import { ChangeDetectionStrategy, Component, OnInit, OnDestroy } from '@angular/core'; -import { NavbarComponent } from '../../shared/components/navbar/navbar.component'; import { NgFor } from '@angular/common'; @Component({ diff --git a/frontend/src/app/feature/login-success/login-success.component.ts b/frontend/src/app/feature/login-success/login-success.component.ts index 067afe6..3b506ca 100644 --- a/frontend/src/app/feature/login-success/login-success.component.ts +++ b/frontend/src/app/feature/login-success/login-success.component.ts @@ -1,7 +1,7 @@ import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/core'; -import { UserService } from '../../service/user.service'; import { KeycloakService } from 'keycloak-angular'; import { Router } from '@angular/router'; +import { UserService } from '@service/user.service'; @Component({ selector: 'app-login-success', diff --git a/frontend/src/app/shared/components/confirmation/confirmation.component.ts b/frontend/src/app/shared/components/confirmation/confirmation.component.ts index 9c26f22..ed84f2d 100644 --- a/frontend/src/app/shared/components/confirmation/confirmation.component.ts +++ b/frontend/src/app/shared/components/confirmation/confirmation.component.ts @@ -8,7 +8,7 @@ import { AfterViewInit, OnDestroy, } from '@angular/core'; -import { ModalAnimationService } from '../../services/modal-animation.service'; +import { ModalAnimationService } from '@shared/services/modal-animation.service'; import gsap from 'gsap'; @Component({ @@ -23,7 +23,7 @@ export class ConfirmationComponent implements AfterViewInit, OnDestroy { @ViewChild('modalBg') modalBg!: ElementRef; @ViewChild('modalCard') modalCard!: ElementRef; - constructor(private modalAnimationService: ModalAnimationService) {} + constructor(private modalAnimationService: ModalAnimationService) { } ngAfterViewInit() { if (this.successful) { diff --git a/frontend/src/app/shared/components/navbar/navbar.component.ts b/frontend/src/app/shared/components/navbar/navbar.component.ts index a6bbc15..adf7b78 100644 --- a/frontend/src/app/shared/components/navbar/navbar.component.ts +++ b/frontend/src/app/shared/components/navbar/navbar.component.ts @@ -1,9 +1,9 @@ import { ChangeDetectionStrategy, Component, inject, OnInit, signal } from '@angular/core'; import { RouterModule } from '@angular/router'; import { KeycloakService } from 'keycloak-angular'; -import { UserService } from '../../../service/user.service'; import { CurrencyPipe } from '@angular/common'; +import { UserService } from '@service/user.service'; @Component({ selector: 'app-navbar', templateUrl: './navbar.component.html', From fb6655a1960ab125d2e1b23896abdcc2e8088045 Mon Sep 17 00:00:00 2001 From: Jan K9f Date: Wed, 2 Apr 2025 09:03:36 +0200 Subject: [PATCH 03/12] style: format constructor style in components --- .../blackjack/components/playing-card/playing-card.component.ts | 2 +- frontend/src/app/feature/home/home.component.ts | 2 +- .../shared/components/confirmation/confirmation.component.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/feature/game/blackjack/components/playing-card/playing-card.component.ts b/frontend/src/app/feature/game/blackjack/components/playing-card/playing-card.component.ts index a367a39..8ae8824 100644 --- a/frontend/src/app/feature/game/blackjack/components/playing-card/playing-card.component.ts +++ b/frontend/src/app/feature/game/blackjack/components/playing-card/playing-card.component.ts @@ -58,7 +58,7 @@ export class PlayingCardComponent implements AfterViewInit, OnChanges { @Input({ required: true }) hidden!: boolean; @Input() isNew = false; - constructor(private elementRef: ElementRef) { } + constructor(private elementRef: ElementRef) {} get isRedSuit(): boolean { return this.suit === 'HEARTS' || this.suit === 'DIAMONDS'; diff --git a/frontend/src/app/feature/home/home.component.ts b/frontend/src/app/feature/home/home.component.ts index 3104b53..eb12454 100644 --- a/frontend/src/app/feature/home/home.component.ts +++ b/frontend/src/app/feature/home/home.component.ts @@ -21,7 +21,7 @@ export default class HomeComponent implements OnInit { constructor( public route: ActivatedRoute, public router: Router - ) { } + ) {} ngOnInit() { this.isDepositSuccessful = this.route.snapshot.queryParams['success'] == 'true'; diff --git a/frontend/src/app/shared/components/confirmation/confirmation.component.ts b/frontend/src/app/shared/components/confirmation/confirmation.component.ts index ed84f2d..8bc884a 100644 --- a/frontend/src/app/shared/components/confirmation/confirmation.component.ts +++ b/frontend/src/app/shared/components/confirmation/confirmation.component.ts @@ -23,7 +23,7 @@ export class ConfirmationComponent implements AfterViewInit, OnDestroy { @ViewChild('modalBg') modalBg!: ElementRef; @ViewChild('modalCard') modalCard!: ElementRef; - constructor(private modalAnimationService: ModalAnimationService) { } + constructor(private modalAnimationService: ModalAnimationService) {} ngAfterViewInit() { if (this.successful) { From b0b358ae9ffe162d8f2c3c733208c5862076d8e6 Mon Sep 17 00:00:00 2001 From: Jan K9f Date: Wed, 2 Apr 2025 09:05:33 +0200 Subject: [PATCH 04/12] style(tsconfig): fix path configuration formatting --- frontend/tsconfig.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index efb8a7f..07e5492 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -5,10 +5,10 @@ "compilerOptions": { "baseUrl": "./src", "paths": { - "@service/*": ["app/service/*"] - "@environments/*": ["environments/*"] - "@shared/*": ["app/shared/*"] - "@blackjack/*": ["app/feature/game/blackjack/*"] + "@service/*": "app/service/*", + "@environments/*": "environments/*", + "@shared/*": "app/shared/*", + "@blackjack/*": "app/feature/game/blackjack/*" }, "outDir": "./dist/out-tsc", "strict": true, From 732d475a8452ea043dce02da30af56a83c17776e Mon Sep 17 00:00:00 2001 From: Jan-Marlon Leibl Date: Wed, 2 Apr 2025 09:06:44 +0200 Subject: [PATCH 05/12] feat: add game state enum and refactor game components --- .../casino/blackjack/BlackJackGameEntity.java | 4 - .../de/szut/casino/blackjack/CardEntity.java | 4 - frontend/src/app/enum/gameState.ts | 6 ++ .../game/blackjack/blackjack.component.html | 2 +- .../game/blackjack/blackjack.component.ts | 15 ++-- .../game-controls/game-controls.component.ts | 82 +++---------------- .../game-result/game-result.component.css | 1 - .../game-result/game-result.component.spec.ts | 22 ----- .../game-result/game-result.component.ts | 10 +-- .../services/game-controls.service.ts | 74 +++++++++++++++++ 10 files changed, 105 insertions(+), 115 deletions(-) create mode 100644 frontend/src/app/enum/gameState.ts delete mode 100644 frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.css delete mode 100644 frontend/src/app/feature/game/blackjack/components/game-result/game-result.component.spec.ts create mode 100644 frontend/src/app/feature/game/blackjack/services/game-controls.service.ts diff --git a/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameEntity.java b/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameEntity.java index 0dbfcc0..4f22c9d 100644 --- a/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameEntity.java +++ b/backend/src/main/java/de/szut/casino/blackjack/BlackJackGameEntity.java @@ -24,10 +24,6 @@ public class BlackJackGameEntity { @GeneratedValue private Long id; - @Version - @JsonIgnore - private Long version; - @ManyToOne @JoinColumn(name = "user_id", nullable = false) @JsonIgnore diff --git a/backend/src/main/java/de/szut/casino/blackjack/CardEntity.java b/backend/src/main/java/de/szut/casino/blackjack/CardEntity.java index 27d09d6..5520b58 100644 --- a/backend/src/main/java/de/szut/casino/blackjack/CardEntity.java +++ b/backend/src/main/java/de/szut/casino/blackjack/CardEntity.java @@ -19,10 +19,6 @@ public class CardEntity { @JsonIgnore private Long id; - @Version - @JsonIgnore - private Long version; - @ManyToOne @JoinColumn(name = "game_id", nullable = false) @JsonBackReference diff --git a/frontend/src/app/enum/gameState.ts b/frontend/src/app/enum/gameState.ts new file mode 100644 index 0000000..b07bf85 --- /dev/null +++ b/frontend/src/app/enum/gameState.ts @@ -0,0 +1,6 @@ +export enum GameState { + PLAYER_WON = 'PLAYER_WON', + IN_PROGRESS = 'IN_PROGRESS', + PLAYER_LOST = 'PLAYER_LOST', + DRAW = 'DRAW', +} \ No newline at end of file diff --git a/frontend/src/app/feature/game/blackjack/blackjack.component.html b/frontend/src/app/feature/game/blackjack/blackjack.component.html index c47d2f6..887aeeb 100644 --- a/frontend/src/app/feature/game/blackjack/blackjack.component.html +++ b/frontend/src/app/feature/game/blackjack/blackjack.component.html @@ -49,5 +49,5 @@ [gameState]="gameState()" [amount]="currentBet()" [show]="showGameResult()" - (close)="onCloseGameResult()" + (gameResultClosed)="onCloseGameResult()" > diff --git a/frontend/src/app/feature/game/blackjack/blackjack.component.ts b/frontend/src/app/feature/game/blackjack/blackjack.component.ts index 5b5ad42..621cbf5 100644 --- a/frontend/src/app/feature/game/blackjack/blackjack.component.ts +++ b/frontend/src/app/feature/game/blackjack/blackjack.component.ts @@ -12,6 +12,7 @@ import { Card, BlackjackGame } from './models/blackjack.model'; import { BlackjackService } from './services/blackjack.service'; import { HttpErrorResponse } from '@angular/common/http'; import { GameResultComponent } from './components/game-result/game-result.component'; +import { GameState } from '../../../enum/gameState'; @Component({ selector: 'app-blackjack', @@ -40,7 +41,7 @@ export default class BlackjackComponent { balance = signal(0); currentGameId = signal(undefined); gameInProgress = signal(false); - gameState = signal('IN_PROGRESS'); + gameState = signal(GameState.IN_PROGRESS); showGameResult = signal(false); isActionInProgress = signal(false); @@ -60,15 +61,15 @@ export default class BlackjackComponent { console.log('Game state update:', game); this.currentGameId.set(game.id); this.currentBet.set(game.bet); - this.gameInProgress.set(game.state === 'IN_PROGRESS'); - this.gameState.set(game.state); + this.gameInProgress.set(game.state === GameState.IN_PROGRESS); + this.gameState.set(game.state as GameState); - const isGameOver = game.state !== 'IN_PROGRESS'; + const isGameOver = game.state !== GameState.IN_PROGRESS; this.dealerCards.set( game.dealerCards.map((card, index) => ({ ...card, - hidden: !isGameOver && index === 1 && game.state === 'IN_PROGRESS', + hidden: !isGameOver && index === 1 && game.state === GameState.IN_PROGRESS, })) ); @@ -127,7 +128,7 @@ export default class BlackjackComponent { onStand(): void { if (!this.currentGameId() || this.isActionInProgress()) return; - if (this.gameState() !== 'IN_PROGRESS') { + if (this.gameState() !== GameState.IN_PROGRESS) { console.log('Cannot stand: game is not in progress'); return; } @@ -151,7 +152,7 @@ export default class BlackjackComponent { onDoubleDown(): void { if (!this.currentGameId() || this.isActionInProgress()) return; - if (this.gameState() !== 'IN_PROGRESS' || this.playerCards().length !== 2) { + if (this.gameState() !== GameState.IN_PROGRESS || this.playerCards().length !== 2) { console.log('Cannot double down: game is not in progress or more than 2 cards'); return; } diff --git a/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts b/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts index 9922309..00a8eca 100644 --- a/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts +++ b/frontend/src/app/feature/game/blackjack/components/game-controls/game-controls.component.ts @@ -1,6 +1,8 @@ import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; import { CommonModule } from '@angular/common'; import { Card } from '../../models/blackjack.model'; +import { GameState } from '../../../../../enum/gameState'; +import { GameControlsService } from '../../services/game-controls.service'; @Component({ selector: 'app-game-controls', @@ -11,10 +13,10 @@ import { Card } from '../../models/blackjack.model';
- Deine Punkte: {{ calculateHandValue(playerCards) }} + Deine Punkte: {{ gameControlsService.calculateHandValue(playerCards) }}
- Status: {{ getStatusText(gameState) }} + Status: {{ gameControlsService.getStatusText(gameState) }}
@@ -22,7 +24,7 @@ import { Card } from '../../models/blackjack.model';