I want to do this code you have seen using ternary operation instead of if conditional blocks. Generally, is the use of the ternary operator always a good choice? In some places they say it is more readable and more flexible code to use the ternary operator instead of constantly using if conditional blocks.
@Override
public ResponseEntity<? extends UserDetailResponse> getByPhoneNumberUserDetail(String phoneNumber) {
UserDetail userDetail = userDetailRepository.findByPhoneNumber(phoneNumber);
if (!userDetail.getPhoneNumber().equals(phoneNumber)) {
return new ResponseEntity<>(new UserDetailResponse(MessageCase.COULDNT_FOUNDED_USER_DETAILS_SUCH_PHONE_NUMBER.getMessage(), 400), HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>(new UserDetailResponse(MessageCase.USER_DETAL_SUCESSFULLY_FOUNDED.getMessage(), 200), HttpStatus.OK);
}