repositories

package
v0.0.0-...-d1dae27 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package repositories implements repositories for use in services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDatabaseConnection

func NewDatabaseConnection(dsn string) (*gorm.DB, error)

Create a new database connection that can be used by repositories.

func NewDatabaseConnectionAndMigrate

func NewDatabaseConnectionAndMigrate(ctx context.Context, dsn string) (db *gorm.DB, err error)

Create a new database connection and perform a migration. Try until connection succeeds or context is done.

func StringToCategory

func StringToCategory(category string) datasourcetype.Category

func StringToType

func StringToType(category string) upload.InstanceType

Types

type APIKeyModel

type APIKeyModel struct {
	gorm.Model
	APIName string
	APIKey  string
}

Database representation of a apikey.APIKey

func MakeAPIKeyModel

func MakeAPIKeyModel(apiKey apikey.APIKey) APIKeyModel

Create a APIKeyModel from a apikey.APIKey.

func (APIKeyModel) TableName

func (APIKeyModel) TableName() string

Set the name of the table in the database.

type APIKeyRepository

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

func NewAPIKeyRepository

func NewAPIKeyRepository(db *gorm.DB) *APIKeyRepository

Create a new APIKeyRepository.

func (*APIKeyRepository) Create

func (r *APIKeyRepository) Create(apiKey apikey.APIKey) (apikey.APIKey, error)

func (*APIKeyRepository) Delete

func (r *APIKeyRepository) Delete(apiKey apikey.APIKey) error

func (*APIKeyRepository) Find

func (r *APIKeyRepository) Find(apiKey apikey.APIKey) (apikey.APIKey, error)

func (*APIKeyRepository) GetAll

func (r *APIKeyRepository) GetAll() ([]apikey.APIKey, error)

type AccountModel

type AccountModel struct {
	gorm.Model
	CampaignModelID uint `gorm:"column:campaign_id"`
	Campaign        CampaignModel
	ActivatedAt     *needforheat.Time
	CloudFeeds      []CloudFeedModel `gorm:"foreignKey:AccountID"`
	Devices         []DeviceModel
}

Database representation of a account.Account.

func MakeAccountModel

func MakeAccountModel(account account.Account) AccountModel

Create a new AccountModel from a account.Account.

func (AccountModel) TableName

func (AccountModel) TableName() string

Set the name of the table in the database.

type AccountRepository

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

func NewAccountRepository

func NewAccountRepository(db *gorm.DB) *AccountRepository

func (*AccountRepository) Create

func (r *AccountRepository) Create(account account.Account) (account.Account, error)

func (*AccountRepository) Delete

func (r *AccountRepository) Delete(account account.Account) error

func (*AccountRepository) Find

func (r *AccountRepository) Find(accountToFind account.Account) (account.Account, error)

func (*AccountRepository) GetAll

func (r *AccountRepository) GetAll() ([]account.Account, error)

func (*AccountRepository) Update

func (r *AccountRepository) Update(account account.Account) (account.Account, error)

type AdminModel

type AdminModel struct {
	gorm.Model
	Name        string `gorm:"unique;not null"`
	ActivatedAt time.Time
	Expiry      time.Time
}

Database representation of a admin.Admin.

func MakeAdminModel

func MakeAdminModel(admin admin.Admin) AdminModel

Create a new AdminModel from a admin.Admin.

func (AdminModel) TableName

func (AdminModel) TableName() string

Set the name of the table in the database.

type AdminRepository

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

func NewAdminRepository

func NewAdminRepository(fileName string) (*AdminRepository, error)

Create a new AdminRepository from a badger DB at fileName.

func (*AdminRepository) Create

func (r *AdminRepository) Create(admin admin.Admin) (admin.Admin, error)

func (*AdminRepository) Delete

func (r *AdminRepository) Delete(admin admin.Admin) error

func (*AdminRepository) Find

func (r *AdminRepository) Find(admin admin.Admin) (admin.Admin, error)

func (*AdminRepository) GetAll

func (r *AdminRepository) GetAll() ([]admin.Admin, error)

func (*AdminRepository) Update

func (r *AdminRepository) Update(admin admin.Admin) (admin.Admin, error)

type AppModel

type AppModel struct {
	gorm.Model
	Name                    string `gorm:"unique;not null"`
	ProvisioningURLTemplate string
	OauthRedirectURL        string
}

Database representation of a app.App.

func MakeAppModel

func MakeAppModel(app app.App) AppModel

Create a new AppModel from a app.App

