Files
weatherapi/internal/adapters/inbound/httpapi/observations_endpoint.go
Eric Rakestraw 6806de3c0a
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
Added support for rounding of values by default in API responses
2026-03-20 11:30:11 -05:00

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"),
)
}