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_endpoint.go defines the /forecast/hourly endpoint behavior.
|
||||
// forecast_endpoint.go defines forecast endpoint behavior.
|
||||
// Layer: adapters/inbound/httpapi forecast route.
|
||||
package httpapi
|
||||
|
||||
@@ -24,19 +24,43 @@ const (
|
||||
var forecastNow = time.Now
|
||||
|
||||
func forecastDefinitions(svc Service) []endpoint.Definition {
|
||||
out := make([]endpoint.Definition, 0, 6)
|
||||
out = append(out, forecastDefinitionSet(
|
||||
"/forecast/hourly",
|
||||
"forecast_hourly.txt.tmpl",
|
||||
svc.LatestHourlyForecast,
|
||||
)...)
|
||||
out = append(out, forecastDefinitionSet(
|
||||
"/forecast/narrative",
|
||||
"forecast_narrative.txt.tmpl",
|
||||
svc.LatestNarrativeForecast,
|
||||
)...)
|
||||
return out
|
||||
}
|
||||
|
||||
func forecastDefinitionSet(
|
||||
basePath string,
|
||||
templateName string,
|
||||
fetch func(context.Context) (*model.WeatherForecastRun, error),
|
||||
) []endpoint.Definition {
|
||||
return []endpoint.Definition{
|
||||
forecastDefinition(svc, "/forecast/hourly", forecastDaySliceAll),
|
||||
forecastDefinition(svc, "/forecast/hourly/today", forecastDaySliceToday),
|
||||
forecastDefinition(svc, "/forecast/hourly/tomorrow", forecastDaySliceTomorrow),
|
||||
forecastDefinition(basePath, forecastDaySliceAll, templateName, fetch),
|
||||
forecastDefinition(basePath+"/today", forecastDaySliceToday, templateName, fetch),
|
||||
forecastDefinition(basePath+"/tomorrow", forecastDaySliceTomorrow, templateName, fetch),
|
||||
}
|
||||
}
|
||||
|
||||
func forecastDefinition(svc Service, path string, daySlice forecastDaySlice) endpoint.Definition {
|
||||
func forecastDefinition(
|
||||
path string,
|
||||
daySlice forecastDaySlice,
|
||||
templateName string,
|
||||
fetch func(context.Context) (*model.WeatherForecastRun, error),
|
||||
) endpoint.Definition {
|
||||
return endpoint.GET(
|
||||
path,
|
||||
bindForecastPrecisionQuery,
|
||||
func(ctx context.Context, req precisionQueryRequest) (any, error) {
|
||||
run, err := svc.LatestHourlyForecast(ctx)
|
||||
run, err := fetch(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -48,7 +72,7 @@ func forecastDefinition(svc Service, path string, daySlice forecastDaySlice) end
|
||||
return response.Envelope{Data: presenter.ForecastPayload(run, req.Units, req.Precision, req.Timezone)}, nil
|
||||
},
|
||||
endpoint.WithProduces(render.FormatJSON, render.FormatXML, render.FormatText),
|
||||
endpoint.WithTemplate("forecast_hourly.txt.tmpl"),
|
||||
endpoint.WithTemplate(templateName),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user