tables

package
v0.0.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultPasswordCost    = 12
	DefaultExpirationDelta = 30 * 24 * time.Hour
)

Variables

View Source
var Conditions = map[Condition]string{
	Lt: "<",
	Gt: ">",
	Le: "<=",
	Ge: ">=",
}
View Source
var ConditionsOPs = map[string]Condition{
	"<":  Lt,
	">":  Gt,
	"<=": Le,
	">=": Ge,
}

Functions

This section is empty.

Types

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;"`
	ConditionOP string    `json:"conditionOP" gorm:"-"`
	Condition   Condition `json:"-" gorm:"not null;"`
	Value       float64   `json:"value" gorm:"not null;"`
}

func RandomAlert

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

func (*Alert) AfterFind

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

func (*Alert) BeforeSave

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

type Condition

type Condition int
const (
	Lt Condition = iota
	Gt
	Le
	Ge
)

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"`
}

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;"`
	CountryName     string                    `json:"countryName" gorm:"-"`
	SubdivisionName string                    `json:"subdivisionName" gorm:"-"`
	Country         countries.CountryCode     `json:"-" gorm:"not null;"`
	Subdivision     countries.SubdivisionCode `json:"-" gorm:"not null"`
	Description     string                    `json:"description"`
	Latitude        float64                   `json:"latitude" gorm:"not null;"`
	Longitude       float64                   `json:"longitude" gorm:"not null;"`
	Sensors         []Sensor                  `json:"sensors"`
}

func RandomStation

func RandomStation(user *User) *Station

func (*Station) AfterFind

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

func (*Station) BeforeSave

func (s *Station) BeforeSave(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:"confimed" gorm:"not null;default:FALSE;"`
	Stations     []Station `json:"stations"`
}

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