All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
29 lines
918 B
Go
29 lines
918 B
Go
// observations_endpoint.go defines the /observations endpoint behavior.
|
|
// Layer: adapters/inbound/httpapi observation 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 observationDefinition(svc Service) endpoint.Definition {
|
|
return endpoint.GET(
|
|
"/observations",
|
|
bindPrecisionQuery,
|
|
func(ctx context.Context, req precisionQueryRequest) (any, error) {
|
|
obs, err := svc.LatestObservation(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return response.Envelope{Data: presenter.ObservationPayload(obs, req.Units, req.Precision)}, nil
|
|
},
|
|
endpoint.WithProduces(render.FormatJSON, render.FormatXML, render.FormatText),
|
|
endpoint.WithTemplate("observations.txt.tmpl"),
|
|
)
|
|
}
|