models

package
v0.0.0-...-ed7bc7a Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

DB and R variables is exported to use on the whole models package. The connections is set by using drivers on the main package.

View Source
var RPOOL *redis.Pool

RPOOL variables keeps a pool to get connection when need to access Redis.

Functions

func Login

func Login(username string, password string) (string, error)

Login checks the db with given username and password. Returns a result by checking if the user exist.

func Migrate

func Migrate() *gorm.DB

Migrate makes migrations by using gorm.

Types

type Noise

type Noise struct {
	gorm.Model
	Title       string    `gorm:"not null"`
	Author      User      `gorm:"foreignkey:AuthorRefer" json:"-"`
	AuthorRefer uint      `gorm:"not null" json:"-"`
	Tags        []Tag     `gorm:"many2many:noise_tags"`
	File        NoiseFile `gorm:"foreignkey:NoiseRefer;association_foreignkey:ID" json:"-"`
	Text        string
	IsActive    bool `gorm:"default:false"`
}

Noise model.

func (*Noise) AfterSave

func (noise *Noise) AfterSave(scope *gorm.Scope) error

AfterCreate runs starting to recognition and returns. Recognition ops are run as a goroutine.

func (*Noise) Delete

func (noise *Noise) Delete() error

Delete temporarily deletes the noise.

func (*Noise) DeletePermanently

func (noise *Noise) DeletePermanently() error

DeletePermanently deletes the noise permanently.

func (*Noise) Update

func (noise *Noise) Update(user *User, title string, file []byte, ts []string) error

Update updates the noise with given attributes.

type NoiseFile

type NoiseFile struct {
	gorm.Model
	Data       []byte `gorm:"not null"` // TODO move file to gcloud.
	Noise      *Noise `gorm:"foreignkey:NoiseRefer"`
	NoiseRefer uint   `gorm:"not null"`
}

NoiseFile model.

type Tag

type Tag struct {
	gorm.Model
	Title       string  `gorm:"not null"`
	Author      User    `gorm:"foreignkey:AuthorRefer" json:"-"`
	AuthorRefer uint    `gorm:"not null" json:"-"`
	Noises      []Noise `gorm:"many2many:noise_tags" json:"-"`
}

Tag model.

type User

type User struct {
	gorm.Model
	Name     string  `gorm:"not null"`
	Surname  string  `gorm:"not null"`
	Username string  `gorm:"unique;unique_index;not null"`
	Password []byte  `gorm:"not null" json:"-"`
	Noises   []Noise `gorm:"foreignkey:AuthorRefer;association_foreignkey:ID" json:"-"`
	Tags     []Tag   `gorm:"foreignkey:AuthorRefer;association_foreignkey:ID" json:"-"`
}

User model.

func CurrentUser

func CurrentUser(token string) (User, error)

CurrentUser returns the current user that matches with the token.

func SignUp

func SignUp(name string, surname string, username string, password string) (User, error)

SignUp creates users by using username and password. Password is hashed by using bcrypt package.

func (*User) Delete

func (user *User) Delete() error

Delete deletes the user.

func (*User) DeletePermanently

func (user *User) DeletePermanently() error

DeletePermanently deletes the user.

func (*User) GetNoise

func (user *User) GetNoise(id string) (Noise, error)

GetNoise returns wanted noise that is associated with the user.

func (*User) GetNoiseWithFile

func (user *User) GetNoiseWithFile(id string) (Noise, error)

GetNoiseWithFile returns wanted noise's file that is associated with the user.

func (*User) GetNoises

func (user *User) GetNoises(q string, sort string, take int) ([]Noise, error)

GetNoises returns all noises that are matched by checking noises' titles, noises' texts and tags' titles. It can set sort type and limit.

func (*User) Logout

func (user *User) Logout(token string) error

Logout removes the current user's session.

func (*User) NoiseCreate

func (user *User) NoiseCreate(title string, file []byte, ts []string) (Noise, error)

NoiseCreate creates a noise for the user.

Jump to

Keyboard shortcuts

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