-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
7817 fix api response status 500 instead of 400 when coordinates not specified #7850
7817 fix api response status 500 instead of 400 when coordinates not specified #7850
Conversation
for (EventDateLocationDto eventDateLocationDto : eventDateLocationDtos) { | ||
AddressDto coordinates = eventDateLocationDto.getCoordinates(); | ||
|
||
if (coordinates == null || coordinates.getLatitude() == null || coordinates.getLongitude() == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe make sens use Objects.isNull() ckeck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
double latitude = coordinates.getLatitude(); | ||
double longitude = coordinates.getLongitude(); | ||
|
||
if (latitude < -90.0 || latitude > 90.0 || longitude < -180.0 || longitude > 180.0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe move this check to separate method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
.latitude(ModelUtils.getAddressDto().getLatitude()) | ||
.longitude(ModelUtils.getAddressDto().getLongitude()) | ||
.build(); | ||
when(modelMapper.map(ModelUtils.getAddressLatLngResponse(), AddressDto.class)).thenReturn(build); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this AddressDto builder to ModelsUtils class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
… ModelUtils, replace '==' with Objects.isNull(), extract coordinate validation to a separate method
} | ||
|
||
private boolean isValidCoordinate(double latitude, double longitude) { | ||
return latitude >= -90.0 && latitude <= 90.0 && longitude >= -180.0 && longitude <= 180.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Math.abs(latitude) <= 90.0 && Math.abs(longitude) <= 180.0;
what about such solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
@@ -179,6 +179,9 @@ public class ErrorMessage { | |||
public static final String USER_HAS_NO_FRIEND_WITH_ID = "User has no friend with this id: "; | |||
public static final String INVALID_DURATION = "The duration for such habit is lower than previously set"; | |||
public static final String ADDRESS_NOT_FOUND_EXCEPTION = "No address found for the given coordinates."; | |||
public static final String INVALID_COORDINATES = "The coordinates field must not be empty"; | |||
public static final String INVALID_LONGITUDE = "Longitude must be between -180 and 180 degrees"; | |||
public static final String INVALID_LATITUDE = "Latitude must be between -90 and 90 degrees"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need constants INVALID_LONGITUDE and INVALID_LATITUDE?
You don't use them anywhere.
Quality Gate passedIssues Measures |
GreenCity PR
Issue Link:
7817
Changes:
Current Behavior:
The response now indicates when coordinates are not specified.