repositories

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: 24 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.

Types

type AccountModel

type AccountModel struct {
	gorm.Model
	CampaignModelID uint `gorm:"column:campaign_id"`
	Campaign        CampaignModel
	ActivatedAt     *time.Time
	Buildings       []BuildingModel
	CloudFeedAuths  []CloudFeedAuthModel `gorm:"foreignKey:AccountID"`
}

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(account 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 BuildingModel

type BuildingModel struct {
	gorm.Model
	AccountModelID uint `gorm:"column:account_id"`
	Longtitude     float32
	Latitude       float32
	TZName         string
	Devices        []DeviceModel
}

Database representation of a building.Building.

func MakeBuildingModel

func MakeBuildingModel(building building.Building) BuildingModel

Create a new BuildingModel from a building.Building

func (BuildingModel) TableName

func (BuildingModel) TableName() string

Set the name of the table in the database.

type BuildingRepository

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

func NewBuildingRepository

func NewBuildingRepository(db *gorm.DB) *BuildingRepository

func (*BuildingRepository) Create

func (r *BuildingRepository) Create(building building.Building) (building.Building, error)

func (*BuildingRepository) Delete

func (r *BuildingRepository) Delete(building building.Building) error

func (*BuildingRepository) Find

func (*BuildingRepository) GetAll

func (r *BuildingRepository) GetAll() ([]building.Building, 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"`
	CloudFeeds []CloudFeedModel `gorm:"many2many:campaign_cloud_feed"`
	StartTime  *time.Time
	EndTime    *time.Time
}

Database representation of campaign.Campaign.

func MakeCampaignModel

func MakeCampaignModel(campaign campaign.Campaign) CampaignModel

Create a new CampaignModel from a [twomes.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 (*CampaignRepository) GetAll

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

type CloudFeedAuthModel

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

Database representation of cloudfeedauth.CloudFeedAuth.

func MakeCloudFeedAuthModel

func MakeCloudFeedAuthModel(cloudFeedAuth cloudfeedauth.CloudFeedAuth) CloudFeedAuthModel

Create a new CloudFeedAuthModel from a [twomes.cloudFeedAuth].

func (CloudFeedAuthModel) TableName

func (CloudFeedAuthModel) TableName() string

Set the name of the table in the database.

type CloudFeedAuthRepository

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

func NewCloudFeedAuthRepository

func NewCloudFeedAuthRepository(db *gorm.DB) *CloudFeedAuthRepository

func (*CloudFeedAuthRepository) Create

func (*CloudFeedAuthRepository) Delete

func (r *CloudFeedAuthRepository) Delete(cloudFeedAuth cloudfeedauth.CloudFeedAuth) error

func (*CloudFeedAuthRepository) Find

func (*CloudFeedAuthRepository) FindDevice

func (r *CloudFeedAuthRepository) FindDevice(cloudFeedAuth cloudfeedauth.CloudFeedAuth) (*device.Device, error)

func (*CloudFeedAuthRepository) FindFirstTokenToExpire

func (r *CloudFeedAuthRepository) FindFirstTokenToExpire() (uint, uint, time.Time, error)

func (*CloudFeedAuthRepository) FindOAuthInfo

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

func (*CloudFeedAuthRepository) GetAll

func (*CloudFeedAuthRepository) Update

type CloudFeedModel

type CloudFeedModel 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
	CloudFeedAuths []CloudFeedAuthModel `gorm:"foreignKey:CloudFeedID"`
}

Database representation of a cloudfeed.CloudFeed

func MakeCloudFeedModel

func MakeCloudFeedModel(cloudFeed cloudfeed.CloudFeed) CloudFeedModel

Create a CloudFeedModel from a cloudfeed.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

Create a new CloudFeedRepository.

func (*CloudFeedRepository) Create

func (*CloudFeedRepository) Delete

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

func (*CloudFeedRepository) Find

func (*CloudFeedRepository) GetAll

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

func (*CloudFeedRepository) Update

type DeviceModel

type DeviceModel struct {
	gorm.Model
	Name                 string `gorm:"unique;not null"`
	DeviceTypeModelID    uint   `gorm:"column:device_type_id"`
	DeviceType           DeviceTypeModel
	BuildingModelID      uint `gorm:"column:building_id"`
	ActivationSecretHash string
	ActivatedAt          *time.Time
	Uploads              []UploadModel
}

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) (*time.Time, error)

func (*DeviceRepository) GetAll

func (r *DeviceRepository) GetAll() ([]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"`
	InstallationManualURL string
	InfoURL               string
}

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 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
	DeviceModelID uint `gorm:"column:device_id"`
	ServerTime    time.Time
	DeviceTime    time.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