Files
weatherapi/internal/app/service.go

63 lines
2.2 KiB
Go
Raw Normal View History

// service.go defines application read ports and use-case orchestration.
// Layer: internal/app core business-facing API.
package app
2026-03-19 19:52:13 -05:00
import (
"context"
"gitea.maximumdirect.net/ejr/weatherfeeder/model"
)
// Repository defines outbound data access used by weatherapi use cases.
type Repository interface {
LatestObservation(ctx context.Context) (*model.WeatherObservation, error)
LatestHourlyForecast(ctx context.Context) (*model.WeatherForecastRun, error)
LatestNarrativeForecast(ctx context.Context) (*model.WeatherForecastRun, error)
LatestForecastDiscussion(ctx context.Context) (*model.WeatherForecastDiscussion, error)
2026-05-30 07:06:29 -05:00
LatestWeatherStoryRun(ctx context.Context) (*model.WeatherStoryRun, error)
LatestWeatherStory(ctx context.Context) (*model.WeatherStory, error)
LatestAlertRun(ctx context.Context) (*model.WeatherAlertRun, error)
2026-03-19 23:16:26 -05:00
CurrentConditions(ctx context.Context, observationWindowMinutes int) (*CurrentConditions, error)
2026-03-19 19:52:13 -05:00
}
// Service provides weather read use-cases.
type Service struct {
repo Repository
}
func NewService(repo Repository) *Service {
return &Service{repo: repo}
}
func (s *Service) LatestObservation(ctx context.Context) (*model.WeatherObservation, error) {
return s.repo.LatestObservation(ctx)
}
func (s *Service) LatestHourlyForecast(ctx context.Context) (*model.WeatherForecastRun, error) {
return s.repo.LatestHourlyForecast(ctx)
}
func (s *Service) LatestNarrativeForecast(ctx context.Context) (*model.WeatherForecastRun, error) {
return s.repo.LatestNarrativeForecast(ctx)
}
func (s *Service) LatestForecastDiscussion(ctx context.Context) (*model.WeatherForecastDiscussion, error) {
return s.repo.LatestForecastDiscussion(ctx)
}
2026-05-30 07:06:29 -05:00
func (s *Service) LatestWeatherStoryRun(ctx context.Context) (*model.WeatherStoryRun, error) {
return s.repo.LatestWeatherStoryRun(ctx)
}
func (s *Service) LatestWeatherStory(ctx context.Context) (*model.WeatherStory, error) {
return s.repo.LatestWeatherStory(ctx)
}
func (s *Service) LatestAlertRun(ctx context.Context) (*model.WeatherAlertRun, error) {
return s.repo.LatestAlertRun(ctx)
2026-03-19 19:52:13 -05:00
}
2026-03-19 23:16:26 -05:00
func (s *Service) CurrentConditions(ctx context.Context) (*CurrentConditions, error) {
return s.repo.CurrentConditions(ctx, ObservationWindowMinutesDefault)
}