fix: SonarLint fixes
This commit is contained in:
parent
d0e21e9eff
commit
ec0ee860ee
3 changed files with 13 additions and 7 deletions
|
@ -5,7 +5,11 @@ import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
|
||||||
public class UserNotFoundException extends RuntimeException {
|
public class UserNotFoundException extends RuntimeException {
|
||||||
|
|
||||||
public UserNotFoundException(CurrencyExchangeRequest entity) {
|
public UserNotFoundException(CurrencyExchangeRequest entity) {
|
||||||
super("User with PESEL %s not found".formatted(entity.pesel()));
|
this(entity.pesel());
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserNotFoundException(String pesel) {
|
||||||
|
super("User with PESEL %s not found".formatted(pesel));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
package eu.ztsh.wymiana.web.controller;
|
package eu.ztsh.wymiana.web.controller;
|
||||||
|
|
||||||
import eu.ztsh.wymiana.exception.InsufficientFundsException;
|
import eu.ztsh.wymiana.exception.InsufficientFundsException;
|
||||||
import eu.ztsh.wymiana.exception.UserAlreadyExistsException;
|
|
||||||
import eu.ztsh.wymiana.exception.UserNotFoundException;
|
import eu.ztsh.wymiana.exception.UserNotFoundException;
|
||||||
import eu.ztsh.wymiana.service.CurrencyService;
|
import eu.ztsh.wymiana.service.CurrencyService;
|
||||||
import eu.ztsh.wymiana.validation.ValidationFailedException;
|
|
||||||
import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
|
import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.HttpEntity;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.ztsh.wymiana.web.controller;
|
package eu.ztsh.wymiana.web.controller;
|
||||||
|
|
||||||
import eu.ztsh.wymiana.exception.UserAlreadyExistsException;
|
import eu.ztsh.wymiana.exception.UserAlreadyExistsException;
|
||||||
|
import eu.ztsh.wymiana.exception.UserNotFoundException;
|
||||||
import eu.ztsh.wymiana.model.User;
|
import eu.ztsh.wymiana.model.User;
|
||||||
import eu.ztsh.wymiana.service.UserService;
|
import eu.ztsh.wymiana.service.UserService;
|
||||||
import eu.ztsh.wymiana.validation.ValidationFailedException;
|
import eu.ztsh.wymiana.validation.ValidationFailedException;
|
||||||
|
@ -31,9 +32,13 @@ public class UserController {
|
||||||
try {
|
try {
|
||||||
return userService.get(pesel)
|
return userService.get(pesel)
|
||||||
.map(ResponseEntity::ok)
|
.map(ResponseEntity::ok)
|
||||||
.orElse(ResponseEntity.notFound().build());
|
.orElseThrow(() -> new UserNotFoundException(pesel));
|
||||||
} catch (ValidationException e) {
|
} catch (Exception e) {
|
||||||
return ResponseEntity.badRequest().build();
|
return ResponseEntity.status(switch (e) {
|
||||||
|
case ValidationException ignore -> 400;
|
||||||
|
case UserNotFoundException ignore -> 404;
|
||||||
|
default -> 500;
|
||||||
|
}).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue