From 3bb632e3f10be548f670653b2052bf012a81e47f Mon Sep 17 00:00:00 2001 From: Alexander Kim Date: Thu, 26 Jun 2025 18:42:46 +0300 Subject: [PATCH 1/4] feat: separate services logic, add interfaces --- .../climify/Client/Interfaces/IWeatherApiClient.java | 7 +++++++ .../java/com/climify/Client/WeatherApiClient.java | 3 ++- .../com/climify/Controllers/WeatherController.java | 6 +++--- .../main/java/com/climify/Services/CacheService.java | 3 ++- .../climify/Services/Interfaces/ICacheService.java | 8 ++++++++ .../climify/Services/Interfaces/IWeatherService.java | 7 +++++++ .../java/com/climify/Services/WeatherService.java | 12 +++++++----- 7 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 backend/src/main/java/com/climify/Client/Interfaces/IWeatherApiClient.java create mode 100644 backend/src/main/java/com/climify/Services/Interfaces/ICacheService.java create mode 100644 backend/src/main/java/com/climify/Services/Interfaces/IWeatherService.java 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..f60d7d4 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,7 +10,7 @@ import java.time.Duration; @Service -public class CacheService { +public class CacheService implements ICacheService { private final RedisTemplate redisTemplate; private final ValueOperations valueOperations; 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; } From 18d65729e7380ba1640b4c019c01bb3772af7532 Mon Sep 17 00:00:00 2001 From: Alexander Kim Date: Thu, 26 Jun 2025 18:43:50 +0300 Subject: [PATCH 2/4] refactor: convert field to a local variable --- backend/src/main/java/com/climify/Services/CacheService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/src/main/java/com/climify/Services/CacheService.java b/backend/src/main/java/com/climify/Services/CacheService.java index f60d7d4..040856b 100644 --- a/backend/src/main/java/com/climify/Services/CacheService.java +++ b/backend/src/main/java/com/climify/Services/CacheService.java @@ -12,12 +12,10 @@ @Service 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(); } From 9e72927e4ef304f1f950ad04a0fd1b9860ac7dd6 Mon Sep 17 00:00:00 2001 From: Alexander Kim Date: Thu, 26 Jun 2025 23:33:36 +0300 Subject: [PATCH 3/4] refactor: update application.yaml --- backend/src/main/resources/application.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From 99a8f6d48990a0d4ca2cc57ec07555b3e12a6986 Mon Sep 17 00:00:00 2001 From: Alexander Kim Date: Thu, 26 Jun 2025 23:33:50 +0300 Subject: [PATCH 4/4] feat: add CI --- .github/workflows/java.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/java.yml 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