package alerts import ( "context" "fmt" "time" "gitea.maximumdirect.net/ejr/weatherapi/internal/core/ports" ) type Service struct { repo ports.AlertRepository } func NewService(repo ports.AlertRepository) *Service { return &Service{repo: repo} } type Response struct { Alerts []AlertResponse `json:"alerts"` } type AlertResponse struct { Effective *time.Time `json:"effective,omitempty"` Expires *time.Time `json:"expires,omitempty"` Severity *string `json:"severity,omitempty"` Event *string `json:"event,omitempty"` Headline *string `json:"headline,omitempty"` Instruction *string `json:"instruction,omitempty"` Description *string `json:"description,omitempty"` } func (s *Service) GetCurrent(ctx context.Context) (Response, error) { if s == nil { return Response{}, fmt.Errorf("alerts service is nil") } rows, err := s.repo.ListCurrentAlerts(ctx) if err != nil { return Response{}, err } alerts := make([]AlertResponse, 0, len(rows)) for _, row := range rows { alerts = append(alerts, AlertResponse{ Effective: row.Effective, Expires: row.Expires, Severity: row.Severity, Event: row.Event, Headline: row.Headline, Instruction: row.Instruction, Description: row.Description, }) } return Response{Alerts: alerts}, nil }