diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml new file mode 100644 index 0000000..c5298c3 --- /dev/null +++ b/.github/workflows/java.yml @@ -0,0 +1,16 @@ +name: Java CI +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 21 + uses: actions/setup-java@v2 + with: + java-version: '21' + distribution: 'temurin' + - name: Build with Maven + run: mvn --batch-mode --update-snapshots package \ No newline at end of file diff --git a/backend/src/main/java/com/climify/Client/Interfaces/IWeatherApiClient.java b/backend/src/main/java/com/climify/Client/Interfaces/IWeatherApiClient.java new file mode 100644 index 0000000..05fc25f --- /dev/null +++ b/backend/src/main/java/com/climify/Client/Interfaces/IWeatherApiClient.java @@ -0,0 +1,7 @@ +package com.climify.Client.Interfaces; + +import com.climify.Models.DTO.WeatherResponse; + +public interface IWeatherApiClient { + WeatherResponse fetchWeather(String city); +} diff --git a/backend/src/main/java/com/climify/Client/WeatherApiClient.java b/backend/src/main/java/com/climify/Client/WeatherApiClient.java index 161ec75..4b8bd67 100644 --- a/backend/src/main/java/com/climify/Client/WeatherApiClient.java +++ b/backend/src/main/java/com/climify/Client/WeatherApiClient.java @@ -1,5 +1,6 @@ package com.climify.Client; +import com.climify.Client.Interfaces.IWeatherApiClient; import com.climify.Models.DTO.WeatherResponse; import com.climify.Models.Exceptions.CityNotFoundException; import com.climify.Models.Exceptions.WeatherApiException; @@ -8,7 +9,7 @@ import org.springframework.web.client.RestTemplate; @Service -public class WeatherApiClient { +public class WeatherApiClient implements IWeatherApiClient { private final RestTemplate restTemplate; private final String apiKey; diff --git a/backend/src/main/java/com/climify/Controllers/WeatherController.java b/backend/src/main/java/com/climify/Controllers/WeatherController.java index f75beea..3dc158b 100644 --- a/backend/src/main/java/com/climify/Controllers/WeatherController.java +++ b/backend/src/main/java/com/climify/Controllers/WeatherController.java @@ -1,7 +1,7 @@ package com.climify.Controllers; import com.climify.Models.DTO.WeatherResponse; -import com.climify.Services.WeatherService; +import com.climify.Services.Interfaces.IWeatherService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -17,10 +17,10 @@ @RestController @RequestMapping("climify/api/weather") public class WeatherController { - private final WeatherService weatherService; + private final IWeatherService weatherService; @Autowired - public WeatherController(WeatherService weatherService) { + public WeatherController(IWeatherService weatherService) { this.weatherService = weatherService; } diff --git a/backend/src/main/java/com/climify/Services/CacheService.java b/backend/src/main/java/com/climify/Services/CacheService.java index 1ad2098..040856b 100644 --- a/backend/src/main/java/com/climify/Services/CacheService.java +++ b/backend/src/main/java/com/climify/Services/CacheService.java @@ -1,6 +1,7 @@ package com.climify.Services; import com.climify.Models.DTO.WeatherResponse; +import com.climify.Services.Interfaces.ICacheService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ValueOperations; @@ -9,14 +10,12 @@ import java.time.Duration; @Service -public class CacheService { +public class CacheService implements ICacheService { - private final RedisTemplate redisTemplate; private final ValueOperations valueOperations; @Autowired public CacheService(RedisTemplate redisTemplate) { - this.redisTemplate = redisTemplate; this.valueOperations = redisTemplate.opsForValue(); } diff --git a/backend/src/main/java/com/climify/Services/Interfaces/ICacheService.java b/backend/src/main/java/com/climify/Services/Interfaces/ICacheService.java new file mode 100644 index 0000000..9783f84 --- /dev/null +++ b/backend/src/main/java/com/climify/Services/Interfaces/ICacheService.java @@ -0,0 +1,8 @@ +package com.climify.Services.Interfaces; + +import com.climify.Models.DTO.WeatherResponse; + +public interface ICacheService { + WeatherResponse get(String city); + void put(String city, WeatherResponse weatherResponse); +} diff --git a/backend/src/main/java/com/climify/Services/Interfaces/IWeatherService.java b/backend/src/main/java/com/climify/Services/Interfaces/IWeatherService.java new file mode 100644 index 0000000..a60b350 --- /dev/null +++ b/backend/src/main/java/com/climify/Services/Interfaces/IWeatherService.java @@ -0,0 +1,7 @@ +package com.climify.Services.Interfaces; + +import com.climify.Models.DTO.WeatherResponse; + +public interface IWeatherService { + WeatherResponse getWeather(String city); +} diff --git a/backend/src/main/java/com/climify/Services/WeatherService.java b/backend/src/main/java/com/climify/Services/WeatherService.java index e10b5de..b86124e 100644 --- a/backend/src/main/java/com/climify/Services/WeatherService.java +++ b/backend/src/main/java/com/climify/Services/WeatherService.java @@ -1,19 +1,21 @@ package com.climify.Services; -import com.climify.Client.WeatherApiClient; +import com.climify.Client.Interfaces.IWeatherApiClient; import com.climify.Models.DTO.WeatherResponse; import com.climify.Models.Exceptions.WeatherNotFoundException; +import com.climify.Services.Interfaces.ICacheService; +import com.climify.Services.Interfaces.IWeatherService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service -public class WeatherService { +public class WeatherService implements IWeatherService { - private final WeatherApiClient weatherApiClient; - private final CacheService cacheService; + private final IWeatherApiClient weatherApiClient; + private final ICacheService cacheService; @Autowired - public WeatherService(WeatherApiClient weatherApiClient, CacheService cacheService) { + public WeatherService(IWeatherApiClient weatherApiClient, ICacheService cacheService) { this.weatherApiClient = weatherApiClient; this.cacheService = cacheService; } diff --git a/backend/src/main/resources/application.yaml b/backend/src/main/resources/application.yaml index 6e27d6d..6299c64 100644 --- a/backend/src/main/resources/application.yaml +++ b/backend/src/main/resources/application.yaml @@ -33,8 +33,8 @@ springdoc: logging: level: com.climify: DEBUG -# root: DEBUG # org.springframework: DEBUG +# root: DEBUG management: endpoints: