Documentation ¶
Overview ¶
Package services exposes a services as entrypoints for business logic.
Index ¶
- Constants
- Variables
- type AccountService
- func (s *AccountService) Activate(id uint, longtitude, latitude float32, tzName string) (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) ([]cloudfeedauthstatus.CloudFeedAuthStatus, 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 BuildingService
- type CampaignService
- type CloudFeedAuthService
- func (s *CloudFeedAuthService) Create(ctx context.Context, accountID, cloudFeedID uint, authGrantToken string) (cloudfeedauth.CloudFeedAuth, error)
- func (s *CloudFeedAuthService) Download(ctx context.Context, cfa cloudfeedauth.CloudFeedAuth, startPeriod time.Time, ...) error
- func (s *CloudFeedAuthService) DownloadInBackground(ctx context.Context, downloadStartTime time.Time)
- func (s *CloudFeedAuthService) Find(cloudFeedAuth cloudfeedauth.CloudFeedAuth) (cloudfeedauth.CloudFeedAuth, error)
- func (s *CloudFeedAuthService) RefreshTokens(ctx context.Context, accountID uint, cloudFeedID uint) (cloudfeedauth.CloudFeedAuth, error)
- func (s *CloudFeedAuthService) RefreshTokensInBackground(ctx context.Context, preRenewalDuration time.Duration)
- type CloudFeedService
- func (s *CloudFeedService) Create(name string, authorizationURL string, tokenURL string, clientID string, ...) (cloudfeed.CloudFeed, error)
- func (s *CloudFeedService) Find(cloudFeed cloudfeed.CloudFeed) (cloudfeed.CloudFeed, error)
- func (s *CloudFeedService) GetByID(id uint) (cloudfeed.CloudFeed, 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, buildingID, accountID uint, activationSecret string) (device.Device, error)
- func (s *DeviceService) GetAccountByDeviceID(id uint) (uint, 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, installationManualURL, infoURL 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) GetByName(name string) (devicetype.DeviceType, error)
- 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 UploadService
Constants ¶
const (
CloudFeedDownloadInterval = time.Hour * 24
)
Variables ¶
var ( ErrTokenSigningMethodInvalid = errors.New("unexpected signing method") ErrTokenInvalid = errors.New("token is invalid") )
var ( ErrDuplicateCloudFeedAuth = errors.New("duplicate cloud feed auth") NoLatestUploadTime = time.Time{} )
var ( ErrDeviceDoesNotBelongToAccount = errors.New("device does not belong to this account") ErrBuildingDoesNotBelongToAccount = errors.New("building does not belong to this account") ErrDeviceTypeNameInvalid = errors.New("device type name invalid") )
var (
ErrEmptyUpload = errors.New("no measurements in upload")
)
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 AccountService ¶
type AccountService struct {
// contains filtered or unexported fields
}
func NewAccountService ¶
func NewAccountService(repository account.AccountRepository, authService *AuthorizationService, appService *AppService, campaignService *CampaignService, buildingService *BuildingService, cloudFeedAuthService *CloudFeedAuthService) *AccountService
Create a new AccountService
func (*AccountService) Activate ¶
func (s *AccountService) Activate(id uint, longtitude, latitude float32, tzName string) (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) ([]cloudfeedauthstatus.CloudFeedAuthStatus, 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 BuildingService ¶
type BuildingService struct {
// contains filtered or unexported fields
}
func NewBuildingService ¶
func NewBuildingService(repository building.BuildingRepository, uploadService *UploadService) *BuildingService
Create a new BuildingService.
type CampaignService ¶
type CampaignService struct {
// contains filtered or unexported fields
}
func NewCampaignService ¶
func NewCampaignService(repository campaign.CampaignRepository, appService *AppService, cloudFeedService *CloudFeedService) *CampaignService
Create a new CampaignService.
func (*CampaignService) Create ¶
func (s *CampaignService) Create(name string, app app.App, infoURL string, cloudFeeds []cloudfeed.CloudFeed, startTime, endTime *time.Time) (campaign.Campaign, error)
Create a new campaign.
type CloudFeedAuthService ¶
type CloudFeedAuthService struct {
// contains filtered or unexported fields
}
func NewCloudFeedAuthService ¶
func NewCloudFeedAuthService(cloudFeedAuthRepo cloudfeedauth.CloudFeedAuthRepository, cloudFeedRepo cloudfeed.CloudFeedRepository, uploadService *UploadService) *CloudFeedAuthService
Create a new CloudFeedAuthService.
func (*CloudFeedAuthService) Create ¶
func (s *CloudFeedAuthService) Create(ctx context.Context, accountID, cloudFeedID uint, authGrantToken string) (cloudfeedauth.CloudFeedAuth, error)
Create a new cloudFeedAuth. This function exchanges the AuthGrantToken (Code) for a access and refresh token.
func (*CloudFeedAuthService) Download ¶
func (s *CloudFeedAuthService) Download(ctx context.Context, cfa cloudfeedauth.CloudFeedAuth, startPeriod time.Time, endPeriod time.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 (*CloudFeedAuthService) DownloadInBackground ¶
func (s *CloudFeedAuthService) 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 (*CloudFeedAuthService) Find ¶
func (s *CloudFeedAuthService) Find(cloudFeedAuth cloudfeedauth.CloudFeedAuth) (cloudfeedauth.CloudFeedAuth, error)
Find a cloudFeedAuth using any field set in the cloudFeedAuth struct.
func (*CloudFeedAuthService) RefreshTokens ¶
func (s *CloudFeedAuthService) RefreshTokens(ctx context.Context, accountID uint, cloudFeedID uint) (cloudfeedauth.CloudFeedAuth, error)
Refresh the tokens for the CloudFeedAuth corresponding to accountID and cloudFeedID.
func (*CloudFeedAuthService) RefreshTokensInBackground ¶
func (s *CloudFeedAuthService) 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 CloudFeedService ¶
type CloudFeedService struct {
// contains filtered or unexported fields
}
func NewCloudFeedService ¶
func NewCloudFeedService(repository cloudfeed.CloudFeedRepository) *CloudFeedService
Create a new CloudFeedService.
type DeviceService ¶
type DeviceService struct {
// contains filtered or unexported fields
}
func NewDeviceService ¶
func NewDeviceService(repository device.DeviceRepository, authService *AuthorizationService, deviceTypeService *DeviceTypeService, BuildingService *BuildingService, 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) 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, installationManualURL, infoURL 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) GetByName ¶
func (s *DeviceTypeService) GetByName(name string) (devicetype.DeviceType, error)
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 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(deviceID uint, deviceTime twomes.Time, measurements []measurement.Measurement) (upload.Upload, error)