func (AppModel) TableName

func (AppModel) TableName() string

Set the name of the table in the database.

type AppRepository

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

func NewAppRepository

func NewAppRepository(db *gorm.DB) *AppRepository

func (*AppRepository) Create

func (r *AppRepository) Create(app app.App) (app.App, error)

func (*AppRepository) Delete

func (r *AppRepository) Delete(app app.App) error

func (*AppRepository) Find

func (r *AppRepository) Find(app app.App) (app.App, error)

func (*AppRepository) GetAll

func (r *AppRepository) GetAll() ([]app.App, error)

type CampaignModel

type CampaignModel struct {
	gorm.Model
	Name             string `gorm:"unique;not null"`
	AppModelID       uint   `gorm:"column:app_id"`
	App              AppModel
	InfoURL          string `gorm:"unique;not null"`
	StartTime        *needforheat.Time
	EndTime          *needforheat.Time
	DataSourceListID uint
}

Database representation of campaign.Campaign.

func MakeCampaignModel

func MakeCampaignModel(campaign campaign.Campaign) CampaignModel

Create a new CampaignModel from a [needforheat.campaign].

func (CampaignModel) TableName

func (CampaignModel) TableName() string

Set the name of the table in the database.

type CampaignRepository

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

func NewCampaignRepository

func NewCampaignRepository(db *gorm.DB) *CampaignRepository

func (*CampaignRepository) Create

func (r *CampaignRepository) Create(campaign campaign.Campaign) (campaign.Campaign, error)

func (*CampaignRepository) Delete

func (r *CampaignRepository) Delete(campaign campaign.Campaign) error

func (*CampaignRepository) Find

func (r *CampaignRepository) Find(campaignToFind campaign.Campaign) (campaign.Campaign, error)

func (*CampaignRepository) GetAll

func (r *CampaignRepository) GetAll() ([]campaign.Campaign, error)

type CloudFeedModel

type CloudFeedModel struct {
	AccountID       uint `gorm:"primaryKey;autoIncrement:false"`
	CloudFeedTypeID uint `gorm:"primaryKey;autoIncrement:false"`
	CreatedAt       needforheat.Time
	UpdatedAt       needforheat.Time
	DeletedAt       gorm.DeletedAt `gorm:"index"`
	// TODO: WARNING encrypted string encryption not yet implemented.
	AccessToken    encryption.EncryptedString
	RefreshToken   encryption.EncryptedString
	Expiry         needforheat.Time
	AuthGrantToken encryption.EncryptedString
	ActivatedAt    *needforheat.Time
}

Database representation of cloudfeed.CloudFeed.

func MakeCloudFeedModel

func MakeCloudFeedModel(cloudFeed cloudfeed.CloudFeed) CloudFeedModel

Create a new CloudFeedModel from a [needforheat.cloudFeed].

func (CloudFeedModel) TableName

func (CloudFeedModel) TableName() string

Set the name of the table in the database.

type CloudFeedRepository

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

func NewCloudFeedRepository

func NewCloudFeedRepository(db *gorm.DB) *CloudFeedRepository

func (*CloudFeedRepository) Create

func (*CloudFeedRepository) Delete

func (r *CloudFeedRepository) Delete(cloudFeed cloudfeed.CloudFeed) error

func (*CloudFeedRepository) Find

func (*CloudFeedRepository) FindDevice

func (r *CloudFeedRepository) FindDevice(cloudFeed cloudfeed.CloudFeed) (*device.Device, error)

func (*CloudFeedRepository) FindFirstTokenToExpire

func (r *CloudFeedRepository) FindFirstTokenToExpire() (uint, uint, needforheat.Time, error)

func (*CloudFeedRepository) FindOAuthInfo

func (r *CloudFeedRepository) FindOAuthInfo(accountID uint, cloudFeedID uint) (string, string, string, string, error)

func (*CloudFeedRepository) GetAll

func (r *CloudFeedRepository) GetAll() ([]cloudfeed.CloudFeed, error)

func (*CloudFeedRepository) Update

type CloudFeedTypeModel

type CloudFeedTypeModel struct {
	gorm.Model
	Name             string `gorm:"unique;not null"`
	AuthorizationURL string
	TokenURL         string
	ClientID         string
	// TODO: WARNING EncryptedString still has to implement the encryption.
	ClientSecret    encryption.EncryptedString
	Scope           string
	RedirectURL     string
	CloudFeeds      []CloudFeedModel      `gorm:"foreignKey:CloudFeedTypeID"`
	DataSourceTypes []DataSourceTypeModel `gorm:"polymorphic:TypeInstance;"`
}

