Weather 이벤트에 Source, TargetDate, ForecaseDate 추가

This commit is contained in:
2025-12-08 21:07:19 +09:00
parent 4742d8f01d
commit 619cdc7d6a
2 changed files with 22 additions and 10 deletions

View File

@@ -31,6 +31,8 @@ func NewHandler(broker broker.Broker, key string, lat float64, lon float64) *Han
func (h *Handler) Handle(ctx context.Context) error { func (h *Handler) Handle(ctx context.Context) error {
log.Println("get forecast") log.Println("get forecast")
now := time.Now()
forecast, err := openweather.Forecast(ctx, h.key, h.lat, h.lon) forecast, err := openweather.Forecast(ctx, h.key, h.lat, h.lon)
if err != nil { if err != nil {
return fmt.Errorf("error in get forecast: %w", err) 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 { for _, list := range forecast.List {
weatherEvent := domain.WeatherEvent{ weatherEvent := domain.WeatherEvent{
Date: time.Unix(int64(list.Dt), 0), Source: domain.WeatherSourceOpenWeather,
Condition: decideCondition(list.Weather), ForecastDate: now,
Temperature: &domain.Temperature{Value: domain.Celsius(list.Main.Temp)}, TargetDate: time.Unix(int64(list.Dt), 0),
High: &domain.Temperature{Value: domain.Celsius(list.Main.TempMax)}, Condition: decideCondition(list.Weather),
Low: &domain.Temperature{Value: domain.Celsius(list.Main.TempMin)}, Temperature: domain.Temperature{
Value: domain.Celsius(list.Main.Temp),
},
} }
message, err := json.Marshal(&weatherEvent) message, err := json.Marshal(&weatherEvent)

View File

@@ -8,10 +8,18 @@ type Temperature struct {
Value Celsius `json:"value"` Value Celsius `json:"value"`
} }
type WeatherSource string
const (
WeatherSourceOpenWeather WeatherSource = "openweather"
WeatherSourceKMA WeatherSource = "kma"
)
type WeatherEvent struct { type WeatherEvent struct {
Date time.Time `json:"date"` // Source is the source of the weather event. openweather, kma etc
Condition WeatherCondition `json:"condition"` Source WeatherSource `json:"source"`
Temperature *Temperature `json:"temperature,omitempty"` TargetDate time.Time `json:"target_date"`
High *Temperature `json:"high,omitempty"` ForecastDate time.Time `json:"forecast_date"`
Low *Temperature `json:"low,omitempty"` Condition WeatherCondition `json:"condition"`
Temperature Temperature `json:"temperature,omitzero"`
} }