Added new endpoints under /forecast/narrative
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// forecast_read.go executes hourly forecast and period queries.
|
||||
// forecast_read.go executes forecast and period queries.
|
||||
// Layer: adapters/outbound/postgres forecast feature.
|
||||
package postgres
|
||||
|
||||
@@ -12,12 +12,24 @@ import (
|
||||
)
|
||||
|
||||
func (r *Repository) LatestHourlyForecast(ctx context.Context) (*model.WeatherForecastRun, error) {
|
||||
return r.loadLatestForecastRun(ctx, queryLatestHourlyForecast, "hourly")
|
||||
}
|
||||
|
||||
func (r *Repository) LatestNarrativeForecast(ctx context.Context) (*model.WeatherForecastRun, error) {
|
||||
return r.loadLatestForecastRun(ctx, queryLatestNarrativeForecast, "narrative")
|
||||
}
|
||||
|
||||
func (r *Repository) loadLatestForecastRun(
|
||||
ctx context.Context,
|
||||
parentQuery string,
|
||||
productLabel string,
|
||||
) (*model.WeatherForecastRun, error) {
|
||||
if r == nil || r.db == nil {
|
||||
return nil, fmt.Errorf("postgres repository is not configured")
|
||||
}
|
||||
|
||||
var row forecastParentRow
|
||||
err := r.db.QueryRowContext(ctx, queryLatestHourlyForecast).Scan(
|
||||
err := r.db.QueryRowContext(ctx, parentQuery).Scan(
|
||||
&row.EventID,
|
||||
&row.LocationID,
|
||||
&row.LocationName,
|
||||
@@ -32,7 +44,7 @@ func (r *Repository) LatestHourlyForecast(ctx context.Context) (*model.WeatherFo
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query latest hourly forecast: %w", err)
|
||||
return nil, fmt.Errorf("query latest %s forecast: %w", productLabel, err)
|
||||
}
|
||||
|
||||
run := mapForecastParentRow(row)
|
||||
|
||||
Reference in New Issue
Block a user