models

package
v0.0.0-...-d7671c7 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMD5Hash

func GetMD5Hash(text string) string

func Hash

func Hash(password string) ([]byte, error)

func VerifyPassword

func VerifyPassword(hashedPassword, password string) error

Types

type Election

type Election struct {
	ID          uint64    `gorm:"primary_key;auto_increment" json:"id"`
	Title       string    `gorm:"size:255;not null;unique" json:"title"`
	Description string    `gorm:"size:255;not null;" json:"description"`
	Author      User      `json:"author"`
	AuthorID    uint32    `sql:"type:int REFERENCES users(id)" json:"author_id"`
	Candidates  JsonArray `json:"candidates"`
	Data        JSON      `json:"data"`
	CreatedAt   time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt   time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
}

func (*Election) DeleteAElection

func (p *Election) DeleteAElection(db *gorm.DB, pid uint64, uid uint32) (int64, error)

func (*Election) FindAllElections

func (p *Election) FindAllElections(db *gorm.DB) (*[]Election, error)

func (*Election) FindElectionByID

func (p *Election) FindElectionByID(db *gorm.DB, pid uint64) (*Election, error)

func (*Election) Prepare

func (p *Election) Prepare()

func (*Election) SaveElection

func (p *Election) SaveElection(db *gorm.DB) (*Election, error)

func (*Election) UpdateAElection

func (p *Election) UpdateAElection(db *gorm.DB) (*Election, error)

func (*Election) Validate

func (p *Election) Validate() error

type JSON

type JSON map[string]interface{}

func (JSON) GormDBDataType

func (JSON) GormDBDataType(db *gorm.DB, field *schema.Field) string

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type JsonArray

type JsonArray []map[string]interface{}

func (JsonArray) GormDBDataType

func (JsonArray) GormDBDataType(db *gorm.DB, field *schema.Field) string

func (*JsonArray) Scan

func (j *JsonArray) Scan(value interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (JsonArray) Value

func (j JsonArray) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type LoginUser

type LoginUser struct {
	User
	Token string `json:"token,omitempty"`
}

func (*LoginUser) Validate

func (u *LoginUser) Validate(action string) error

type Post

type Post struct {
	ID        uint64    `gorm:"primary_key;auto_increment" json:"id"`
	Title     string    `gorm:"size:255;not null;unique" json:"title"`
	Content   string    `gorm:"size:255;not null;" json:"content"`
	Author    User      `json:"author"`
	AuthorID  uint32    `sql:"type:int REFERENCES users(id)" json:"author_id"`
	CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
}

func (*Post) DeleteAPost

func (p *Post) DeleteAPost(db *gorm.DB, pid uint64, uid uint32) (int64, error)

func (*Post) FindAllPosts

func (p *Post) FindAllPosts(db *gorm.DB) (*[]Post, error)

func (*Post) FindPostByID

func (p *Post) FindPostByID(db *gorm.DB, pid uint64) (*Post, error)

func (*Post) Prepare

func (p *Post) Prepare()

func (*Post) SavePost

func (p *Post) SavePost(db *gorm.DB) (*Post, error)

func (*Post) UpdateAPost

func (p *Post) UpdateAPost(db *gorm.DB) (*Post, error)

func (*Post) Validate

func (p *Post) Validate() error

type User

type User struct {
	ID        uint32    `gorm:"primary_key;auto_increment" json:"id"`
	Nickname  string    `gorm:"size:255;not null;unique" json:"nickname"`
	Email     string    `gorm:"size:100;not null;unique" json:"email"`
	Password  string    `gorm:"size:100;not null;" json:"password,omitempty"`
	Admin     bool      `gorm:"not null;default:false" json:"admin"`
	CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
}

func (*User) BeforeSave

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

func (*User) DeleteAUser

func (u *User) DeleteAUser(db *gorm.DB, uid uint32) (int64, error)

func (*User) FindAllUsers

func (u *User) FindAllUsers(db *gorm.DB) (*[]User, error)

func (*User) FindUserByID

func (u *User) FindUserByID(db *gorm.DB, uid uint32) (*User, error)

func (*User) Prepare

func (u *User) Prepare()

func (*User) ResetUserPassword

func (u *User) ResetUserPassword(db *gorm.DB, uid uint32, sendEmail bool) (*User, error)

func (*User) SaveUser

func (u *User) SaveUser(db *gorm.DB) (*User, error)

func (*User) UpdateAUser

func (u *User) UpdateAUser(db *gorm.DB, uid uint32) (*User, error)

func (*User) Validate

func (u *User) Validate(action string) error

type Vote

type Vote struct {
	ID         uint64    `gorm:"primary_key;auto_increment" json:"id"`
	ElectionID uint64    `gorm:"column:election_id" json:"election_id"`
	Author     User      `json:"author"`
	AuthorID   uint32    `sql:"column:author_id;type:int REFERENCES users(id)" json:"author_id"`
	Ranking    JsonArray `json:"ranking"`
	CreatedAt  time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
}

func (*Vote) FindAllVotes

func (v *Vote) FindAllVotes(db *gorm.DB, getAuthors bool) (*[]Vote, error)

func (*Vote) FindVoteByID

func (v *Vote) FindVoteByID(db *gorm.DB, pid uint64) (*Vote, error)

func (*Vote) Prepare

func (p *Vote) Prepare()

func (*Vote) SaveVote

func (v *Vote) SaveVote(db *gorm.DB) (*Vote, error)

func (*Vote) Validate

func (p *Vote) Validate() error

Jump to

Keyboard shortcuts

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