Database representation of a cloudfeed.CloudFeed

func MakeCloudFeedTypeModel

func MakeCloudFeedTypeModel(cloudFeedType cloudfeedtype.CloudFeedType) CloudFeedTypeModel

Create a CloudFeedTypeModel from a cloudfeedtype.CloudFeedtype.

func (CloudFeedTypeModel) TableName

func (CloudFeedTypeModel) TableName() string

Set the name of the table in the database.

type CloudFeedTypeRepository

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

func NewCloudFeedTypeRepository

func NewCloudFeedTypeRepository(db *gorm.DB) *CloudFeedTypeRepository

Create a new CloudFeedTypeRepository.

func (*CloudFeedTypeRepository) Create

func (*CloudFeedTypeRepository) Delete

func (r *CloudFeedTypeRepository) Delete(cloudFeedType cloudfeedtype.CloudFeedType) error

func (*CloudFeedTypeRepository) Find

func (*CloudFeedTypeRepository) GetAll

func (*CloudFeedTypeRepository) Update

type DataSourceListItems

type DataSourceListItems struct {
	ID                    uint
	DataSourceListModelID uint
	DataSourceTypeModelID uint
	Order                 uint
}

Custom Many2Many table to support duplicates and list order

func (DataSourceListItems) TableName

func (DataSourceListItems) TableName() string

type DataSourceListModel

type DataSourceListModel struct {
	gorm.Model
	Items    []DataSourceListItems
	Campaign []CampaignModel `gorm:"foreignKey:DataSourceListID"`
	Name     string
}

Database representation of a datasourcelist.DataSourceList.

func MakeDataSourceListModel

func MakeDataSourceListModel(dataSourceList datasourcelist.DataSourceList) DataSourceListModel

Create a new DataSourceListModel from a datasourcelist.DataSourceList

func (DataSourceListModel) TableName

func (DataSourceListModel) TableName() string

Set the name of the table in the database.

type DataSourceListRepository

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

func NewDataSourceListRepository

func NewDataSourceListRepository(db *gorm.DB) *DataSourceListRepository

func (*DataSourceListRepository) Create

func (*DataSourceListRepository) Delete

func (r *DataSourceListRepository) Delete(datasourcelist datasourcelist.DataSourceList) error

func (*DataSourceListRepository) Find

func (*DataSourceListRepository) GetAll

type DataSourceTypeModel

type DataSourceTypeModel struct {
	gorm.Model
	TypeInstanceID        uint
	TypeInstanceType      string //Category in API
	Order                 uint   `gorm:"-"` //Used for returning the Order with DataSourceList
	InstallationManualURL string
	FAQURL                string
	InfoURL               string
	Precedes              []DataSourceTypeModel `gorm:"many2many:data_source_precedence;"`
	UploadSchedule        string                `gorm:"type:text"`
	MeasurementSchedule   string                `gorm:"type:text"`
	NotificationThreshold string
}

Database representation of a datasourcetype.DataSourceType.

func MakeDataSourceTypeModel

func MakeDataSourceTypeModel(datasourcetype datasourcetype.DataSourceType) DataSourceTypeModel

Create a new DataSourceTypeModel from a datasourcetype.ShoppinglistItem

func (*DataSourceTypeModel) AfterSave

func (s *DataSourceTypeModel) AfterSave(tx *gorm.DB) (err error)

Check if we did not make a loop that can softlock the app

func (*DataSourceTypeModel) CheckforCircular

func (s *DataSourceTypeModel) CheckforCircular(item *DataSourceTypeModel, previousIDs []uint) bool

func (DataSourceTypeModel) TableName

func (DataSourceTypeModel) TableName() string

Set the name of the table in the database.

type DataSourceTypeRepository

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

func NewDataSourceTypeRepository

func NewDataSourceTypeRepository(db *gorm.DB) *DataSourceTypeRepository

func (*DataSourceTypeRepository) Create

func (*DataSourceTypeRepository) Delete

func (r *DataSourceTypeRepository) Delete(datasourcetype datasourcetype.DataSourceType) error

func (*DataSourceTypeRepository) Find

func (*DataSourceTypeRepository) GetAll

type DeviceModel

