Files
weatherapi/internal/adapters/inbound/httpapi/weatherstories_endpoint.go
Eric Rakestraw ecea856e8e
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
Implemented weather stories support
2026-05-30 07:06:29 -05:00

44 lines
1.4 KiB
Go

// weatherstories_endpoint.go defines the /weatherstories endpoint behavior.
// Layer: adapters/inbound/httpapi weather stories route.
package httpapi
import (
"context"
"gitea.maximumdirect.net/ejr/feedapi/endpoint"
"gitea.maximumdirect.net/ejr/feedapi/render"
"gitea.maximumdirect.net/ejr/feedapi/response"
"gitea.maximumdirect.net/ejr/weatherapi/internal/adapters/inbound/httpapi/presenter"
)
func weatherStoriesDefinitions(svc Service) []endpoint.Definition {
return []endpoint.Definition{
endpoint.GET(
"/weatherstories",
bindTimezoneQuery,
func(ctx context.Context, req timezoneQueryRequest) (any, error) {
run, err := svc.LatestWeatherStoryRun(ctx)
if err != nil {
return nil, err
}
return response.Envelope{Data: presenter.WeatherStoryRunPayload(run, req.Units, req.Timezone)}, nil
},
endpoint.WithProduces(render.FormatJSON, render.FormatXML, render.FormatText),
endpoint.WithTemplate("weatherstories.txt.tmpl"),
),
endpoint.GET(
"/weatherstories/latest",
bindTimezoneQuery,
func(ctx context.Context, req timezoneQueryRequest) (any, error) {
story, err := svc.LatestWeatherStory(ctx)
if err != nil {
return nil, err
}
return response.Envelope{Data: presenter.WeatherStoryPayload(story, req.Units, req.Timezone)}, nil
},
endpoint.WithProduces(render.FormatJSON, render.FormatXML, render.FormatText),
endpoint.WithTemplate("weatherstories_latest.txt.tmpl"),
),
}
}