import de.juplo.kafka.payment.transfer.domain.TransferService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
-import org.springframework.validation.FieldError;
-import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
@RestController
.map(transfer -> ResponseEntity.ok(TransferDTO.of(transfer)))
.orElse(ResponseEntity.notFound().build());
}
-
- @ResponseStatus(HttpStatus.BAD_REQUEST)
- @ExceptionHandler(MethodArgumentNotValidException.class)
- public Map<String, String> handleValidationExceptions(
- MethodArgumentNotValidException ex) {
- Map<String, String> errors = new HashMap<>();
- ex.getBindingResult().getAllErrors().forEach((error) -> {
- String fieldName = ((FieldError) error).getField();
- String errorMessage = error.getDefaultMessage();
- errors.put(fieldName, errorMessage);
- });
- return errors;
- }
}