services

package
v0.0.0-...-ebd6d4f Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Package services exposes a services as entrypoints for business logic.

Index

Constants

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

Variables

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

	NoLatestUploadTime = time.Time{}
)
View Source
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")
)
View Source
var (
	ErrEmptyUpload = errors.New("no measurements in upload")
)
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 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) 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) ([]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) 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 BuildingService

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

func NewBuildingService

func NewBuildingService(repository building.BuildingRepository, uploadService *UploadService) *BuildingService

Create a new BuildingService.

func (*BuildingService) Create

func (s *BuildingService) Create(accountID uint, long float32, lat float32, tzName string) (building.Building, error)

func (*BuildingService) GetByID

func (s *BuildingService) GetByID(id uint) (building.Building, error)

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.

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

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.

func (*CloudFeedService) Create

func (s *CloudFeedService) Create(name string, authorizationURL string, tokenURL string, clientID string, clientSecret string, scope string, redirectURL string) (cloudfeed.CloudFeed, error)

func (*CloudFeedService) Find

func (*CloudFeedService) GetByID

func (s *CloudFeedService) GetByID(id uint) (cloudfeed.CloudFeed, error)

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

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

func (*DeviceService) Create

func (s *DeviceService) Create(name string, buildingID, accountID uint, activationSecret string) (device.Device, error)

func (*DeviceService) GetAccountByDeviceID

func (s *DeviceService) GetAccountByDeviceID(id uint) (uint, 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, installationManualURL, infoURL 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) 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)

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

func (*UploadService) GetLatestUploadTimeForDeviceWithID

func (s *UploadService) GetLatestUploadTimeForDeviceWithID(id uint) (*time.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