Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.climify.Client.Interfaces;

import com.climify.Models.DTO.WeatherResponse;

public interface IWeatherApiClient {
WeatherResponse fetchWeather(String city);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}

Expand Down
5 changes: 2 additions & 3 deletions backend/src/main/java/com/climify/Services/CacheService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,14 +10,12 @@
import java.time.Duration;

@Service
public class CacheService {
public class CacheService implements ICacheService {

private final RedisTemplate<String, WeatherResponse> redisTemplate;
private final ValueOperations<String, WeatherResponse> valueOperations;

@Autowired
public CacheService(RedisTemplate<String, WeatherResponse> redisTemplate) {
this.redisTemplate = redisTemplate;
this.valueOperations = redisTemplate.opsForValue();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.climify.Services.Interfaces;

import com.climify.Models.DTO.WeatherResponse;

public interface IWeatherService {
WeatherResponse getWeather(String city);
}
12 changes: 7 additions & 5 deletions backend/src/main/java/com/climify/Services/WeatherService.java
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ springdoc:
logging:
level:
com.climify: DEBUG
# root: DEBUG
# org.springframework: DEBUG
# root: DEBUG

management:
endpoints:
Expand Down