hey guys. im looking for advice on this question. right now i have this:
@PostMapping(value = "/myendpoint", produces = "application/json")
@ResponseStatus(HttpStatus.CREATED)
public ResponseEntity<PaymentDTO> createPaymentInformation(@RequestBody @Valid PaymentDTO paymentInformationRequest){
myValidationService.validateCreatePaymentInformationRequest(paymentInformationRequest);
PaymentDTO paymentInformationResponse=myService.createPaymentInformation(paymentInformationRequest);
ResponseEntity<PaymentDTO> responseEntity = new ResponseEntity<>(paymentInformationResponse, HttpStatus.CREATED);
return responseEntity;
}
i need to manually check if some fields of my DTO are null. this is my myValidationService's method:
public void validateCreatePaymentInformationRequest(PaymentDTO paymentRequest){
System.out.println("TransactionID: " + paymentRequest.getTransactionId());
System.out.println("ClientID: " + paymentRequest.getClientId());
System.out.println("Amount: " + paymentRequest.getAmount());
System.out.println("Signature: " + paymentRequest.getSignature());
//System.exit(1);
if (paymentRequest.getAmount() == null) {
//todo return 400 bad req
}
if (paymentRequest.getClientId() == null) {
//todo return 400 bad req
}
so my questions are:
- should i craete
try-catchblock in my controller, and intryblock call the validation method? - or can i leave the controller as is?
- if amount or clientId is null, i want to return 400 bad request. do i need to create a custom exception that should be handled in my exception handler?
thanks for your help