Compare commits
No commits in common. "v1.69.0" and "v1.68.7" have entirely different histories.
22 changed files with 151 additions and 193 deletions
|
@ -1,66 +0,0 @@
|
|||
name: Setup Gitea Tea CLI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize] # Runs on new PRs and updates
|
||||
|
||||
jobs:
|
||||
setup-and-login:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
ref: ${{ github.ref }}
|
||||
fetch-tags: true
|
||||
|
||||
- name: Set Tea Version
|
||||
id: tea_version
|
||||
run: echo "version=0.9.2" >> $GITHUB_OUTPUT # Check for the latest version
|
||||
|
||||
- name: Download Tea CLI
|
||||
run: |
|
||||
TEA_VERSION=$(echo "${{ steps.tea_version.outputs.version }}")
|
||||
wget "https://gitea.com/gitea/tea/releases/download/v${TEA_VERSION}/tea-${TEA_VERSION}-linux-amd64" -O tea
|
||||
chmod +x tea
|
||||
sudo mv tea /usr/local/bin/tea
|
||||
|
||||
- name: Verify Tea Installation
|
||||
run: tea --version
|
||||
|
||||
- name: Add Gitea Login
|
||||
env:
|
||||
GITEA_URL: ${{ secrets._GITEA_URL }}
|
||||
GITEA_TOKEN: ${{ secrets._GITEA_TOKEN }}
|
||||
run: |
|
||||
if [ -z "$GITEA_URL" ]; then
|
||||
echo "Error: GITEA_URL secret is not set."
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$GITEA_TOKEN" ]; then
|
||||
echo "Error: GITEA_TOKEN secret is not set."
|
||||
exit 1
|
||||
fi
|
||||
tea login add --name mygitea --url "$GITEA_URL" --token "$GITEA_TOKEN" --insecure ${{ startsWith(secrets._GITEA_URL, 'http://') || '' }}
|
||||
|
||||
- name: Install bun
|
||||
uses: oven-sh/setup-bun@v2
|
||||
|
||||
- name: Install claude code
|
||||
run: bun i -g @anthropic-ai/claude-code
|
||||
|
||||
- name: Claude PR Review
|
||||
env:
|
||||
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
PR_NUMBER: ${{ github.event.number }}
|
||||
run: |
|
||||
claude --allowedTools "Bash(tea:*)" --allowedTools "Bash(git:*) Read Grep WebFetch Glob LS" -p "You are a code review assistant. Your task is to review the changes in Pull Request #${PR_NUMBER}. All relevant changes can be seen by looking at the git diff HEAD...main (NEVER EVER REVIEW ALL THE CODE ONLY THE ONE FROM THE DIFF you can use the rest as context) or using the tea cli which you can use and we are on gitea. Also make sure to only review the changes in this pull request
|
||||
|
||||
Only provide constructive feedback on the quality, correctness, readability, and potential issues in the code. Do not make any changes or suggest complete rewrites—just review what is there.
|
||||
|
||||
Once you are done with your review, post your feedback as a reject or review on the pull request using the following exact format:
|
||||
|
||||
tea \"<reject or approve>\" ${PR_NUMBER} \"<your review message here>\"
|
||||
|
||||
Make sure the comment is clear, professional, and helpful. Only run the tea comment command once you're finished reviewing all changes. AND MOST IMPORTANDLY ONLY REVIEW THE DIFF FROM THE CURRENT STATE TO THE MAIN BRANCH TO GET THAT USE GIT DIFF."
|
|
@ -59,7 +59,13 @@ public class BlackJackGameController {
|
|||
|
||||
@PostMapping("/blackjack/start")
|
||||
public ResponseEntity<Object> createBlackJackGame(@RequestBody @Valid BetDto betDto) {
|
||||
UserEntity user = this.userService.getCurrentUser();
|
||||
Optional<UserEntity> optionalUser = userService.getCurrentUser();
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
||||
if (!this.balanceService.hasFunds(user, betDto)) {
|
||||
throw new InsufficientFundsException();
|
||||
|
@ -69,7 +75,13 @@ public class BlackJackGameController {
|
|||
}
|
||||
|
||||
private BlackJackGameEntity getBlackJackGame(Long gameId) {
|
||||
UserEntity user = userService.getCurrentUser();
|
||||
Optional<UserEntity> optionalUser = userService.getCurrentUser();
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
BlackJackGameEntity game = blackJackService.getBlackJackGame(gameId);
|
||||
if (game == null || !Objects.equals(game.getUserId(), user.getId())) {
|
||||
throw new UserBlackJackGameMismatchException(gameId);
|
||||
|
|
|
@ -28,7 +28,13 @@ public class CoinflipController {
|
|||
|
||||
@PostMapping("/coinflip")
|
||||
public ResponseEntity<Object> coinFlip(@RequestBody @Valid CoinflipDto coinflipDto) {
|
||||
UserEntity user = userService.getCurrentUser();
|
||||
Optional<UserEntity> optionalUser = userService.getCurrentUser();
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
||||
if (!this.balanceService.hasFunds(user, coinflipDto)) {
|
||||
throw new InsufficientFundsException();
|
||||
|
|
|
@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
public class DepositController {
|
||||
|
||||
|
@ -27,7 +29,7 @@ public class DepositController {
|
|||
|
||||
private final TransactionService transactionService;
|
||||
|
||||
private final UserService userService;
|
||||
private UserService userService;
|
||||
|
||||
public DepositController(TransactionService transactionService, UserService userService) {
|
||||
this.transactionService = transactionService;
|
||||
|
@ -38,7 +40,7 @@ public class DepositController {
|
|||
public ResponseEntity<SessionIdDto> checkout(@RequestBody @Valid AmountDto amountDto, @RequestHeader("Authorization") String token) throws StripeException {
|
||||
Stripe.apiKey = stripeKey;
|
||||
|
||||
UserEntity user = userService.getCurrentUser();
|
||||
Optional<UserEntity> optionalUserEntity = this.userService.getCurrentUser();
|
||||
|
||||
SessionCreateParams params = SessionCreateParams.builder()
|
||||
.addLineItem(SessionCreateParams.LineItem.builder()
|
||||
|
@ -58,7 +60,11 @@ public class DepositController {
|
|||
|
||||
Session session = Session.create(params);
|
||||
|
||||
transactionService.createTransaction(user, session.getId(), amountDto.getAmount());
|
||||
if (optionalUserEntity.isEmpty()) {
|
||||
throw new RuntimeException("User doesnt exist");
|
||||
}
|
||||
|
||||
transactionService.createTransaction(optionalUserEntity.get(), session.getId(), amountDto.getAmount());
|
||||
|
||||
return ResponseEntity.ok(new SessionIdDto(session.getId()));
|
||||
}
|
||||
|
|
|
@ -27,7 +27,13 @@ public class DiceController {
|
|||
|
||||
@PostMapping("/dice")
|
||||
public ResponseEntity<Object> rollDice(@RequestBody @Valid DiceDto diceDto) {
|
||||
UserEntity user = userService.getCurrentUser();
|
||||
Optional<UserEntity> optionalUser = userService.getCurrentUser();
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
||||
if (!this.balanceService.hasFunds(user, diceDto)) {
|
||||
throw new InsufficientFundsException();
|
||||
|
|
|
@ -38,7 +38,13 @@ public class LootBoxController {
|
|||
}
|
||||
|
||||
LootBoxEntity lootBox = optionalLootBox.get();
|
||||
UserEntity user = userService.getCurrentUser();
|
||||
|
||||
Optional<UserEntity> optionalUser = userService.getCurrentUser();
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
||||
if (lootBoxService.hasSufficientBalance(user, lootBox.getPrice())) {
|
||||
throw new InsufficientFundsException();
|
||||
|
|
|
@ -9,6 +9,7 @@ import de.szut.casino.user.dto.CreateUserDto;
|
|||
import de.szut.casino.user.dto.GetUserDto;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -19,11 +20,8 @@ import java.io.IOException;
|
|||
public class AuthController {
|
||||
|
||||
|
||||
private final AuthService authService;
|
||||
|
||||
public AuthController(AuthService authService) {
|
||||
this.authService = authService;
|
||||
}
|
||||
@Autowired
|
||||
private AuthService authService;
|
||||
|
||||
@PostMapping("/login")
|
||||
public ResponseEntity<AuthResponseDto> authenticateUser(@Valid @RequestBody LoginRequestDto loginRequest) throws EmailNotVerifiedException {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.szut.casino.security;
|
||||
|
||||
import de.szut.casino.security.jwt.JwtAuthenticationFilter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -31,13 +32,11 @@ public class SecurityConfig {
|
|||
@Value("${app.frontend-host}")
|
||||
private String frontendHost;
|
||||
|
||||
private final UserDetailsService userDetailsService;
|
||||
private final JwtAuthenticationFilter jwtAuthenticationFilter;
|
||||
@Autowired
|
||||
private UserDetailsService userDetailsService;
|
||||
|
||||
public SecurityConfig(UserDetailsService userDetailsService, JwtAuthenticationFilter jwtAuthenticationFilter) {
|
||||
this.userDetailsService = userDetailsService;
|
||||
this.jwtAuthenticationFilter = jwtAuthenticationFilter;
|
||||
}
|
||||
@Autowired
|
||||
private JwtAuthenticationFilter jwtAuthenticationFilter;
|
||||
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -4,6 +4,7 @@ import jakarta.servlet.FilterChain;
|
|||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
@ -18,13 +19,11 @@ import java.io.IOException;
|
|||
@Component
|
||||
public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
||||
|
||||
private final JwtUtils jwtUtils;
|
||||
private final UserDetailsService userDetailsService;
|
||||
@Autowired
|
||||
private JwtUtils jwtUtils;
|
||||
|
||||
public JwtAuthenticationFilter(JwtUtils jwtUtils, UserDetailsService userDetailsService) {
|
||||
this.jwtUtils = jwtUtils;
|
||||
this.userDetailsService = userDetailsService;
|
||||
}
|
||||
@Autowired
|
||||
private UserDetailsService userDetailsService;
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||
|
|
|
@ -4,6 +4,7 @@ import de.szut.casino.exceptionHandling.exceptions.OAuth2AuthenticationProcessin
|
|||
import de.szut.casino.user.AuthProvider;
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import de.szut.casino.user.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.InternalAuthenticationServiceException;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
@ -21,13 +22,11 @@ import java.util.UUID;
|
|||
@Service
|
||||
public class CustomOAuth2UserService extends DefaultOAuth2UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final PasswordEncoder oauth2PasswordEncoder;
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
public CustomOAuth2UserService(UserRepository userRepository, PasswordEncoder oauth2PasswordEncoder) {
|
||||
this.userRepository = userRepository;
|
||||
this.oauth2PasswordEncoder = oauth2PasswordEncoder;
|
||||
}
|
||||
@Autowired
|
||||
private PasswordEncoder oauth2PasswordEncoder;
|
||||
|
||||
@Override
|
||||
public OAuth2User loadUser(OAuth2UserRequest oAuth2UserRequest) throws OAuth2AuthenticationException {
|
||||
|
|
|
@ -5,6 +5,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
|
||||
|
@ -20,11 +21,8 @@ public class OAuth2AuthenticationSuccessHandler extends SimpleUrlAuthenticationS
|
|||
@Value("${app.oauth2.authorizedRedirectUris}")
|
||||
private String redirectUri;
|
||||
|
||||
private final JwtUtils jwtUtils;
|
||||
|
||||
public OAuth2AuthenticationSuccessHandler(JwtUtils jwtUtils) {
|
||||
this.jwtUtils = jwtUtils;
|
||||
}
|
||||
@Autowired
|
||||
private JwtUtils jwtUtils;
|
||||
|
||||
@Override
|
||||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
|
||||
|
|
|
@ -3,6 +3,7 @@ package de.szut.casino.security.oauth2.github;
|
|||
import de.szut.casino.security.dto.AuthResponseDto;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -22,11 +23,8 @@ public class GitHubController {
|
|||
@Value("${spring.security.oauth2.client.registration.github.redirect-uri}")
|
||||
private String redirectUri;
|
||||
|
||||
private final GitHubService githubService;
|
||||
|
||||
public GitHubController(GitHubService githubService) {
|
||||
this.githubService = githubService;
|
||||
}
|
||||
@Autowired
|
||||
private GitHubService githubService;
|
||||
|
||||
@GetMapping("/authorize")
|
||||
public RedirectView authorizeGithub() {
|
||||
|
|
|
@ -5,6 +5,7 @@ import de.szut.casino.security.jwt.JwtUtils;
|
|||
import de.szut.casino.user.AuthProvider;
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import de.szut.casino.user.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
@ -28,17 +29,17 @@ public class GitHubService {
|
|||
@Value("${spring.security.oauth2.client.registration.github.client-secret}")
|
||||
private String clientSecret;
|
||||
|
||||
private final AuthenticationManager authenticationManager;
|
||||
private final UserRepository userRepository;
|
||||
private final JwtUtils jwtUtils;
|
||||
private final PasswordEncoder oauth2PasswordEncoder;
|
||||
@Autowired
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
public GitHubService(AuthenticationManager authenticationManager, UserRepository userRepository, JwtUtils jwtUtils, PasswordEncoder oauth2PasswordEncoder) {
|
||||
this.authenticationManager = authenticationManager;
|
||||
this.userRepository = userRepository;
|
||||
this.jwtUtils = jwtUtils;
|
||||
this.oauth2PasswordEncoder = oauth2PasswordEncoder;
|
||||
}
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private JwtUtils jwtUtils;
|
||||
|
||||
@Autowired
|
||||
private PasswordEncoder oauth2PasswordEncoder;
|
||||
|
||||
public AuthResponseDto processGithubCode(String code) {
|
||||
try {
|
||||
|
|
|
@ -4,6 +4,7 @@ import de.szut.casino.security.dto.AuthResponseDto;
|
|||
import de.szut.casino.security.oauth2.github.GithubCallbackDto;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -23,11 +24,8 @@ public class GoogleController {
|
|||
@Value("${spring.security.oauth2.client.registration.google.redirect-uri}")
|
||||
private String redirectUri;
|
||||
|
||||
private final GoogleService googleService;
|
||||
|
||||
public GoogleController(GoogleService googleService) {
|
||||
this.googleService = googleService;
|
||||
}
|
||||
@Autowired
|
||||
private GoogleService googleService;
|
||||
|
||||
@GetMapping("/authorize")
|
||||
public RedirectView authorizeGoogle() {
|
||||
|
|
|
@ -7,6 +7,7 @@ import de.szut.casino.user.UserEntity;
|
|||
import de.szut.casino.user.UserRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
@ -22,9 +23,7 @@ import org.springframework.util.MultiValueMap;
|
|||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class GoogleService {
|
||||
|
@ -45,17 +44,17 @@ public class GoogleService {
|
|||
@Value("${spring.security.oauth2.client.provider.google.user-info-uri}")
|
||||
private String userInfoUri;
|
||||
|
||||
private final AuthenticationManager authenticationManager;
|
||||
private final UserRepository userRepository;
|
||||
private final JwtUtils jwtUtils;
|
||||
private final PasswordEncoder oauth2PasswordEncoder;
|
||||
@Autowired
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
public GoogleService(AuthenticationManager authenticationManager, UserRepository userRepository, JwtUtils jwtUtils, PasswordEncoder oauth2PasswordEncoder) {
|
||||
this.authenticationManager = authenticationManager;
|
||||
this.userRepository = userRepository;
|
||||
this.jwtUtils = jwtUtils;
|
||||
this.oauth2PasswordEncoder = oauth2PasswordEncoder;
|
||||
}
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
private JwtUtils jwtUtils;
|
||||
|
||||
@Autowired
|
||||
private PasswordEncoder oauth2PasswordEncoder;
|
||||
|
||||
public AuthResponseDto processGoogleCode(String code) {
|
||||
try {
|
||||
|
|
|
@ -11,6 +11,7 @@ import de.szut.casino.user.dto.CreateUserDto;
|
|||
import de.szut.casino.user.dto.GetUserDto;
|
||||
import jakarta.mail.MessagingException;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
@ -24,19 +25,20 @@ import java.util.Optional;
|
|||
@Service
|
||||
public class AuthService {
|
||||
|
||||
private final AuthenticationManager authenticationManager;
|
||||
private final JwtUtils jwtUtils;
|
||||
private final UserService userService;
|
||||
private final EmailService emailService;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
@Autowired
|
||||
private AuthenticationManager authenticationManager;
|
||||
|
||||
public AuthService(AuthenticationManager authenticationManager, JwtUtils jwtUtils, UserService userService, EmailService emailService, PasswordEncoder passwordEncoder) {
|
||||
this.authenticationManager = authenticationManager;
|
||||
this.jwtUtils = jwtUtils;
|
||||
this.userService = userService;
|
||||
this.emailService = emailService;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
@Autowired
|
||||
private JwtUtils jwtUtils;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
public AuthResponseDto login(LoginRequestDto loginRequest) throws EmailNotVerifiedException {
|
||||
if (!userService.isVerified(loginRequest.getUsernameOrEmail())) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.szut.casino.security.service;
|
|||
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import de.szut.casino.user.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
@ -13,11 +14,8 @@ import java.util.Optional;
|
|||
@Service
|
||||
public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserDetailsServiceImpl(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String usernameOrEmail) throws UsernameNotFoundException {
|
||||
|
|
|
@ -32,7 +32,13 @@ public class SlotController {
|
|||
|
||||
@PostMapping("/slots/spin")
|
||||
public ResponseEntity<Object> spinSlots(@RequestBody @Valid BetDto betDto) {
|
||||
UserEntity user = userService.getCurrentUser();
|
||||
Optional<UserEntity> optionalUser = userService.getCurrentUser();
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
||||
if (!this.balanceService.hasFunds(user, betDto)) {
|
||||
throw new InsufficientFundsException();
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.szut.casino.user;
|
|||
|
||||
import de.szut.casino.user.dto.GetUserDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -14,17 +15,14 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RequestMapping("/users")
|
||||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
private final UserMappingService userMappingService;
|
||||
|
||||
public UserController(UserService userService, UserMappingService userMappingService) {
|
||||
this.userService = userService;
|
||||
this.userMappingService = userMappingService;
|
||||
}
|
||||
@Autowired
|
||||
private UserMappingService userMappingService;
|
||||
|
||||
@GetMapping("/me")
|
||||
public ResponseEntity<GetUserDto> getCurrentUser() {
|
||||
return ResponseEntity.ok(userMappingService.mapToGetUserDto(userService.getCurrentUser()));
|
||||
return ResponseEntity.ok(userMappingService.mapToGetUserDto(userService.getCurrentUser().orElseThrow()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package de.szut.casino.user;
|
||||
|
||||
import de.szut.casino.exceptionHandling.exceptions.UserNotFoundException;
|
||||
import de.szut.casino.user.dto.CreateUserDto;
|
||||
import jakarta.persistence.EntityExistsException;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -13,13 +13,11 @@ import java.util.Optional;
|
|||
|
||||
@Service
|
||||
public class UserService {
|
||||
private final UserRepository userRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
public UserService(UserRepository userRepository, PasswordEncoder passwordEncoder) {
|
||||
this.userRepository = userRepository;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
@Autowired
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
public UserEntity createUser(CreateUserDto createUserDto) {
|
||||
if (userRepository.existsByUsername(createUserDto.getUsername())) {
|
||||
|
@ -41,15 +39,10 @@ public class UserService {
|
|||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
public UserEntity getCurrentUser() {
|
||||
public Optional<UserEntity> getCurrentUser() {
|
||||
String username = SecurityContextHolder.getContext().getAuthentication().getName();
|
||||
|
||||
Optional<UserEntity> optionalUser = userRepository.findByUsername(username);
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
|
||||
return optionalUser.get();
|
||||
return userRepository.findByUsername(username);
|
||||
}
|
||||
|
||||
public Optional<UserEntity> getUserByVerificationToken(String token) {
|
||||
|
|
|
@ -6,29 +6,31 @@ 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 {
|
||||
|
||||
private final UserService userService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
private final TransactionRepository transactionRepository;
|
||||
@Autowired
|
||||
private TransactionRepository transactionRepository;
|
||||
|
||||
public GetTransactionService(UserService userService, TransactionRepository transactionRepository) {
|
||||
this.userService = userService;
|
||||
this.transactionRepository = transactionRepository;
|
||||
}
|
||||
public UserTransactionsDto getUserTransactionsDto(String authToken, Integer limit, Integer offset) {
|
||||
Optional<UserEntity> user = this.userService.getCurrentUser();
|
||||
if (user.isPresent()) {
|
||||
List<TransactionEntity> transactionEntities = this.transactionRepository.findByUserIdWithLimit(user.get(), limit, offset);
|
||||
Boolean hasMore = this.transactionRepository.hasMore(user.get(), limit, offset);
|
||||
|
||||
public UserTransactionsDto getUserTransactionsDto(Integer limit, Integer offset) {
|
||||
UserEntity user = userService.getCurrentUser();
|
||||
return new UserTransactionsDto(mapTransactionsToDtos(transactionEntities), hasMore);
|
||||
}
|
||||
|
||||
List<TransactionEntity> transactionEntities = this.transactionRepository.findByUserIdWithLimit(user, limit, offset);
|
||||
Boolean hasMore = this.transactionRepository.hasMore(user, limit, offset);
|
||||
|
||||
return new UserTransactionsDto(mapTransactionsToDtos(transactionEntities), hasMore);
|
||||
return new UserTransactionsDto(List.of(), false);
|
||||
}
|
||||
|
||||
public List<GetTransactionDto> mapTransactionsToDtos(List<TransactionEntity> transactions) {
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
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 {
|
||||
|
||||
private final GetTransactionService transactionService;
|
||||
|
||||
public TransactionController(GetTransactionService transactionService) {
|
||||
this.transactionService = transactionService;
|
||||
}
|
||||
@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(limit, offset);
|
||||
UserTransactionsDto transactionEntities = this.transactionService.getUserTransactionsDto(authToken, limit, offset);
|
||||
|
||||
return ResponseEntity.ok(transactionEntities);
|
||||
}
|
||||
|
|
Reference in a new issue