type DeviceModel struct {
	gorm.Model
	Name                 string `gorm:"unique;not null"`
	DeviceTypeModelID    uint   `gorm:"column:device_type_id"`
	DeviceType           DeviceTypeModel
	AccountModelID       uint `gorm:"column:account_id"`
	ActivationSecretHash string
	ActivatedAt          *needforheat.Time
	Uploads              []UploadModel `gorm:"polymorphic:Instance;"`
}

Database representation of a device.Device

func MakeDeviceModel

func MakeDeviceModel(device device.Device) DeviceModel

Create a DeviceModel from a device.Device.

func (DeviceModel) TableName

func (DeviceModel) TableName() string

Set the name of the table in the database.

type DeviceRepository

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

func NewDeviceRepository

func NewDeviceRepository(db *gorm.DB) *DeviceRepository

Create a new DeviceRepository.

func (*DeviceRepository) Create

func (r *DeviceRepository) Create(device device.Device) (device.Device, error)

func (*DeviceRepository) Delete

func (r *DeviceRepository) Delete(device device.Device) error

func (*DeviceRepository) Find

func (r *DeviceRepository) Find(device device.Device) (device.Device, error)

func (*DeviceRepository) FindCloudFeedAuthCreationTimeFromDeviceID

func (r *DeviceRepository) FindCloudFeedAuthCreationTimeFromDeviceID(deviceID uint) (*needforheat.Time, error)

func (*DeviceRepository) GetAll

func (r *DeviceRepository) GetAll() ([]device.Device, error)

func (*DeviceRepository) GetAllByAccount

func (r *DeviceRepository) GetAllByAccount(accountID uint) ([]device.Device, error)

func (*DeviceRepository) GetMeasurements

func (r *DeviceRepository) GetMeasurements(device device.Device, filters map[string]string) ([]measurement.Measurement, error)

func (*DeviceRepository) GetProperties

func (r *DeviceRepository) GetProperties(device device.Device) ([]property.Property, error)

func (*DeviceRepository) Update

func (r *DeviceRepository) Update(device device.Device) (device.Device, error)

type DeviceTypeModel

type DeviceTypeModel struct {
	gorm.Model
	Name            string                `gorm:"unique;non null"`
	DataSourceTypes []DataSourceTypeModel `gorm:"polymorphic:TypeInstance;"`
}

Database representation of a devicetype.DeviceType

func MakeDeviceTypeModel

func MakeDeviceTypeModel(deviceType devicetype.DeviceType) DeviceTypeModel

Create a DeviceTypeModel from a devicetype.DeviceType.

func (DeviceTypeModel) TableName

func (DeviceTypeModel) TableName() string

Set the name of the table in the database.

type DeviceTypeRepository

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

func NewDeviceTypeRepository

func NewDeviceTypeRepository(db *gorm.DB) *DeviceTypeRepository

Create a new DeviceTypeRepository.

func (*DeviceTypeRepository) Create

func (*DeviceTypeRepository) Delete

func (r *DeviceTypeRepository) Delete(deviceType devicetype.DeviceType) error

func (*DeviceTypeRepository) Find

func (*DeviceTypeRepository) GetAll

type EnergyQueryModel

type EnergyQueryModel struct {
	gorm.Model
	EnergyQueryTypeModelID uint `gorm:"column:energy_query_type_id"`
	EnergyQueryType        EnergyQueryTypeModel
	AccountModelID         uint `gorm:"column:account_id"`
	ActivatedAt            *needforheat.Time
	Uploads                []UploadModel `gorm:"polymorphic:Instance;"`
}

Database representation of a energyquery.EnergyQuery

func MakeEnergyQueryModel

func MakeEnergyQueryModel(energyQuery energyquery.EnergyQuery) EnergyQueryModel

Create a EnergyQueryModel from a [EnergyQuery.EnergyQuery].

func (EnergyQueryModel) TableName

func (EnergyQueryModel) TableName() string

Set the name of the table in the database.

type EnergyQueryRepository

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

func NewEnergyQueryRepository

func NewEnergyQueryRepository(db *gorm.DB) *EnergyQueryRepository

Create a new EnergyQueryRepository.

func (*EnergyQueryRepository) Create

func (*EnergyQueryRepository) Delete

func (r *EnergyQueryRepository) Delete(energyQuery energyquery.EnergyQuery) error

func (*EnergyQueryRepository) Find

func (*EnergyQueryRepository) GetAll

func (*EnergyQueryRepository) GetAllByAccount

func (r *EnergyQueryRepository) GetAllByAccount(accountID uint) ([]energyquery.EnergyQuery, error)

