models

package
v0.0.0-...-a8fe247 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VerificationCodeLength = 6
)

Variables

View Source
var (
	ErrSentryNotRunning      = errors.New("Sentry is not in running state.")
	ErrInvalidNotificationID = errors.New("Invalid notification ID.")
	ErrZeroAffectedRows      = errors.New("Zero affected rows.")
)

Functions

func Init

func Init(db *gorm.DB) (err error)

func IsErrNoDocument

func IsErrNoDocument(err error) bool

func Transaction

func Transaction(fun func(tx TX) error) error

Types

type EmailVerification

type EmailVerification struct {
	ID               uint      `gorm:"primary_key"`
	Email            string    `gorm:"type:varchar(255);index:email_expiredat"`
	VerificationCode string    `gorm:"type:char(6)"` // verificationCodeLength
	ExpiredAt        time.Time `gorm:"index:email_expiredat"`
}

type NotificationMethod

type NotificationMethod struct {
	ID        int64  `gorm:"primary_key;auto_increment:false"` // use snowflake for this ID
	Name      string `gorm:"type:varchar(100)"`
	UserID    int64  `gorm:"index"` // foreignkey: User.ID
	Type      string `gorm:"type:varchar(16)"`
	Setting   string // json
	CreatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

type RunningState

type RunningState int64
const (
	RSRunning RunningState = 1
	RSPaused  RunningState = -1
)

func (*RunningState) Scan

func (p *RunningState) Scan(value interface{}) error

func (RunningState) Value

func (p RunningState) Value() (driver.Value, error)

type Sentry

type Sentry struct {
	ID             int64  `gorm:"primary_key;auto_increment:false"` // use snowflake for this ID
	Name           string `gorm:"type:varchar(100)"`
	UserID         int64  `gorm:"index"` // foreignkey: User.ID
	RunningState   RunningState
	NotificationID int64  // foreignkey: NotificationMethod.ID
	Trigger        string // json
	LastCheckTime  *time.Time
	NextCheckTime  time.Time `gorm:"index"`
	Interval       int
	CheckCount     int
	NotifyCount    int
	LatestImageID  *uint  // foreignkey: SentryImage.ID
	Task           string // json
	CreatedAt      time.Time
	DeletedAt      gorm.DeletedAt `gorm:"index"`
}

type SentryImage

type SentryImage struct {
	ID        uint      `gorm:"primary_key"`
	SentryID  int64     `gorm:"index:sentryid_createdat"` // foreignkey: Sentry.ID
	File      string    `gorm:"type:varchar(40)"`
	CreatedAt time.Time `gorm:"index:sentryid_createdat"`
}

type SystemSetting

type SystemSetting struct {
	Key   string `gorm:"primary_key;type:varchar(64)"`
	Value string
}

type TX

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

func (TX) CheckUserExistence

func (t TX) CheckUserExistence(u string) (bool, error)

func (TX) CheckVerificationCode

func (t TX) CheckVerificationCode(u string, vc string) (bool, error)

CheckVerificationCode checks if the given verification code is one of the non-expired verification existed in the db

func (TX) CreateEmailVerification

func (t TX) CreateEmailVerification(u string) (string, error)

CreateCreateEmailVerification create new verification code associated with an email address

func (TX) CreateSentry

func (t TX) CreateSentry(s *Sentry) (int64, error)

func (TX) CreateUser

func (t TX) CreateUser(u string, pwd string, tz *time.Location, lang language.Tag) error

CreateUser add a new user and the default notification method

func (TX) DeleteSentry

func (t TX) DeleteSentry(id int64, uid int64) error

func (TX) GetImageHistory

func (t TX) GetImageHistory(id int64) (results []SentryImage, err error)

func (TX) GetNotification

func (t TX) GetNotification(id int64) (*NotificationMethod, error)

func (TX) GetSentry

func (t TX) GetSentry(id int64) (*Sentry, error)

func (TX) GetSentryName

func (t TX) GetSentryName(id int64) (string, error)

func (TX) GetSentryNotification

func (t TX) GetSentryNotification(id int64) (int64, error)

func (TX) GetUncheckedSentry

func (t TX) GetUncheckedSentry() (*Sentry, *SentryImage, error)

If there isn't an unchecked sentry, it returns (nil, nil, nil)

func (TX) GetUserByID

func (t TX) GetUserByID(id int64) (*User, error)

GetUserByID get the user's information by his id, it takes a id, and a result structure

func (TX) GetUserSentries

func (t TX) GetUserSentries(userID int64) (results []Sentry, err error)

func (TX) IsLastVerificationCodeGeneratedTimeExceeded

func (t TX) IsLastVerificationCodeGeneratedTimeExceeded(u string) (bool, error)

IsLastVerificationCodeGeneratedTimeExceeded checks if the current is within the duration allowed starting from when the latest verification code is created

func (TX) NotificationAddEmail

func (t TX) NotificationAddEmail(userID int64, email string, name string) (err error)

func (TX) NotificationAddServerChan

func (t TX) NotificationAddServerChan(name string, userID int64, sckey string) (id int64, err error)

func (TX) NotificationList

func (t TX) NotificationList(userID int64) (results []NotificationMethod, err error)

func (TX) UpdateSentry

func (t TX) UpdateSentry(sid int64, uid int64, s *Sentry) error

func (TX) UpdateSentryAfterCheck

func (t TX) UpdateSentryAfterCheck(id int64, changed bool, newImage string) error

func (TX) UpdateUser

func (t TX) UpdateUser(id int64, u User) error

func (TX) UserLogin

func (t TX) UserLogin(u, p string) (*int64, error)

type Trigger

type Trigger struct {
	SimilarityThreshold float64 `json:"similarityThreshold"`
}

Stored as json string

type User

type User struct {
	ID        int64  `gorm:"primary_key;auto_increment:false"` // use snowflake for this ID
	Email     string `gorm:"type:varchar(255);unique_index"`   // lower case
	Password  string `gorm:"type:char(60)"`                    // bcrypt
	Language  string `gorm:"type:varchar(10)"`
	TimeZone  string `gorm:"type:varchar(64)"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

Jump to

Keyboard shortcuts

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