-
Notifications
You must be signed in to change notification settings - Fork 1
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
✨ feat(batch): recommend music based on real time weather #472
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.depromeet.config; | ||
|
||
import com.depromeet.external.feign.client.OpenApiFeignClient; | ||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableFeignClients(clients = OpenApiFeignClient.class) | ||
public class FeignConfig { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.depromeet.domains.weather.jobs; | ||
|
||
import com.depromeet.domains.weather.service.WeatherService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class RealTimeWeatherJob { | ||
|
||
private final WeatherService weatherService; | ||
|
||
public void run() { | ||
weatherService.getRealTimeWeather(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.depromeet.domains.weather.response.dto; | ||
|
||
public record BodyDto( | ||
String dataType, | ||
ItemsDto items, | ||
int pageNo, | ||
int numOfRows, | ||
int totalCount | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.depromeet.domains.weather.response.dto; | ||
|
||
public record HeaderDto( | ||
String resultCode, | ||
String resultMsg | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.depromeet.domains.weather.response.dto; | ||
|
||
public record ItemDto( | ||
String baseDate, | ||
String baseTime, | ||
String category, | ||
int nx, | ||
int ny, | ||
String obsrValue | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.depromeet.domains.weather.response.dto; | ||
|
||
import java.util.List; | ||
|
||
public record ItemsDto( | ||
List<ItemDto> item | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.depromeet.domains.weather.response.dto; | ||
|
||
public record ResponseDto( | ||
HeaderDto header, | ||
BodyDto body | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.depromeet.domains.weather.response.dto; | ||
|
||
public record WeatherResponseDto( | ||
ResponseDto response | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.depromeet.domains.weather.scheduler; | ||
|
||
import com.depromeet.domains.weather.jobs.RealTimeWeatherJob; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class RealTimeWeatherBatchScheduler { | ||
|
||
private final RealTimeWeatherJob realTimeWeatherJob; | ||
|
||
@Scheduled(cron = "0 0 */3 * * *") | ||
public void runWeatherJob() { | ||
realTimeWeatherJob.run(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.depromeet.domains.weather.service; | ||
|
||
import com.depromeet.external.feign.client.OpenApiFeignClient; | ||
import com.depromeet.domains.weather.response.dto.WeatherResponseDto; | ||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
import java.time.format.DateTimeFormatter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class WeatherService { | ||
|
||
@Value("${open-api.secret-key}") | ||
private String openApiKey; | ||
|
||
private final OpenApiFeignClient openApiFeignClient; | ||
|
||
public WeatherResponseDto getRealTimeWeather() { | ||
String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); | ||
String time = LocalTime.now().format(DateTimeFormatter.ofPattern("HHmm")); | ||
|
||
return openApiFeignClient.getRealTimeWeather(openApiKey, 1, 8, "json", date, time, 60, 125); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.depromeet.external.feign.client; | ||
|
||
import com.depromeet.config.FeignConfig; | ||
import com.depromeet.domains.weather.response.dto.WeatherResponseDto; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@FeignClient(name = "openApiFeignClient", url = "${open-api.base-url}", configuration = FeignConfig.class) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 MVC나 Webflux가 아니라 Feign을 쓰신 이유가 있으신지 궁금합니다! 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 외부 API와 통신하는 방법으로 5가지 정도 고민했어요.
성능을 결정하는 요인은 외부 API의 속도라고 생각해서 어떤 기술을 쓰든 성능은 비슷할 것이라 생각했어요. |
||
public interface OpenApiFeignClient { | ||
|
||
@GetMapping(value = "${open-api.weather-api-url}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
WeatherResponseDto getRealTimeWeather( | ||
@RequestParam("serviceKey") String serviceKey, | ||
@RequestParam("pageNo") int pageNo, | ||
@RequestParam("numOfRows") int numOfRows, | ||
@RequestParam("dataType") String dataType, | ||
@RequestParam("base_date") String baseDate, | ||
@RequestParam("base_time") String baseTime, | ||
@RequestParam("nx") int nx, | ||
@RequestParam("ny") int ny); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 파라미터가 많아서 @RequestParam보다는 객체나 @RequestBody로 받는 것은 어떨까요? 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open API로 요청을 보내는 부분이에요! |
||
|
||
} |
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.
소스코드에 cron 시간을 설정하면 나중에 시간을 변경하고 싶을때 소스코드 변경 및 애플리케이션 재배포가
필요해서 rundeck 같은 오픈소스나 aws event trigger 같은 거 다같이 논의해서 써보면 어떨까여? 👍
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.
외부에서 변경을 할 수 있군요 👀
안건 올려두겠습니다. 다음 회의 때 논의해 보아요!