Compare commits
No commits in common. "v1.36.1" and "v1.36.0" have entirely different histories.
7 changed files with 31 additions and 27 deletions
|
@ -1,6 +1,5 @@
|
|||
package de.szut.casino.blackjack;
|
||||
|
||||
import de.szut.casino.exceptionHandling.exceptions.UserNotFoundException;
|
||||
import de.szut.casino.shared.dto.BetDto;
|
||||
import de.szut.casino.shared.service.BalanceService;
|
||||
import de.szut.casino.user.UserEntity;
|
||||
|
@ -32,7 +31,7 @@ public class BlackJackGameController {
|
|||
Optional<UserEntity> optionalUser = userService.getCurrentUser(token);
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
@ -49,7 +48,7 @@ public class BlackJackGameController {
|
|||
Optional<UserEntity> optionalUser = userService.getCurrentUser(token);
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
@ -66,7 +65,7 @@ public class BlackJackGameController {
|
|||
Optional<UserEntity> optionalUser = userService.getCurrentUser(token);
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
@ -83,7 +82,7 @@ public class BlackJackGameController {
|
|||
Optional<UserEntity> optionalUser = userService.getCurrentUser(token);
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
@ -100,7 +99,7 @@ public class BlackJackGameController {
|
|||
Optional<UserEntity> optionalUser = userService.getCurrentUser(token);
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
@ -117,7 +116,7 @@ public class BlackJackGameController {
|
|||
Optional<UserEntity> optionalUser = userService.getCurrentUser(token);
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package de.szut.casino.exceptionHandling;
|
||||
|
||||
import de.szut.casino.exceptionHandling.exceptions.UserNotFoundException;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
|
@ -10,11 +12,17 @@ import org.springframework.web.context.request.WebRequest;
|
|||
import java.util.Date;
|
||||
|
||||
@ControllerAdvice
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "500", description = "invalid JSON posted",
|
||||
content = @Content)
|
||||
})
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(UserNotFoundException.class)
|
||||
public ResponseEntity<?> handleUserNotFoundException(UserNotFoundException ex, WebRequest request) {
|
||||
@ExceptionHandler(ResourceNotFoundException.class)
|
||||
public ResponseEntity<?> handleHelloEntityNotFoundException(ResourceNotFoundException ex, WebRequest request) {
|
||||
ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false));
|
||||
return new ResponseEntity<>(errorDetails, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package de.szut.casino.exceptionHandling;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(value = HttpStatus.NOT_FOUND)
|
||||
public class ResourceNotFoundException extends RuntimeException {
|
||||
public ResourceNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package de.szut.casino.exceptionHandling.exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(value = HttpStatus.NOT_FOUND)
|
||||
public class UserNotFoundException extends RuntimeException {
|
||||
public UserNotFoundException() {
|
||||
super("user not found");
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package de.szut.casino.lootboxes;
|
||||
|
||||
import de.szut.casino.exceptionHandling.exceptions.UserNotFoundException;
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import de.szut.casino.user.UserRepository;
|
||||
import de.szut.casino.user.UserService;
|
||||
|
@ -38,7 +37,7 @@ public class LootBoxController {
|
|||
|
||||
Optional<UserEntity> optionalUser = userService.getCurrentUser(token);
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package de.szut.casino.slots;
|
||||
|
||||
import de.szut.casino.exceptionHandling.exceptions.UserNotFoundException;
|
||||
import de.szut.casino.shared.dto.BetDto;
|
||||
import de.szut.casino.shared.service.BalanceService;
|
||||
import de.szut.casino.user.UserEntity;
|
||||
|
@ -32,7 +31,7 @@ public class SlotController {
|
|||
Optional<UserEntity> optionalUser = userService.getCurrentUser(token);
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
throw new UserNotFoundException();
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
UserEntity user = optionalUser.get();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package de.szut.casino.user;
|
||||
|
||||
import de.szut.casino.exceptionHandling.exceptions.UserNotFoundException;
|
||||
import de.szut.casino.user.dto.CreateUserDto;
|
||||
import de.szut.casino.user.dto.GetUserDto;
|
||||
import jakarta.validation.Valid;
|
||||
|
@ -35,7 +34,7 @@ public class UserController {
|
|||
GetUserDto userData = userService.getCurrentUserAsDto(token);
|
||||
|
||||
if (userData == null) {
|
||||
throw new UserNotFoundException();
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(userData);
|
||||
|
|
Reference in a new issue