72 lines
2.2 KiB
Go
72 lines
2.2 KiB
Go
package platform
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
)
|
|
|
|
type Store interface {
|
|
DashboardSummary(context.Context) (DashboardSummary, error)
|
|
Vehicles(context.Context, url.Values) (Page[VehicleRow], error)
|
|
RealtimeLocations(context.Context, url.Values) (Page[RealtimeLocationRow], error)
|
|
HistoryLocations(context.Context, url.Values) (Page[HistoryLocationRow], error)
|
|
RawFrames(context.Context, RawFrameQuery) (Page[RawFrameRow], error)
|
|
DailyMileage(context.Context, url.Values) (Page[DailyMileageRow], error)
|
|
QualityIssues(context.Context, url.Values) (Page[QualityIssueRow], error)
|
|
OpsHealth(context.Context) (OpsHealth, error)
|
|
}
|
|
|
|
type RawFrameQuery struct {
|
|
Protocol string `json:"protocol"`
|
|
VIN string `json:"vin"`
|
|
DateFrom string `json:"dateFrom"`
|
|
DateTo string `json:"dateTo"`
|
|
Fields []string `json:"fields"`
|
|
IncludeFields bool `json:"includeFields"`
|
|
Limit int `json:"limit"`
|
|
Offset int `json:"offset"`
|
|
}
|
|
|
|
type Service struct {
|
|
store Store
|
|
}
|
|
|
|
func NewService(store Store) *Service {
|
|
return &Service{store: store}
|
|
}
|
|
|
|
func (s *Service) DashboardSummary(ctx context.Context) (DashboardSummary, error) {
|
|
return s.store.DashboardSummary(ctx)
|
|
}
|
|
|
|
func (s *Service) Vehicles(ctx context.Context, query url.Values) (Page[VehicleRow], error) {
|
|
return s.store.Vehicles(ctx, query)
|
|
}
|
|
|
|
func (s *Service) RealtimeLocations(ctx context.Context, query url.Values) (Page[RealtimeLocationRow], error) {
|
|
return s.store.RealtimeLocations(ctx, query)
|
|
}
|
|
|
|
func (s *Service) HistoryLocations(ctx context.Context, query url.Values) (Page[HistoryLocationRow], error) {
|
|
return s.store.HistoryLocations(ctx, query)
|
|
}
|
|
|
|
func (s *Service) RawFrames(ctx context.Context, query RawFrameQuery) (Page[RawFrameRow], error) {
|
|
if query.Limit <= 0 || query.Limit > 500 {
|
|
query.Limit = 100
|
|
}
|
|
return s.store.RawFrames(ctx, query)
|
|
}
|
|
|
|
func (s *Service) DailyMileage(ctx context.Context, query url.Values) (Page[DailyMileageRow], error) {
|
|
return s.store.DailyMileage(ctx, query)
|
|
}
|
|
|
|
func (s *Service) QualityIssues(ctx context.Context, query url.Values) (Page[QualityIssueRow], error) {
|
|
return s.store.QualityIssues(ctx, query)
|
|
}
|
|
|
|
func (s *Service) OpsHealth(ctx context.Context) (OpsHealth, error) {
|
|
return s.store.OpsHealth(ctx)
|
|
}
|