Skip to content

Commit

Permalink
- Fix: adding more validations
Browse files Browse the repository at this point in the history
  • Loading branch information
FarukBraimo committed Jun 20, 2024
1 parent d6b0477 commit 2a1533f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import jakarta.validation.constraints.Size;

public record AuthLoginRequest(
@NotBlank(message = "Username should not be null or empty") @Pattern(regexp = "[a-zA-Z0-9 ]")
@NotBlank(message = "Username should not be null or empty" )
String username,
@NotBlank(message = "Username should not be null or empty") @Size(min = 6, max = 64)
@NotBlank(message = "Username should not be null or empty")
String password) {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.vodacom.falcon.model.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

public record UserRegistrationRequest(@NotBlank(message = "Username should not be null or empty") String username,
@NotBlank(message = "Username should not be null or empty") String password) {
@NotBlank(message = "Username should not be null or empty") @Size(min = 6, max = 64) String password) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class InsightService {

public InsightResponse getInsight(String city) throws ResourceNotFoundException {
log.info("Getting insights for {}", city);
ValidationFactory.validateSearch("Country", city);
ValidationFactory.validateSearch("City", city);

MetadataResponse metadata = new MetadataResponse();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public class WeatherForecastService {
@Value("${open-weather-map.apiKeyV3}")
private String openWeatherApiKeyV3;

private final String OPEN_WEATHER_API_VERSION = "2.5"; // TODO: Add feature flag Or row controller, to determine the version to use. (2.5 0r 3.0)
private final String OPEN_WEATHER_API_VERSION = "3.0"; // TODO: Add feature flag Or row controller, to determine the version to use. (2.5 0r 3.0)

// TODO: CACHE THE RESPONSE
public WeatherForecastResponse getWeatherForecast(String city) throws ResourceNotFoundException {
return WeatherForecastResponse
.builder()
Expand All @@ -41,10 +40,10 @@ private OpenWeatherForecastResponse buildWeatherForecast(String city) throws Res

if (location == null) {
log.info("Couldn't find location for {}", city);
throw new ResourceNotFoundException(String.format("Location: %s Not found", city));
throw new ResourceNotFoundException(String.format("City: %s Not found", city));
}

String url = String.format("%s/data/%s/onecall?units=metric&cnt=4&exclude=hourly,minutely,alerts&lat=%s&lon=%s&appid=%s", FalconDefaults.OPEN_WEATHER_API_BASE_URL, OPEN_WEATHER_API_VERSION, location.getLat(), location.getLon(), openWeatherApiKeyV2);
String url = String.format("%s/data/%s/onecall?units=metric&cnt=4&exclude=hourly,minutely,alerts&lat=%s&lon=%s&appid=%s", FalconDefaults.OPEN_WEATHER_API_BASE_URL, OPEN_WEATHER_API_VERSION, location.getLat(), location.getLon(), openWeatherApiKeyV3);
HttpResponse<String> response = APICaller.getData(url);
if (response != null) {
OpenWeatherForecastResponse openWeatherForecast = deserialize(response.body(), OpenWeatherForecastResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class ValidationFactory {
public static void validateSearch(String term, String value) throws ResourceNotFoundException {
boolean isValid = value != null && value.length() > 3 && value.matches("^[a-zA-Z]*$");
boolean isValid = value != null && value.length() > 3;
if (!isValid) {
throw new ResourceNotFoundException(String.format("Please provide a valid: %s", term));
}
Expand Down

0 comments on commit 2a1533f

Please sign in to comment.