feat: add transaction handling on user signup process
All checks were successful
CI / Get Changed Files (pull_request) Successful in 11s
CI / eslint (pull_request) Has been skipped
CI / oxlint (pull_request) Has been skipped
CI / prettier (pull_request) Has been skipped
CI / test-build (pull_request) Has been skipped
Label PRs based on size / Check PR size (pull_request) Successful in 11s
Claude PR Review / claude-code (pull_request) Successful in 27s
Pull Request Labeler / labeler (pull_request_target) Successful in 6s
CI / Docker frontend validation (pull_request) Has been skipped
CI / Checkstyle Main (pull_request) Successful in 1m29s
CI / Docker backend validation (pull_request) Successful in 1m49s
CI / Backend Tests (pull_request) Successful in 2m59s

This commit is contained in:
Constantin Simonis 2025-06-04 14:38:18 +02:00
commit e4173e3ade
No known key found for this signature in database
GPG key ID: 32E45D43790A8142
3 changed files with 33 additions and 4 deletions

View file

@ -1,5 +1,8 @@
package de.szut.casino.security.oauth2.github; package de.szut.casino.security.oauth2.github;
import de.szut.casino.deposit.TransactionEntity;
import de.szut.casino.deposit.TransactionRepository;
import de.szut.casino.deposit.TransactionStatus;
import de.szut.casino.security.dto.AuthResponseDto; import de.szut.casino.security.dto.AuthResponseDto;
import de.szut.casino.security.jwt.JwtUtils; import de.szut.casino.security.jwt.JwtUtils;
import de.szut.casino.user.AuthProvider; import de.szut.casino.user.AuthProvider;
@ -30,12 +33,14 @@ public class GitHubService {
private final AuthenticationManager authenticationManager; private final AuthenticationManager authenticationManager;
private final UserRepository userRepository; private final UserRepository userRepository;
private final TransactionRepository transactionRepository;
private final JwtUtils jwtUtils; private final JwtUtils jwtUtils;
private final PasswordEncoder oauth2PasswordEncoder; private final PasswordEncoder oauth2PasswordEncoder;
public GitHubService(AuthenticationManager authenticationManager, UserRepository userRepository, JwtUtils jwtUtils, PasswordEncoder oauth2PasswordEncoder) { public GitHubService(AuthenticationManager authenticationManager, UserRepository userRepository, TransactionRepository transactionRepository, JwtUtils jwtUtils, PasswordEncoder oauth2PasswordEncoder) {
this.authenticationManager = authenticationManager; this.authenticationManager = authenticationManager;
this.userRepository = userRepository; this.userRepository = userRepository;
this.transactionRepository = transactionRepository;
this.jwtUtils = jwtUtils; this.jwtUtils = jwtUtils;
this.oauth2PasswordEncoder = oauth2PasswordEncoder; this.oauth2PasswordEncoder = oauth2PasswordEncoder;
} }
@ -139,15 +144,20 @@ public class GitHubService {
user.setProvider(AuthProvider.GITHUB); user.setProvider(AuthProvider.GITHUB);
user.setProviderId(githubId); user.setProviderId(githubId);
user.setEmailVerified(true); user.setEmailVerified(true);
user.setBalance(new BigDecimal("100.00"));
user.setBalance(new BigDecimal("1000.00"));
} }
} }
String randomPassword = UUID.randomUUID().toString(); String randomPassword = UUID.randomUUID().toString();
user.setPassword(oauth2PasswordEncoder.encode(randomPassword)); user.setPassword(oauth2PasswordEncoder.encode(randomPassword));
TransactionEntity transaction = new TransactionEntity();
transaction.setAmount(100L);
transaction.setUser(user);
transaction.setSessionId("signup_bonus");
transaction.setStatus(TransactionStatus.SUCCEEDED);
userRepository.save(user); userRepository.save(user);
transactionRepository.save(transaction);
Authentication authentication = this.authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(user.getEmail(), randomPassword)); Authentication authentication = this.authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(user.getEmail(), randomPassword));

