Added new endpoints under /forecast/narrative
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful

This commit is contained in:
2026-03-27 22:39:17 -05:00
parent 78dc7817e9
commit 291a9178c8
10 changed files with 360 additions and 19 deletions

View File

@@ -1,4 +1,4 @@
// forecast_queries.go contains SQL text for hourly forecast reads.
// forecast_queries.go contains SQL text for forecast reads.
// Layer: adapters/outbound/postgres forecast feature.
package postgres
@@ -17,6 +17,22 @@ SELECT
FROM forecasts
WHERE product = 'hourly'
ORDER BY issued_at DESC, event_emitted_at DESC
LIMIT 1`
queryLatestNarrativeForecast = `
SELECT
event_id,
location_id,
location_name,
issued_at,
updated_at,
product,
latitude,
longitude,
elevation_meters
FROM forecasts
WHERE product = 'narrative'
ORDER BY issued_at DESC, event_emitted_at DESC
LIMIT 1`
queryForecastPeriods = `

View File

@@ -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)