Compare commits
13 commits
Author | SHA1 | Date | |
---|---|---|---|
b07a3a935a | |||
|
0cc8ff50aa | ||
|
6f3f3791c3 | ||
|
66e5d730dd | ||
a677b1fbdb | |||
|
070be95928 | ||
|
d46ec45f4a | ||
|
0eaccb4453 | ||
|
35184807c0 | ||
|
157e774e86 | ||
|
03d67ef362 | ||
|
9817fb95db | ||
|
d6077645d9 |
35 changed files with 350 additions and 83 deletions
|
@ -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 {
|
||||
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
package de.szut.casino.blackjack;
|
||||
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public interface BlackJackGameRepository extends JpaRepository<BlackJackGameEntity, Long> {
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
@Service
|
||||
|
|
|
@ -8,7 +8,6 @@ import de.szut.casino.deposit.dto.AmountDto;
|
|||
import de.szut.casino.deposit.dto.SessionIdDto;
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import de.szut.casino.user.UserRepository;
|
||||
import de.szut.casino.user.UserService;
|
||||
import de.szut.casino.user.dto.KeycloakUserDto;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
@ -16,7 +15,10 @@ import org.springframework.http.HttpEntity;
|
|||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Optional;
|
||||
|
|
|
@ -5,7 +5,7 @@ import jakarta.persistence.*;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
|
@ -26,4 +26,7 @@ public class TransactionEntity {
|
|||
|
||||
@Enumerated(EnumType.STRING)
|
||||
private TransactionStatus status = TransactionStatus.PROCESSING;
|
||||
|
||||
@Column(name = "created_at")
|
||||
private Date createdAt = new Date();
|
||||
}
|
||||
|
|
|
@ -5,10 +5,20 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
|||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public interface TransactionRepository extends JpaRepository<TransactionEntity, Long> {
|
||||
@Query("SELECT t FROM TransactionEntity t WHERE t.sessionId = ?1")
|
||||
Optional<TransactionEntity> findOneBySessionID(String sessionId);
|
||||
|
||||
@Query("SELECT t FROM TransactionEntity t WHERE t.user = ?1")
|
||||
List<TransactionEntity> findAllByUserId(UserEntity id);
|
||||
|
||||
@Query("SELECT t FROM TransactionEntity t WHERE t.user = ?1 ORDER BY t.createdAt DESC LIMIT ?2 OFFSET ?3")
|
||||
List<TransactionEntity> findByUserIdWithLimit(UserEntity userEntity, Integer limit, Integer offset);
|
||||
|
||||
@Query("SELECT COUNT(t) > ?2 + ?3 FROM TransactionEntity t WHERE t.user = ?1")
|
||||
Boolean hasMore(UserEntity userEntity, Integer limit, Integer offset);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import de.szut.casino.user.UserEntity;
|
|||
import de.szut.casino.user.UserRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
|
|
|
@ -1,26 +1,21 @@
|
|||
package de.szut.casino.deposit;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import com.stripe.Stripe;
|
||||
import com.stripe.exception.SignatureVerificationException;
|
||||
import com.stripe.exception.StripeException;
|
||||
import com.stripe.model.*;
|
||||
import com.stripe.model.Event;
|
||||
import com.stripe.model.checkout.Session;
|
||||
import com.stripe.net.Webhook;
|
||||
import com.stripe.param.checkout.SessionRetrieveParams;
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import de.szut.casino.user.UserRepository;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
public class WebhookController {
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
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;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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.NoArgsConstructor;
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
package de.szut.casino.user;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import de.szut.casino.user.dto.CreateUserDto;
|
||||
import de.szut.casino.user.dto.GetUserDto;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package de.szut.casino.user.transaction;
|
||||
|
||||
import de.szut.casino.deposit.TransactionEntity;
|
||||
import de.szut.casino.deposit.TransactionRepository;
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import de.szut.casino.user.UserService;
|
||||
import de.szut.casino.user.transaction.dto.GetTransactionDto;
|
||||
import de.szut.casino.user.transaction.dto.UserTransactionsDto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class GetTransactionService {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private TransactionRepository transactionRepository;
|
||||
|
||||
public UserTransactionsDto getUserTransactionsDto(String authToken, Integer limit, Integer offset) {
|
||||
Optional<UserEntity> user = this.userService.getCurrentUser(authToken);
|
||||
if (user.isPresent()) {
|
||||
List<TransactionEntity> transactionEntities = this.transactionRepository.findByUserIdWithLimit(user.get(), limit, offset);
|
||||
Boolean hasMore = this.transactionRepository.hasMore(user.get(), limit, offset);
|
||||
|
||||
return new UserTransactionsDto(mapTransactionsToDtos(transactionEntities), hasMore);
|
||||
}
|
||||
|
||||
return new UserTransactionsDto(List.of(), false);
|
||||
}
|
||||
|
||||
public List<GetTransactionDto> mapTransactionsToDtos(List<TransactionEntity> transactions) {
|
||||
return transactions.stream()
|
||||
.map(transaction -> new GetTransactionDto(
|
||||
transaction.getAmount(),
|
||||
transaction.getStatus(),
|
||||
transaction.getCreatedAt())
|
||||
).toList();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package de.szut.casino.user.transaction;
|
||||
|
||||
import de.szut.casino.user.transaction.dto.UserTransactionsDto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class TransactionController {
|
||||
|
||||
@Autowired
|
||||
private GetTransactionService transactionService;
|
||||
|
||||
@GetMapping("/user/transactions")
|
||||
public ResponseEntity<UserTransactionsDto> getUserTransactions(
|
||||
@RequestHeader("Authorization") String authToken,
|
||||
@RequestParam(value = "limit", required = false) Integer limit,
|
||||
@RequestParam(value = "offset", required = false) Integer offset
|
||||
) {
|
||||
UserTransactionsDto transactionEntities = this.transactionService.getUserTransactionsDto(authToken, limit, offset);
|
||||
|
||||
return ResponseEntity.ok(transactionEntities);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package de.szut.casino.user.transaction.dto;
|
||||
|
||||
import de.szut.casino.deposit.TransactionStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class GetTransactionDto {
|
||||
public double amount = 0;
|
||||
public TransactionStatus status = TransactionStatus.PROCESSING;
|
||||
public Date createdAt = new Date();
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package de.szut.casino.user.transaction.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class UserTransactionsDto {
|
||||
public List<GetTransactionDto> transactions;
|
||||
public Boolean hasMore;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import { routes } from './app.routes';
|
|||
import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
||||
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
|
||||
import { OAuthStorage, provideOAuthClient } from 'angular-oauth2-oidc';
|
||||
import { httpInterceptor } from './shared/interceptor/http.interceptor';
|
||||
import { httpInterceptor } from '@shared/interceptor/http.interceptor';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
import {
|
||||
AfterViewInit,
|
||||
ChangeDetectionStrategy,
|
||||
ChangeDetectorRef,
|
||||
Component,
|
||||
ElementRef,
|
||||
EventEmitter,
|
||||
inject,
|
||||
Input,
|
||||
OnChanges,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
Output,
|
||||
ViewChild,
|
||||
AfterViewInit,
|
||||
OnDestroy,
|
||||
OnChanges,
|
||||
SimpleChanges,
|
||||
ChangeDetectorRef,
|
||||
ViewChild,
|
||||
} from '@angular/core';
|
||||
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { loadStripe, Stripe } from '@stripe/stripe-js';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { ChangeDetectionStrategy, Component, inject, signal, OnInit } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, inject, OnInit, signal } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Router } from '@angular/router';
|
||||
import { PlayingCardComponent } from './components/playing-card/playing-card.component';
|
||||
|
@ -6,7 +6,7 @@ import { DealerHandComponent } from './components/dealer-hand/dealer-hand.compon
|
|||
import { PlayerHandComponent } from './components/player-hand/player-hand.component';
|
||||
import { GameControlsComponent } from './components/game-controls/game-controls.component';
|
||||
import { GameInfoComponent } from './components/game-info/game-info.component';
|
||||
import { Card, BlackjackGame } from '@blackjack/models/blackjack.model';
|
||||
import { BlackjackGame, Card } from '@blackjack/models/blackjack.model';
|
||||
import { BlackjackService } from '@blackjack/services/blackjack.service';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { GameResultComponent } from '@blackjack/components/game-result/game-result.component';
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import {
|
||||
AfterViewInit,
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
ElementRef,
|
||||
Input,
|
||||
OnChanges,
|
||||
SimpleChanges,
|
||||
ElementRef,
|
||||
ViewChild,
|
||||
AfterViewInit,
|
||||
} from '@angular/core';
|
||||
import { CommonModule, CurrencyPipe } from '@angular/common';
|
||||
import { CountUp } from 'countup.js';
|
||||
|
|
|
@ -5,8 +5,8 @@ import {
|
|||
Input,
|
||||
OnChanges,
|
||||
Output,
|
||||
SimpleChanges,
|
||||
signal,
|
||||
SimpleChanges,
|
||||
} from '@angular/core';
|
||||
import { CommonModule, CurrencyPipe } from '@angular/common';
|
||||
import { FormGroup, ReactiveFormsModule } from '@angular/forms';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { ChangeDetectionStrategy, Component, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
|
||||
import { CommonModule, CurrencyPipe } from '@angular/common';
|
||||
import { animate, style, transition, trigger } from '@angular/animations';
|
||||
import { GameState } from '../../enum/gameState';
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import {
|
||||
AfterViewInit,
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
Input,
|
||||
AfterViewInit,
|
||||
ElementRef,
|
||||
Input,
|
||||
OnChanges,
|
||||
SimpleChanges,
|
||||
} from '@angular/core';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Injectable, inject } from '@angular/core';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable, catchError } from 'rxjs';
|
||||
import { catchError, Observable } from 'rxjs';
|
||||
import { BlackjackGame } from '@blackjack/models/blackjack.model';
|
||||
|
||||
@Injectable({
|
||||
|
|
|
@ -81,12 +81,16 @@
|
|||
[isOpen]="isDepositModalOpen"
|
||||
(closeModalEmitter)="closeDepositModal()"
|
||||
></app-deposit>
|
||||
<button class="bg-deep-blue-light hover:bg-deep-blue-contrast w-full py-2 rounded">
|
||||
<button
|
||||
class="bg-deep-blue-light hover:bg-deep-blue-contrast w-full py-2 rounded"
|
||||
(click)="openTransactionModal()"
|
||||
>
|
||||
Transaktionen
|
||||
</button>
|
||||
<button class="bg-deep-blue-light hover:bg-deep-blue-contrast w-full py-2 rounded">
|
||||
Kontoeinstellungen
|
||||
</button>
|
||||
<app-transaction-history
|
||||
[isOpen]="isTransactionModalOpen"
|
||||
(closeEventEmitter)="closeTransactionModal()"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -100,11 +104,13 @@
|
|||
<div class="space-y-3">
|
||||
<div
|
||||
class="flex justify-between items-center"
|
||||
*ngFor="let transaction of recentTransactions"
|
||||
*ngFor="let transaction of (recentTransactionData | async)?.transactions"
|
||||
>
|
||||
<div>
|
||||
<p class="text-sm font-medium">{{ transaction.type }}</p>
|
||||
<p class="text-xs text-text-secondary">{{ transaction.date }}</p>
|
||||
<p class="text-sm font-medium">{{ transaction.status }}</p>
|
||||
<p class="text-xs text-text-secondary">
|
||||
{{ transaction.createdAt | date: 'd.m.Y H:m' }}
|
||||
</p>
|
||||
</div>
|
||||
<span [class]="transaction.amount > 0 ? 'text-emerald' : 'text-accent-red'">
|
||||
{{ transaction.amount | currency: 'EUR' }}
|
||||
|
|
|
@ -1,22 +1,36 @@
|
|||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
||||
import { CurrencyPipe, NgFor } from '@angular/common';
|
||||
import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/core';
|
||||
import { AsyncPipe, CurrencyPipe, DatePipe, NgFor } from '@angular/common';
|
||||
import { DepositComponent } from '../deposit/deposit.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';
|
||||
import { Observable } from 'rxjs';
|
||||
import { TransactionService } from '@service/transaction.service';
|
||||
import format from 'ajv/dist/vocabularies/format';
|
||||
import { TransactionHistoryComponent } from '../transaction-history/transaction-history.component';
|
||||
import { TransactionData } from '../../model/TransactionData';
|
||||
|
||||
@Component({
|
||||
selector: 'app-homepage',
|
||||
standalone: true,
|
||||
imports: [NavbarComponent, CurrencyPipe, NgFor, DepositComponent, ConfirmationComponent],
|
||||
imports: [
|
||||
NavbarComponent,
|
||||
CurrencyPipe,
|
||||
NgFor,
|
||||
DepositComponent,
|
||||
ConfirmationComponent,
|
||||
AsyncPipe,
|
||||
DatePipe,
|
||||
TransactionHistoryComponent,
|
||||
],
|
||||
templateUrl: './home.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export default class HomeComponent implements OnInit {
|
||||
isDepositModalOpen = false;
|
||||
isDepositSuccessful = false;
|
||||
isTransactionModalOpen = false;
|
||||
|
||||
constructor(
|
||||
public route: ActivatedRoute,
|
||||
|
@ -74,11 +88,13 @@ export default class HomeComponent implements OnInit {
|
|||
|
||||
allGames: Game[] = [...this.featuredGames];
|
||||
|
||||
recentTransactions: Transaction[] = [];
|
||||
recentTransactionData: Observable<TransactionData> =
|
||||
inject(TransactionService).getUsersTransactions(5);
|
||||
|
||||
openDepositModal() {
|
||||
this.isDepositModalOpen = true;
|
||||
}
|
||||
|
||||
closeDepositModal() {
|
||||
this.isDepositModalOpen = false;
|
||||
}
|
||||
|
@ -86,11 +102,22 @@ export default class HomeComponent implements OnInit {
|
|||
openDepositConfirmationModal() {
|
||||
this.isDepositSuccessful = true;
|
||||
}
|
||||
|
||||
openTransactionModal() {
|
||||
this.isTransactionModalOpen = true;
|
||||
}
|
||||
|
||||
closeDepositConfirmationModal() {
|
||||
this.isDepositSuccessful = false;
|
||||
}
|
||||
|
||||
closeTransactionModal() {
|
||||
this.isTransactionModalOpen = false;
|
||||
}
|
||||
|
||||
navigateToGame(route: string) {
|
||||
this.router.navigate([route]);
|
||||
}
|
||||
|
||||
protected readonly format = format;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { ChangeDetectionStrategy, Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { NgFor } from '@angular/common';
|
||||
import { NavbarComponent } from '@shared/components/navbar/navbar.component';
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
button[disabled] {
|
||||
cursor: not-allowed;
|
||||
background-color: #077b58;
|
||||
box-shadow: none;
|
||||
}
|
||||
button[disabled]:hover {
|
||||
background-color: #077b58;
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<div *ngIf="isOpen" [@fadeInOut] class="modal-bg" style="z-index: 1000; position: fixed">
|
||||
<div class="modal-card" [@cardAnimation]>
|
||||
<button
|
||||
type="button"
|
||||
(click)="closeDialog()"
|
||||
class="absolute top-2 right-2 text-text-secondary"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" viewBox="0 0 24 24">
|
||||
<path
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M18 6L6 18M6 6l12 12"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
<h2 class="modal-heading mb-0">Transaktionen</h2>
|
||||
<p class="pb-1 text-text-secondary mb-4">Hier siehst du alle vergangenen Einzahlungen</p>
|
||||
@for (transaction of (transactionData$ | async)?.transactions; track null) {
|
||||
<div class="flex justify-between items-center mb-4">
|
||||
<div>
|
||||
<p class="text-sm font-medium">{{ transaction.status }}</p>
|
||||
<p class="text-xs text-text-secondary">{{ transaction.createdAt | date: 'd.m.Y H:m' }}</p>
|
||||
</div>
|
||||
<span [class]="transaction.amount > 0 ? 'text-emerald' : 'text-accent-red'">
|
||||
{{ transaction.amount | currency: 'EUR' }}
|
||||
</span>
|
||||
</div>
|
||||
} @empty {
|
||||
<div class="flex justify-center items-center w-full h-32">
|
||||
<div
|
||||
class="spinner-border animate-spin inline-block w-8 h-8 border-4 rounded-full border-gray-300 border-t-gree-600"
|
||||
role="status"
|
||||
>
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div class="inline inline-flex w-full gap-2">
|
||||
<button
|
||||
type="button"
|
||||
(click)="back()"
|
||||
class="button-primary w-full py-2"
|
||||
[disabled]="offset <= 0"
|
||||
>
|
||||
<
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
(click)="forward()"
|
||||
class="button-primary w-full py-2"
|
||||
[disabled]="!(transactionData$ | async)?.hasMore"
|
||||
>
|
||||
>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,54 @@
|
|||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
EventEmitter,
|
||||
inject,
|
||||
Input,
|
||||
Output,
|
||||
} from '@angular/core';
|
||||
import { TransactionService } from '@service/transaction.service';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AsyncPipe, CurrencyPipe, DatePipe, NgForOf, NgIf } from '@angular/common';
|
||||
import { AnimatedNumberComponent } from '@blackjack/components/animated-number/animated-number.component';
|
||||
import { TransactionData } from '../../model/TransactionData';
|
||||
|
||||
const PER_PAGE = 5;
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
selector: 'app-transaction-history',
|
||||
imports: [NgForOf, AsyncPipe, CurrencyPipe, DatePipe, AnimatedNumberComponent, NgIf],
|
||||
templateUrl: './transaction-history.component.html',
|
||||
styleUrl: './transaction-history.component.css',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class TransactionHistoryComponent {
|
||||
@Input()
|
||||
isOpen = false;
|
||||
@Output()
|
||||
closeEventEmitter = new EventEmitter<void>();
|
||||
|
||||
protected offset = 0;
|
||||
|
||||
private transactionService: TransactionService = inject(TransactionService);
|
||||
transactionData$: Observable<TransactionData> = this.loadTransactions();
|
||||
|
||||
closeDialog() {
|
||||
this.isOpen = false;
|
||||
this.closeEventEmitter.emit();
|
||||
}
|
||||
|
||||
forward() {
|
||||
this.offset++;
|
||||
this.transactionData$ = this.loadTransactions();
|
||||
}
|
||||
|
||||
back() {
|
||||
this.offset--;
|
||||
this.transactionData$ = this.loadTransactions();
|
||||
}
|
||||
|
||||
loadTransactions() {
|
||||
return this.transactionService.getUsersTransactions(PER_PAGE, this.offset * PER_PAGE);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
export interface Transaction {
|
||||
id: string;
|
||||
type: string;
|
||||
status: string;
|
||||
amount: number;
|
||||
date: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
|
6
frontend/src/app/model/TransactionData.ts
Normal file
6
frontend/src/app/model/TransactionData.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { Transaction } from './Transaction';
|
||||
|
||||
export interface TransactionData {
|
||||
transactions: Transaction[];
|
||||
hasMore: boolean;
|
||||
}
|
24
frontend/src/app/service/transaction.service.ts
Normal file
24
frontend/src/app/service/transaction.service.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { inject, Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { TransactionData } from '../model/TransactionData';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class TransactionService {
|
||||
private http: HttpClient = inject(HttpClient);
|
||||
|
||||
public getUsersTransactions(limit: number | null = null, offset: number | null = null) {
|
||||
const baseUrl = new URL(`${window.location.origin}/backend/user/transactions`);
|
||||
|
||||
if (limit !== null) {
|
||||
baseUrl.searchParams.append('limit', limit.toString());
|
||||
}
|
||||
|
||||
if (offset !== null) {
|
||||
baseUrl.searchParams.append('offset', offset.toString());
|
||||
}
|
||||
|
||||
return this.http.get<TransactionData>(`${baseUrl}`);
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
import {
|
||||
AfterViewInit,
|
||||
Component,
|
||||
ElementRef,
|
||||
EventEmitter,
|
||||
Input,
|
||||
OnDestroy,
|
||||
Output,
|
||||
ViewChild,
|
||||
AfterViewInit,
|
||||
OnDestroy,
|
||||
} from '@angular/core';
|
||||
import { ModalAnimationService } from '@shared/services/modal-animation.service';
|
||||
import gsap from 'gsap';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
||||
import { faMoneyBillTransfer, faCreditCard, faWallet } from '@fortawesome/free-solid-svg-icons';
|
||||
import { faPaypal, faGooglePay, faApplePay } from '@fortawesome/free-brands-svg-icons';
|
||||
import { faCreditCard, faMoneyBillTransfer, faWallet } from '@fortawesome/free-solid-svg-icons';
|
||||
import { faApplePay, faGooglePay, faPaypal } from '@fortawesome/free-brands-svg-icons';
|
||||
|
||||
@Component({
|
||||
selector: 'app-footer',
|
||||
|
|
|
@ -2,8 +2,8 @@ import {
|
|||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
inject,
|
||||
OnInit,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
signal,
|
||||
} from '@angular/core';
|
||||
import { RouterModule } from '@angular/router';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue