Add weather API bundle adapter

This commit is contained in:
2026-05-29 17:06:39 +00:00
parent 8c065751c2
commit a885959d39
17 changed files with 1264 additions and 18 deletions

View File

@@ -6,7 +6,9 @@ import (
"fmt"
"time"
"gitea.maximumdirect.net/eric/weatherreporter/internal/adapters/weatherapi"
"gitea.maximumdirect.net/eric/weatherreporter/internal/config"
"gitea.maximumdirect.net/eric/weatherreporter/internal/forecast"
)
type ReportKind string
@@ -40,6 +42,11 @@ type BatchRequest struct {
Batch BatchKind
}
type FetchBundleRequest struct {
Config config.Config
OutputPath string
}
func Generate(ctx context.Context, req GenerateRequest) error {
_ = ctx
_ = req
@@ -51,3 +58,29 @@ func RunBatch(ctx context.Context, req BatchRequest) error {
_ = req
return fmt.Errorf("run is not implemented")
}
func FetchBundle(ctx context.Context, req FetchBundleRequest) (*forecast.Bundle, error) {
client, err := weatherapi.New(req.Config)
if err != nil {
return nil, err
}
bundle, err := client.FetchBundle(ctx)
if err != nil {
return nil, err
}
return bundle, nil
}
func FetchAndSaveBundle(ctx context.Context, req FetchBundleRequest) (*forecast.Bundle, error) {
if req.OutputPath == "" {
return nil, fmt.Errorf("output path is required")
}
bundle, err := FetchBundle(ctx, req)
if err != nil {
return nil, err
}
if err := weatherapi.SaveBundle(req.OutputPath, bundle); err != nil {
return nil, err
}
return bundle, nil
}