func (*EnergyQueryRepository) GetMeasurements

func (r *EnergyQueryRepository) GetMeasurements(energyQuery energyquery.EnergyQuery, filters map[string]string) ([]measurement.Measurement, error)

func (*EnergyQueryRepository) GetProperties

func (r *EnergyQueryRepository) GetProperties(energyQuery energyquery.EnergyQuery) ([]property.Property, error)

func (*EnergyQueryRepository) Update

type EnergyQueryTypeModel

type EnergyQueryTypeModel struct {
	gorm.Model
	Name            string `gorm:"column:energy_query_variety"`
	Formula         string
	DataSourceTypes []DataSourceTypeModel `gorm:"polymorphic:TypeInstance;"`
}

Database representation of a energyquerytype.EnergyQueryType

func MakeEnergyQueryTypeModel

func MakeEnergyQueryTypeModel(energyQueryType energyquerytype.EnergyQueryType) EnergyQueryTypeModel

Create a EnergyQueryTypeModel from a [EnergyQueryType.EnergyQueryType].

func (EnergyQueryTypeModel) TableName

func (EnergyQueryTypeModel) TableName() string

Set the name of the table in the database.

type EnergyQueryTypeRepository

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

func NewEnergyQueryTypeRepository

func NewEnergyQueryTypeRepository(db *gorm.DB) *EnergyQueryTypeRepository

Create a new EnergyQueryTypeRepository.

func (*EnergyQueryTypeRepository) Create

func (*EnergyQueryTypeRepository) Delete

func (*EnergyQueryTypeRepository) Find

func (*EnergyQueryTypeRepository) GetAll

type MeasurementModel

type MeasurementModel struct {
	gorm.Model
	PropertyModelID uint `gorm:"column:property_id"`
	Property        PropertyModel
	UploadModelID   uint `gorm:"column:upload_id"`
	Time            time.Time
	Value           string
}

Database representation of a measurement.Measurement

func MakeMeasurementModel

func MakeMeasurementModel(measurement measurement.Measurement) MeasurementModel

Create a MeasurementModel from a measurement.Measurement.

func (MeasurementModel) TableName

func (MeasurementModel) TableName() string

Set the name of the table in the database.

type PropertyModel

type PropertyModel struct {
	gorm.Model
	Name string `gorm:"unique;non null"`
}

Database representation of a property.Property

func MakePropertyModel

func MakePropertyModel(property property.Property) PropertyModel

Create a PropertyModel from a property.Property.

func (PropertyModel) TableName

func (PropertyModel) TableName() string

Set the name of the table in the database.

type PropertyRepository

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

func NewPropertyRepository

func NewPropertyRepository(db *gorm.DB) *PropertyRepository

Create a new PropertyRepository.

func (*PropertyRepository) Create

func (r *PropertyRepository) Create(property property.Property) (property.Property, error)

func (*PropertyRepository) Delete

func (r *PropertyRepository) Delete(property property.Property) error

func (*PropertyRepository) Find

func (*PropertyRepository) GetAll

func (r *PropertyRepository) GetAll() ([]property.Property, error)

type UploadModel

type UploadModel struct {
	gorm.Model
	InstanceID   uint                `gorm:"column:instance_id"`
	InstanceType upload.InstanceType `gorm:"default:device"`
	ServerTime   needforheat.Time
	DeviceTime   needforheat.Time
	Size         int
	Measurements []MeasurementModel
}

Database representation of a upload.Upload

func MakeUploadModel

func MakeUploadModel(upload upload.Upload) UploadModel

Create an UploadModel from a upload.Upload.

func (UploadModel) TableName

func (UploadModel) TableName() string

Set the name of the table in the database.

type UploadRepository

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

func NewUploadRepository

func NewUploadRepository(db *gorm.DB) *UploadRepository

Create a new UploadRepository.

func (*UploadRepository) Create

func (r *UploadRepository) Create(upload upload.Upload) (upload.Upload, error)

func (*UploadRepository) Delete

func (r *UploadRepository) Delete(upload upload.Upload) error

func (*UploadRepository) Find

func (r *UploadRepository) Find(upload upload.Upload) (upload.Upload, error)

func (*UploadRepository) GetAll

func (r *UploadRepository) GetAll() ([]upload.Upload, error)

func (*UploadRepository) GetLatestUploadForDeviceWithID

func (r *UploadRepository) GetLatestUploadForDeviceWithID(id uint) (upload.Upload, error)

Jump to

Keyboard shortcuts

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