tables

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: BSD-3-Clause Imports: 15 Imported by: 4

Documentation

Index

Constants

View Source
const (
	Lt = "<"
	Gt = ">"
	Le = "<="
	Ge = ">="
)
View Source
const (
	DefaultPasswordCost    = 12
	DefaultExpirationDelta = 30 * 24 * time.Hour
)
View Source
const (
	Email = "email"
)

Variables

View Source
var (
	True  = true
	False = false
)
View Source
var Conditions = []string{
	Lt,
	Gt,
	Le,
	Ge,
}

Functions

func CheckCondition added in v0.0.5

func CheckCondition(condition string) error

Types

type Admin added in v0.0.5

type Admin struct {
	Model
	Username     string `json:"username" gorm:"unique;not null;"`
	Password     string `json:"password" gorm:"-"`
	PasswordHash []byte `json:"-" gorm:"not null;"`
}

func RandomAdmin added in v0.0.5

func RandomAdmin() *Admin

func (*Admin) Authenticate added in v0.0.5

func (a *Admin) Authenticate(password string) bool

func (*Admin) BeforeCreate added in v0.0.5

func (a *Admin) BeforeCreate(tx *gorm.DB) error

func (*Admin) BeforeSave added in v0.0.5

func (a *Admin) BeforeSave(tx *gorm.DB) error

func (*Admin) Claims added in v0.0.5

func (a *Admin) Claims() jwt.MapClaims

func (*Admin) FromClaims added in v0.0.5

func (a *Admin) FromClaims(m jwt.MapClaims) error

type Alert

type Alert struct {
	Model
	User       User      `json:"user" gorm:"foreignKey:UserUUID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	UserUUID   uuid.UUID `json:"userUUID" gorm:"uniqueIndex:idx_unique_alarm;not null;"`
	Name       *string   `json:"name" gorm:"uniqueIndex:idx_unique_alarm;not null;"`
	Sensor     Sensor    `json:"sensor" gorm:"foreignKey:SensorUUID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	SensorUUID uuid.UUID `json:"sensorUUID" gorm:"not null;"`
	Condition  *string   `json:"condition" gorm:"not null;"`
	Value      *float64  `json:"value" gorm:"not null;"`
	Enabled    *bool     `json:"enabled" gorm:"not null;default:FALSE"`
}

func RandomAlert

func RandomAlert(user *User, sensor *Sensor) *Alert

func (*Alert) BeforeCreate added in v0.0.5

func (a *Alert) BeforeCreate(tx *gorm.DB) error

type Message added in v0.0.6

type Message struct {
	Model
	Type      string `json:"type" gorm:"not null;"`
	Recipient string `json:"recipient" gorm:"not null;"`
	Subject   string `json:"subject" gorm:"not null;"`
	Body      string `json:"body" gorm:"not null;"`
}

func RandomMessage added in v0.0.6

func RandomMessage(t string) *Message

func (*Message) BeforeSave added in v0.0.6

func (m *Message) BeforeSave(tx *gorm.DB) error

type Model

type Model struct {
	UUID      uuid.UUID  `json:"uuid" gorm:"primaryKey"`
	CreatedAt time.Time  `json:"-"`
	UpdatedAt time.Time  `json:"-"`
	DeletedAt *time.Time `json:"-" sql:"index"`
}

func (*Model) BeforeSave

func (m *Model) BeforeSave(tx *gorm.DB) error

type Sensor

type Sensor struct {
	Model
	Station     Station          `json:"station" gorm:"foreignKey:StationUUID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	StationUUID uuid.UUID        `json:"stationUUID" gorm:"uniqueIndex:idx_unique_sensor;not null;"`
	Type        string           `json:"type" gorm:"uniqueIndex:idx_unique_sensor;not null;"`
	Registries  []SensorRegistry `json:"registries" gorm:"constraint:OnDelete:CASCADE;"`
}

func RandomSensor

func RandomSensor(station *Station) *Sensor

type SensorRegistry

type SensorRegistry struct {
	Model
	Sensor     Sensor    `json:"sensor" gorm:"foreignKey:SensorUUID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	SensorUUID uuid.UUID `json:"sensorUUID" gorm:"not null;"`
	Value      float64   `json:"value"`
}

type Station

type Station struct {
	Model
	User        User                       `json:"user" gorm:"foreignKey:UserUUID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
	UserUUID    uuid.UUID                  `json:"userUUID" gorm:"uniqueIndex:idx_unique_station;not null;"`
	Name        *string                    `json:"name" gorm:"uniqueIndex:idx_unique_station;not null;"`
	Description *string                    `json:"description"`
	Country     *countries.CountryCode     `json:"country" gorm:"not null;"`
	Subdivision *countries.SubdivisionCode `json:"subdivision" gorm:"not null"`
	Latitude    *float64                   `json:"latitude" gorm:"not null;"`
	Longitude   *float64                   `json:"longitude" gorm:"not null;"`
	APIKey      string                     `json:"-" gorm:"not null;"`
	APIKeyJSON  *string                    `json:"apiKey" gorm:"-"`
	Sensors     []Sensor                   `json:"sensors" gorm:"constraint:OnDelete:CASCADE;"`
}

func RandomStation

func RandomStation(user *User) *Station

func (*Station) BeforeCreate added in v0.0.5

func (s *Station) BeforeCreate(tx *gorm.DB) error

type User

type User struct {
	Model
	Username     string    `json:"username" gorm:"unique;not null;"`
	Password     string    `json:"password" gorm:"-"`
	PasswordHash []byte    `json:"-" gorm:"not null;"`
	Name         *string   `json:"name" gorm:"not null"`
	Phone        *string   `json:"phone" gorm:"unique;not null"`
	Email        *string   `json:"email" gorm:"unique;not null"`
	Confirmed    *bool     `json:"confirmed" gorm:"not null;default:FALSE;"`
	Alerts       []Alert   `json:"alerts" gorm:"constraint:OnDelete:CASCADE;"`
	Stations     []Station `json:"stations" gorm:"constraint:OnDelete:CASCADE;"`
}

func RandomUser

func RandomUser() *User

func (*User) Authenticate

func (u *User) Authenticate(password string) bool

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) error

func (*User) BeforeSave

func (u *User) BeforeSave(tx *gorm.DB) error

func (*User) BeforeUpdate added in v0.0.5

func (u *User) BeforeUpdate(tx *gorm.DB) error

func (*User) Claims

func (u *User) Claims() jwt.MapClaims

func (*User) FromClaims

func (u *User) FromClaims(m jwt.MapClaims) error

Jump to

Keyboard shortcuts

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