View file

@ -1,5 +1,8 @@
package de.szut.casino.security.oauth2.google; package de.szut.casino.security.oauth2.google;
import de.szut.casino.deposit.TransactionEntity;
import de.szut.casino.deposit.TransactionRepository;
import de.szut.casino.deposit.TransactionStatus;
import de.szut.casino.security.dto.AuthResponseDto; import de.szut.casino.security.dto.AuthResponseDto;
import de.szut.casino.security.jwt.JwtUtils; import de.szut.casino.security.jwt.JwtUtils;
import de.szut.casino.user.AuthProvider; import de.szut.casino.user.AuthProvider;
@ -47,12 +50,14 @@ public class GoogleService {
private final AuthenticationManager authenticationManager; private final AuthenticationManager authenticationManager;
private final UserRepository userRepository; private final UserRepository userRepository;
private final TransactionRepository transactionRepository;
private final JwtUtils jwtUtils; private final JwtUtils jwtUtils;
private final PasswordEncoder oauth2PasswordEncoder; private final PasswordEncoder oauth2PasswordEncoder;
public GoogleService(AuthenticationManager authenticationManager, UserRepository userRepository, JwtUtils jwtUtils, PasswordEncoder oauth2PasswordEncoder) { public GoogleService(AuthenticationManager authenticationManager, UserRepository userRepository, TransactionRepository transactionRepository, JwtUtils jwtUtils, PasswordEncoder oauth2PasswordEncoder) {
this.authenticationManager = authenticationManager; this.authenticationManager = authenticationManager;
this.userRepository = userRepository; this.userRepository = userRepository;
this.transactionRepository = transactionRepository;
this.jwtUtils = jwtUtils; this.jwtUtils = jwtUtils;
this.oauth2PasswordEncoder = oauth2PasswordEncoder; this.oauth2PasswordEncoder = oauth2PasswordEncoder;
} }
@ -146,8 +151,14 @@ public class GoogleService {
String randomPassword = UUID.randomUUID().toString(); String randomPassword = UUID.randomUUID().toString();
user.setPassword(oauth2PasswordEncoder.encode(randomPassword)); user.setPassword(oauth2PasswordEncoder.encode(randomPassword));
TransactionEntity transaction = new TransactionEntity();
transaction.setAmount(100L);
transaction.setUser(user);
transaction.setSessionId("signup_bonus");
transaction.setStatus(TransactionStatus.SUCCEEDED);
userRepository.save(user); userRepository.save(user);
transactionRepository.save(transaction);
Authentication authentication = authenticationManager.authenticate( Authentication authentication = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(user.getEmail(), randomPassword) new UsernamePasswordAuthenticationToken(user.getEmail(), randomPassword)

View file

@ -1,5 +1,7 @@
package de.szut.casino.user; package de.szut.casino.user;
import de.szut.casino.deposit.TransactionEntity;
import de.szut.casino.deposit.TransactionStatus;
import de.szut.casino.exceptionHandling.exceptions.UserNotFoundException; import de.szut.casino.exceptionHandling.exceptions.UserNotFoundException;
import de.szut.casino.user.dto.CreateUserDto; import de.szut.casino.user.dto.CreateUserDto;
import jakarta.persistence.EntityExistsException; import jakarta.persistence.EntityExistsException;
@ -38,6 +40,12 @@ public class UserService {
RandomStringUtils.randomAlphanumeric(64) RandomStringUtils.randomAlphanumeric(64)
); );
TransactionEntity transaction = new TransactionEntity();
transaction.setAmount(100L);
transaction.setUser(user);
transaction.setSessionId("signup_bonus");
transaction.setStatus(TransactionStatus.SUCCEEDED);
return userRepository.save(user); return userRepository.save(user);
} }