Documentation ¶
Overview ¶
Package services exposes a services as entrypoints for business logic.
Index ¶
- Constants
- Variables
- type APIKeyService
- type AccountService
- func (s *AccountService) Activate(id uint) (account.Account, error)
- func (s *AccountService) Create(campaign campaign.Campaign) (account.Account, error)
- func (s *AccountService) GetByID(id uint) (account.Account, error)
- func (s *AccountService) GetCloudFeedAuthStatuses(id uint) ([]cloudfeedstatus.CloudFeedStatus, error)
- type AdminService
- func (s *AdminService) Create(name string, expiry time.Time) (admin.Admin, error)
- func (s *AdminService) Delete(admin admin.Admin) error
- func (s *AdminService) Find(admin admin.Admin) (admin.Admin, error)
- func (s *AdminService) GetAll() ([]admin.Admin, error)
- func (s *AdminService) Reactivate(a admin.Admin) (admin.Admin, error)
- func (s *AdminService) SetExpiry(a admin.Admin, expiry time.Time) (admin.Admin, error)
- type AppService
- type AuthorizationService
- func (s *AuthorizationService) CreateToken(kind authorization.AuthKind, id uint, expiry time.Time) (string, error)
- func (s *AuthorizationService) CreateTokenFromAuthorization(auth authorization.Authorization, expiry time.Time) (string, error)
- func (s *AuthorizationService) ParseToken(tokenString string) (authorization.AuthKind, uint, *authorization.Claims, error)
- func (s *AuthorizationService) ParseTokenToAuthorization(tokenString string) (*authorization.Authorization, error)
- type CampaignService
- func (s *CampaignService) Create(name string, app app.App, infoURL string, startTime, endTime *needforheat.Time, ...) (campaign.Campaign, error)
- func (s *CampaignService) Find(campaign campaign.Campaign) (campaign.Campaign, error)
- func (s *CampaignService) GetByID(id uint) (campaign.Campaign, error)
- type CloudFeedService
- func (s *CloudFeedService) Create(ctx context.Context, accountID, cloudFeedTypeID uint, authGrantToken string) (cloudfeed.CloudFeed, error)
- func (s *CloudFeedService) Download(ctx context.Context, cfa cloudfeed.CloudFeed, startPeriod needforheat.Time, ...) error
- func (s *CloudFeedService) DownloadInBackground(ctx context.Context, downloadStartTime time.Time)
- func (s *CloudFeedService) Find(cloudFeed cloudfeed.CloudFeed) (cloudfeed.CloudFeed, error)
- func (s *CloudFeedService) RefreshTokens(ctx context.Context, accountID uint, cloudFeedTypeID uint) (cloudfeed.CloudFeed, error)
- func (s *CloudFeedService) RefreshTokensInBackground(ctx context.Context, preRenewalDuration time.Duration)
- type CloudFeedTypeService
- func (s *CloudFeedTypeService) Create(name string, authorizationURL string, tokenURL string, clientID string, ...) (cloudfeedtype.CloudFeedType, error)
- func (s *CloudFeedTypeService) Find(cloudFeed cloudfeedtype.CloudFeedType) (cloudfeedtype.CloudFeedType, error)
- func (s *CloudFeedTypeService) GetByID(id uint) (cloudfeedtype.CloudFeedType, error)
- func (s *CloudFeedTypeService) GetByIDForDataSourceType(id uint) (interface{}, error)
- func (s *CloudFeedTypeService) GetTableName() string
- type DataSourceListService
- func (s *DataSourceListService) Create(name string, items []datasourcetype.DataSourceType) (datasourcelist.DataSourceList, error)
- func (s *DataSourceListService) Delete(shoppingList datasourcelist.DataSourceList) error
- func (s *DataSourceListService) Find(shoppingList datasourcelist.DataSourceList) (datasourcelist.DataSourceList, error)
- func (s *DataSourceListService) GetAll() ([]datasourcelist.DataSourceList, error)
- type DataSourceTypeService
- func (s *DataSourceTypeService) Create(typeInstanceID uint, category datasourcetype.Category, ...) (datasourcetype.DataSourceType, error)
- func (s *DataSourceTypeService) Delete(dataSourceType datasourcetype.DataSourceType) error
- func (s *DataSourceTypeService) Find(dataSourceType datasourcetype.DataSourceType) (datasourcetype.DataSourceType, error)
- func (s *DataSourceTypeService) GetAll() ([]datasourcetype.DataSourceType, error)
- func (s *DataSourceTypeService) GetSourceByIDAndTable(sourceID uint, table string) (interface{}, Source, error)
- type DeviceService
- func (s *DeviceService) Activate(name, activationSecret string) (device.Device, error)
- func (s *DeviceService) AddUpload(id uint, upload upload.Upload) (device.Device, error)
- func (s *DeviceService) Create(name string, accountID uint, activationSecret string) (device.Device, error)
- func (s *DeviceService) GetAccountByDeviceID(id uint) (uint, error)
- func (s *DeviceService) GetAllByAccount(accountId uint) ([]device.Device, error)
- func (s *DeviceService) GetByID(id uint) (device.Device, error)
- func (s *DeviceService) GetByName(name string) (device.Device, error)
- func (s *DeviceService) GetMeasurementsByDeviceID(id uint, filters map[string]string) ([]measurement.Measurement, error)
- func (s *DeviceService) GetPropertiesByDeviceID(id uint) ([]property.Property, error)
- type DeviceTypeService
- func (s *DeviceTypeService) Create(name string) (devicetype.DeviceType, error)
- func (s *DeviceTypeService) Find(deviceType devicetype.DeviceType) (devicetype.DeviceType, error)
- func (s *DeviceTypeService) GetByHash(deviceTypeHash string) (devicetype.DeviceType, error)
- func (s *DeviceTypeService) GetByID(id uint) (devicetype.DeviceType, error)
- func (s *DeviceTypeService) GetByIDForDataSourceType(id uint) (interface{}, error)
- func (s *DeviceTypeService) GetByName(name string) (devicetype.DeviceType, error)
- func (s *DeviceTypeService) GetTableName() string
- type EnergyQueryService
- func (s *EnergyQueryService) Create(queryType energyquerytype.EnergyQueryType, accountID uint, ...) (energyquery.EnergyQuery, error)
- func (s *EnergyQueryService) GetAccountByEnergyQueryID(id uint) (uint, error)
- func (s *EnergyQueryService) GetAllByAccount(accountId uint) ([]energyquery.EnergyQuery, error)
- func (s *EnergyQueryService) GetByID(id uint) (energyquery.EnergyQuery, error)
- func (s *EnergyQueryService) GetByTypeAndAccount(queryType energyquerytype.EnergyQueryType, accountID uint) (energyquery.EnergyQuery, error)
- func (s *EnergyQueryService) GetMeasurementsByEnergyQueryID(id uint, filters map[string]string) ([]measurement.Measurement, error)
- func (s *EnergyQueryService) GetPropertiesByEnergyQueryID(id uint) ([]property.Property, error)
- type EnergyQueryTypeService
- func (s *EnergyQueryTypeService) Create(variety string, formula string) (energyquerytype.EnergyQueryType, error)
- func (s *EnergyQueryTypeService) Find(energyQueryType energyquerytype.EnergyQueryType) (energyquerytype.EnergyQueryType, error)
- func (s *EnergyQueryTypeService) GetByHash(energyQueryTypeHash string) (energyquerytype.EnergyQueryType, error)
- func (s *EnergyQueryTypeService) GetByID(id uint) (energyquerytype.EnergyQueryType, error)
- func (s *EnergyQueryTypeService) GetByIDForDataSourceType(id uint) (interface{}, error)
- func (s *EnergyQueryTypeService) GetByVariety(variety string) (energyquerytype.EnergyQueryType, error)
- func (s *EnergyQueryTypeService) GetTableName() string
- type PropertyService
- func (s *PropertyService) Create(name string) (property.Property, error)
- func (s *PropertyService) Find(property property.Property) (property.Property, error)
- func (s *PropertyService) GetByID(id uint) (property.Property, error)
- func (s *PropertyService) GetByName(name string) (property.Property, error)
- type Source
- type UploadService
Constants ¶
const (
CloudFeedTypeDownloadInterval = time.Hour * 24
)
Variables ¶
var ( ErrTokenSigningMethodInvalid = errors.New("unexpected signing method") ErrTokenInvalid = errors.New("token is invalid") )
var ( ErrDuplicateCloudFeed = errors.New("duplicate cloud feed auth") NoLatestUploadTime = needforheat.Time{} )
var ( ErrDeviceDoesNotBelongToAccount = errors.New("device does not belong to this account") ErrDeviceTypeNameInvalid = errors.New("device type name invalid") )
var ( ErrEnergyQueryDoesNotBelongToAccount = errors.New("EnergyQuery does not belong to this account") ErrEnergyQueryTypeNameInvalid = errors.New("EnergyQuery type name invalid") )
var (
ErrAPIKeyTypeNameInvalid = errors.New("APIKey type name invalid")
)
var (
ErrEmptyUpload = errors.New("no measurements in upload")
)
var (
ErrHashDoesNotMatchEnergyQueryType = errors.New("hash does not match a energy query type")
)
var (
ErrHashDoesNotMatchType = errors.New("hash does not match a device type")
)
var (
ErrInvalidKeyAlgorithm = errors.New("invalid key algorithm")
)
Functions ¶
This section is empty.
Types ¶
type APIKeyService ¶
type APIKeyService struct {
// contains filtered or unexported fields
}
func NewAPIKeyService ¶
func NewAPIKeyService(repository apikey.APIKeyRepository) *APIKeyService
Create a new APIKeyService.
type AccountService ¶
type AccountService struct {
// contains filtered or unexported fields
}
func NewAccountService ¶
func NewAccountService( repository account.AccountRepository, authService *AuthorizationService, appService *AppService, campaignService *CampaignService, cloudFeedService *CloudFeedService, dataSourceTypeService *DataSourceTypeService, ) *AccountService
Create a new AccountService
func (*AccountService) Activate ¶
func (s *AccountService) Activate(id uint) (account.Account, error)
Activate an account.
func (*AccountService) GetByID ¶
func (s *AccountService) GetByID(id uint) (account.Account, error)
Get an account by ID.
func (*AccountService) GetCloudFeedAuthStatuses ¶
func (s *AccountService) GetCloudFeedAuthStatuses(id uint) ([]cloudfeedstatus.CloudFeedStatus, error)
Get cloud feed auth statuses.
type AdminService ¶
type AdminService struct {
// contains filtered or unexported fields
}
func NewAdminService ¶
func NewAdminService(repository admin.AdminRepository, authService *AuthorizationService) *AdminService
Create a new AdminService.
func (*AdminService) Reactivate ¶
type AppService ¶
type AppService struct {
// contains filtered or unexported fields
}
func NewAppService ¶
func NewAppService(repository app.AppRepository) *AppService
Create a new AppService.
type AuthorizationService ¶
type AuthorizationService struct {
// contains filtered or unexported fields
}
func NewAuthorizationService ¶
func NewAuthorizationService(key crypto.PrivateKey) (*AuthorizationService, error)
Create a new AuthorizationService.
func NewAuthorizationServiceFromFile ¶
func NewAuthorizationServiceFromFile(path string) (*AuthorizationService, error)
Create a new AuthorizationService with the key from a file.
func (*AuthorizationService) CreateToken ¶
func (s *AuthorizationService) CreateToken(kind authorization.AuthKind, id uint, expiry time.Time) (string, error)
func (*AuthorizationService) CreateTokenFromAuthorization ¶
func (s *AuthorizationService) CreateTokenFromAuthorization(auth authorization.Authorization, expiry time.Time) (string, error)
func (*AuthorizationService) ParseToken ¶
func (s *AuthorizationService) ParseToken(tokenString string) (authorization.AuthKind, uint, *authorization.Claims, error)
func (*AuthorizationService) ParseTokenToAuthorization ¶
func (s *AuthorizationService) ParseTokenToAuthorization(tokenString string) (*authorization.Authorization, error)
type CampaignService ¶
type CampaignService struct {
// contains filtered or unexported fields
}
func NewCampaignService ¶
func NewCampaignService( repository campaign.CampaignRepository, appService *AppService, dataSourceListService *DataSourceListService, ) *CampaignService
Create a new CampaignService.
func (*CampaignService) Create ¶
func (s *CampaignService) Create( name string, app app.App, infoURL string, startTime, endTime *needforheat.Time, dataSourceList datasourcelist.DataSourceList, ) (campaign.Campaign, error)
Create a new campaign.
type CloudFeedService ¶
type CloudFeedService struct {
// contains filtered or unexported fields
}
func NewCloudFeedService ¶
func NewCloudFeedService(cloudFeedRepo cloudfeed.CloudFeedRepository, cloudFeedTypeRepo cloudfeedtype.CloudFeedTypeRepository, uploadService *UploadService) *CloudFeedService
Create a new CloudFeedService.
func (*CloudFeedService) Create ¶
func (s *CloudFeedService) Create(ctx context.Context, accountID, cloudFeedTypeID uint, authGrantToken string) (cloudfeed.CloudFeed, error)
Create a new cloudFeed. This function exchanges the AuthGrantToken (Code) for a access and refresh token.
func (*CloudFeedService) Download ¶
func (s *CloudFeedService) Download(ctx context.Context, cfa cloudfeed.CloudFeed, startPeriod needforheat.Time, endPeriod needforheat.Time) error
Download data from a cloud feed using the cloud feed auth and store it in the database. startPeriod and endPeriod are the time periods for which data should be downloaded.
func (*CloudFeedService) DownloadInBackground ¶
func (s *CloudFeedService) DownloadInBackground(ctx context.Context, downloadStartTime time.Time)
Run this function in a goroutine to periodically download data from the cloud feed. downloadStartTime is the time at which the data should be downloaded and repeated each day.
func (*CloudFeedService) RefreshTokens ¶
func (s *CloudFeedService) RefreshTokens(ctx context.Context, accountID uint, cloudFeedTypeID uint) (cloudfeed.CloudFeed, error)
Refresh the tokens for the CloudFeed corresponding to accountID and cloudFeedTypeID.
func (*CloudFeedService) RefreshTokensInBackground ¶
func (s *CloudFeedService) RefreshTokensInBackground(ctx context.Context, preRenewalDuration time.Duration)
Run this function in a goroutine to keep tokens refreshed before they expire. The preRenewalDuration sets the time we need to refresh the tokens in advance of theri expiry.
type CloudFeedTypeService ¶
type CloudFeedTypeService struct {
// contains filtered or unexported fields
}
func NewCloudFeedTypeService ¶
func NewCloudFeedTypeService(repository cloudfeedtype.CloudFeedTypeRepository) *CloudFeedTypeService
Create a new CloudFeedTypeService.
func (*CloudFeedTypeService) Create ¶
func (s *CloudFeedTypeService) Create(name string, authorizationURL string, tokenURL string, clientID string, clientSecret string, scope string, redirectURL string) (cloudfeedtype.CloudFeedType, error)
func (*CloudFeedTypeService) Find ¶
func (s *CloudFeedTypeService) Find(cloudFeed cloudfeedtype.CloudFeedType) (cloudfeedtype.CloudFeedType, error)
func (*CloudFeedTypeService) GetByID ¶
func (s *CloudFeedTypeService) GetByID(id uint) (cloudfeedtype.CloudFeedType, error)
func (*CloudFeedTypeService) GetByIDForDataSourceType ¶
func (s *CloudFeedTypeService) GetByIDForDataSourceType(id uint) (interface{}, error)
func (*CloudFeedTypeService) GetTableName ¶
func (s *CloudFeedTypeService) GetTableName() string
type DataSourceListService ¶
type DataSourceListService struct {
// contains filtered or unexported fields
}
func NewDataSourceListService ¶
func NewDataSourceListService(repository datasourcelist.DataSourceListRepository, shoppingListItemService *DataSourceTypeService) *DataSourceListService
Create a new DataSourceListService.
func (*DataSourceListService) Create ¶
func (s *DataSourceListService) Create(name string, items []datasourcetype.DataSourceType) (datasourcelist.DataSourceList, error)
func (*DataSourceListService) Delete ¶
func (s *DataSourceListService) Delete(shoppingList datasourcelist.DataSourceList) error
func (*DataSourceListService) Find ¶
func (s *DataSourceListService) Find(shoppingList datasourcelist.DataSourceList) (datasourcelist.DataSourceList, error)
func (*DataSourceListService) GetAll ¶
func (s *DataSourceListService) GetAll() ([]datasourcelist.DataSourceList, error)
type DataSourceTypeService ¶
type DataSourceTypeService struct {
// contains filtered or unexported fields
}
func NewDataSourceTypeService ¶
func NewDataSourceTypeService( repository datasourcetype.DataSourceTypeRepository, deviceTypeService *DeviceTypeService, cloudFeedTypeService *CloudFeedTypeService, energyQueryTypeService *EnergyQueryTypeService, ) *DataSourceTypeService
Create a new DataSourceTypeService.
func (*DataSourceTypeService) Create ¶
func (s *DataSourceTypeService) Create( typeInstanceID uint, category datasourcetype.Category, precedes []datasourcetype.DataSourceType, installationManualUrl string, faqURL string, infoUrl string, uploadSchedule string, measurementSchedule string, notificationThreshold string, ) (datasourcetype.DataSourceType, error)
func (*DataSourceTypeService) Delete ¶
func (s *DataSourceTypeService) Delete(dataSourceType datasourcetype.DataSourceType) error
func (*DataSourceTypeService) Find ¶
func (s *DataSourceTypeService) Find(dataSourceType datasourcetype.DataSourceType) (datasourcetype.DataSourceType, error)
func (*DataSourceTypeService) GetAll ¶
func (s *DataSourceTypeService) GetAll() ([]datasourcetype.DataSourceType, error)
func (*DataSourceTypeService) GetSourceByIDAndTable ¶
func (s *DataSourceTypeService) GetSourceByIDAndTable(sourceID uint, table string) (interface{}, Source, error)
type DeviceService ¶
type DeviceService struct {
// contains filtered or unexported fields
}
func NewDeviceService ¶
func NewDeviceService(repository device.DeviceRepository, authService *AuthorizationService, deviceTypeService *DeviceTypeService, AccountService *AccountService, uploadService *UploadService) *DeviceService
Create a new DeviceService.
func (*DeviceService) Activate ¶
func (s *DeviceService) Activate(name, activationSecret string) (device.Device, error)
func (*DeviceService) GetAccountByDeviceID ¶
func (s *DeviceService) GetAccountByDeviceID(id uint) (uint, error)
func (*DeviceService) GetAllByAccount ¶
func (s *DeviceService) GetAllByAccount(accountId uint) ([]device.Device, error)
func (*DeviceService) GetByName ¶
func (s *DeviceService) GetByName(name string) (device.Device, error)
func (*DeviceService) GetMeasurementsByDeviceID ¶
func (s *DeviceService) GetMeasurementsByDeviceID(id uint, filters map[string]string) ([]measurement.Measurement, error)
func (*DeviceService) GetPropertiesByDeviceID ¶
func (s *DeviceService) GetPropertiesByDeviceID(id uint) ([]property.Property, error)
type DeviceTypeService ¶
type DeviceTypeService struct {
// contains filtered or unexported fields
}
func NewDeviceTypeService ¶
func NewDeviceTypeService(repository devicetype.DeviceTypeRepository, propertyService *PropertyService) *DeviceTypeService
Create a new DeviceTypeService.
func (*DeviceTypeService) Create ¶
func (s *DeviceTypeService) Create(name string) (devicetype.DeviceType, error)
func (*DeviceTypeService) Find ¶
func (s *DeviceTypeService) Find(deviceType devicetype.DeviceType) (devicetype.DeviceType, error)
func (*DeviceTypeService) GetByHash ¶
func (s *DeviceTypeService) GetByHash(deviceTypeHash string) (devicetype.DeviceType, error)
func (*DeviceTypeService) GetByID ¶
func (s *DeviceTypeService) GetByID(id uint) (devicetype.DeviceType, error)
func (*DeviceTypeService) GetByIDForDataSourceType ¶
func (s *DeviceTypeService) GetByIDForDataSourceType(id uint) (interface{}, error)
func (*DeviceTypeService) GetByName ¶
func (s *DeviceTypeService) GetByName(name string) (devicetype.DeviceType, error)
func (*DeviceTypeService) GetTableName ¶
func (s *DeviceTypeService) GetTableName() string
type EnergyQueryService ¶
type EnergyQueryService struct {
// contains filtered or unexported fields
}
func NewEnergyQueryService ¶
func NewEnergyQueryService(repository energyquery.EnergyQueryRepository, authService *AuthorizationService, energyQueryTypeService *EnergyQueryTypeService, AccountService *AccountService, uploadService *UploadService) *EnergyQueryService
Create a new EnergyQueryService.
func (*EnergyQueryService) Create ¶
func (s *EnergyQueryService) Create(queryType energyquerytype.EnergyQueryType, accountID uint, uploads []upload.Upload) (energyquery.EnergyQuery, error)
func (*EnergyQueryService) GetAccountByEnergyQueryID ¶
func (s *EnergyQueryService) GetAccountByEnergyQueryID(id uint) (uint, error)
func (*EnergyQueryService) GetAllByAccount ¶
func (s *EnergyQueryService) GetAllByAccount(accountId uint) ([]energyquery.EnergyQuery, error)
func (*EnergyQueryService) GetByID ¶
func (s *EnergyQueryService) GetByID(id uint) (energyquery.EnergyQuery, error)
func (*EnergyQueryService) GetByTypeAndAccount ¶
func (s *EnergyQueryService) GetByTypeAndAccount(queryType energyquerytype.EnergyQueryType, accountID uint) (energyquery.EnergyQuery, error)
func (*EnergyQueryService) GetMeasurementsByEnergyQueryID ¶
func (s *EnergyQueryService) GetMeasurementsByEnergyQueryID(id uint, filters map[string]string) ([]measurement.Measurement, error)
func (*EnergyQueryService) GetPropertiesByEnergyQueryID ¶
func (s *EnergyQueryService) GetPropertiesByEnergyQueryID(id uint) ([]property.Property, error)
type EnergyQueryTypeService ¶
type EnergyQueryTypeService struct {
// contains filtered or unexported fields
}
func NewEnergyQueryTypeService ¶
func NewEnergyQueryTypeService(repository energyquerytype.EnergyQueryTypeRepository, propertyService *PropertyService) *EnergyQueryTypeService
Create a new EnergyQueryTypeService.
func (*EnergyQueryTypeService) Create ¶
func (s *EnergyQueryTypeService) Create(variety string, formula string) (energyquerytype.EnergyQueryType, error)
func (*EnergyQueryTypeService) Find ¶
func (s *EnergyQueryTypeService) Find(energyQueryType energyquerytype.EnergyQueryType) (energyquerytype.EnergyQueryType, error)
func (*EnergyQueryTypeService) GetByHash ¶
func (s *EnergyQueryTypeService) GetByHash(energyQueryTypeHash string) (energyquerytype.EnergyQueryType, error)
func (*EnergyQueryTypeService) GetByID ¶
func (s *EnergyQueryTypeService) GetByID(id uint) (energyquerytype.EnergyQueryType, error)
func (*EnergyQueryTypeService) GetByIDForDataSourceType ¶
func (s *EnergyQueryTypeService) GetByIDForDataSourceType(id uint) (interface{}, error)
func (*EnergyQueryTypeService) GetByVariety ¶
func (s *EnergyQueryTypeService) GetByVariety(variety string) (energyquerytype.EnergyQueryType, error)
func (*EnergyQueryTypeService) GetTableName ¶
func (s *EnergyQueryTypeService) GetTableName() string
type PropertyService ¶
type PropertyService struct {
// contains filtered or unexported fields
}
func NewPropertyService ¶
func NewPropertyService(repository property.PropertyRepository) *PropertyService
Create a new PropertyService.
func (*PropertyService) Create ¶
func (s *PropertyService) Create(name string) (property.Property, error)
type Source ¶
type Source interface { GetByIDForDataSourceType(id uint) (interface{}, error) GetTableName() string }
Used so we do not have to hardcode the check as much
type UploadService ¶
type UploadService struct {
// contains filtered or unexported fields
}
func NewUploadService ¶
func NewUploadService( repository upload.UploadRepository, deviceRepo device.DeviceRepository, propertyService *PropertyService, ) *UploadService
Create a new UploadService.
func (*UploadService) Create ¶
func (s *UploadService) Create(instanceID uint, instanceType upload.InstanceType, deviceTime needforheat.Time, measurements []measurement.Measurement) (upload.Upload, error)
func (*UploadService) GetLatestUploadTimeForDeviceWithID ¶
func (s *UploadService) GetLatestUploadTimeForDeviceWithID(id uint) (*needforheat.Time, bool, error)