services

package
v0.0.0-...-a754e5c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package services exposes a services as entrypoints for business logic.

Index

Constants

View Source
const (
	CloudFeedTypeDownloadInterval = time.Hour * 24
)

Variables

View Source
var (
	ErrTokenSigningMethodInvalid = errors.New("unexpected signing method")
	ErrTokenInvalid              = errors.New("token is invalid")
)
View Source
var (
	ErrDuplicateCloudFeed = errors.New("duplicate cloud feed auth")

	NoLatestUploadTime = needforheat.Time{}
)
View Source
var (
	ErrDeviceDoesNotBelongToAccount = errors.New("device does not belong to this account")
	ErrDeviceTypeNameInvalid        = errors.New("device type name invalid")
)
View Source
var (
	ErrEnergyQueryDoesNotBelongToAccount = errors.New("EnergyQuery does not belong to this account")
	ErrEnergyQueryTypeNameInvalid        = errors.New("EnergyQuery type name invalid")
)
View Source
var (
	ErrAPIKeyTypeNameInvalid = errors.New("APIKey type name invalid")
)
View Source
var (
	ErrEmptyUpload = errors.New("no measurements in upload")
)
View Source
var (
	ErrHashDoesNotMatchEnergyQueryType = errors.New("hash does not match a energy query type")
)
View Source
var (
	ErrHashDoesNotMatchType = errors.New("hash does not match a device type")
)
View Source
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.

func (*APIKeyService) Create

func (s *APIKeyService) Create(apiKey apikey.APIKey) (apikey.APIKey, error)

func (*APIKeyService) Delete

func (s *APIKeyService) Delete(apiKey apikey.APIKey) error

func (*APIKeyService) Find

func (s *APIKeyService) Find(apiKey apikey.APIKey) (apikey.APIKey, error)

func (*APIKeyService) GetByID

func (s *APIKeyService) GetByID(id uint) (apikey.APIKey, error)

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) Create

func (s *AccountService) Create(campaign campaign.Campaign) (account.Account, error)

Create a new 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) Create

func (s *AdminService) Create(name string, expiry time.Time) (admin.Admin, error)

func (*AdminService) Delete

func (s *AdminService) Delete(admin admin.Admin) error

func (*AdminService) Find

func (s *AdminService) Find(admin admin.Admin) (admin.Admin, error)

func (*AdminService) GetAll

func (s *AdminService) GetAll() ([]admin.Admin, error)

func (*AdminService) Reactivate

func (s *AdminService) Reactivate(a admin.Admin) (admin.Admin, error)

func (*AdminService) SetExpiry

func (s *AdminService) SetExpiry(a admin.Admin, expiry time.Time) (admin.Admin, error)

type AppService

type AppService struct {
	// contains filtered or unexported fields
}

func NewAppService

func NewAppService(repository app.AppRepository) *AppService

Create a new AppService.

func (*AppService) Create

func (s *AppService) Create(name, provisioningURLTemplate, oauthRedirectURL string) (app.App, error)

Create a new app.

func (*AppService) Find

func (s *AppService) Find(app app.App) (app.App, error)

func (*AppService) GetAll

func (s *AppService) GetAll() ([]app.App, error)

func (*AppService) GetByID

func (s *AppService) GetByID(id uint) (app.App, error)

Get an app by its ID.

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 (*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.

func (*CampaignService) Find

func (s *CampaignService) Find(campaign campaign.Campaign) (campaign.Campaign, error)

Find a campaign using any field set in the campaign struct.

func (*CampaignService) GetByID

func (s *CampaignService) GetByID(id uint) (campaign.Campaign, error)

Get a campaign by its ID.

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) Find

Find a cloudFeed using any field set in the cloudFeed struct.

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 (*CloudFeedTypeService) GetByID

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 (*DataSourceListService) Delete

func (s *DataSourceListService) Delete(shoppingList datasourcelist.DataSourceList) error

func (*DataSourceListService) Find

func (*DataSourceListService) GetAll

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 (*DataSourceTypeService) GetAll

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) AddUpload

func (s *DeviceService) AddUpload(id uint, upload upload.Upload) (device.Device, error)

func (*DeviceService) Create

func (s *DeviceService) Create(name string, accountID uint, 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) GetByID

func (s *DeviceService) GetByID(id 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 (*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 (*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 (*EnergyQueryTypeService) Find

func (*EnergyQueryTypeService) GetByHash

func (s *EnergyQueryTypeService) GetByHash(energyQueryTypeHash string) (energyquerytype.EnergyQueryType, error)

func (*EnergyQueryTypeService) GetByID

func (*EnergyQueryTypeService) GetByIDForDataSourceType

func (s *EnergyQueryTypeService) GetByIDForDataSourceType(id uint) (interface{}, error)

func (*EnergyQueryTypeService) GetByVariety

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)

func (*PropertyService) Find

func (s *PropertyService) Find(property property.Property) (property.Property, error)

func (*PropertyService) GetByID

func (s *PropertyService) GetByID(id uint) (property.Property, error)

func (*PropertyService) GetByName

func (s *PropertyService) GetByName(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)

Directories

Path Synopsis
cloudfeeds

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL