From 619cdc7d6abe0272136167b01a0f97f9dffb5916 Mon Sep 17 00:00:00 2001 From: jinsu Date: Mon, 8 Dec 2025 21:07:19 +0900 Subject: [PATCH] =?UTF-8?q?Weather=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=EC=97=90?= =?UTF-8?q?=20Source,=20TargetDate,=20ForecaseDate=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/openweather/handler.go | 14 +++++++++----- internal/pkg/domain/weather_event.go | 18 +++++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/cmd/openweather/handler.go b/cmd/openweather/handler.go index 0c9b492..74c115a 100644 --- a/cmd/openweather/handler.go +++ b/cmd/openweather/handler.go @@ -31,6 +31,8 @@ func NewHandler(broker broker.Broker, key string, lat float64, lon float64) *Han func (h *Handler) Handle(ctx context.Context) error { log.Println("get forecast") + now := time.Now() + forecast, err := openweather.Forecast(ctx, h.key, h.lat, h.lon) if err != nil { return fmt.Errorf("error in get forecast: %w", err) @@ -40,11 +42,13 @@ func (h *Handler) Handle(ctx context.Context) error { for _, list := range forecast.List { weatherEvent := domain.WeatherEvent{ - Date: time.Unix(int64(list.Dt), 0), - Condition: decideCondition(list.Weather), - Temperature: &domain.Temperature{Value: domain.Celsius(list.Main.Temp)}, - High: &domain.Temperature{Value: domain.Celsius(list.Main.TempMax)}, - Low: &domain.Temperature{Value: domain.Celsius(list.Main.TempMin)}, + Source: domain.WeatherSourceOpenWeather, + ForecastDate: now, + TargetDate: time.Unix(int64(list.Dt), 0), + Condition: decideCondition(list.Weather), + Temperature: domain.Temperature{ + Value: domain.Celsius(list.Main.Temp), + }, } message, err := json.Marshal(&weatherEvent) diff --git a/internal/pkg/domain/weather_event.go b/internal/pkg/domain/weather_event.go index cccc8d0..5fe4388 100644 --- a/internal/pkg/domain/weather_event.go +++ b/internal/pkg/domain/weather_event.go @@ -8,10 +8,18 @@ type Temperature struct { Value Celsius `json:"value"` } +type WeatherSource string + +const ( + WeatherSourceOpenWeather WeatherSource = "openweather" + WeatherSourceKMA WeatherSource = "kma" +) + type WeatherEvent struct { - Date time.Time `json:"date"` - Condition WeatherCondition `json:"condition"` - Temperature *Temperature `json:"temperature,omitempty"` - High *Temperature `json:"high,omitempty"` - Low *Temperature `json:"low,omitempty"` + // Source is the source of the weather event. openweather, kma etc + Source WeatherSource `json:"source"` + TargetDate time.Time `json:"target_date"` + ForecastDate time.Time `json:"forecast_date"` + Condition WeatherCondition `json:"condition"` + Temperature Temperature `json:"temperature,omitzero"` }