models

package
v0.0.0-...-5e06dbd Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	ID        uint64     `gorm:"primary_key;AUTO_INCREMENT" json:"id"`
	Title     string     `gorm:"size:250;not_null;unique" json:"title" validate:"required"`
	Body      string     `gorm:"size:500;" json:"body"`
	AuthorID  uint64     `gorm:"not_null" json:"author_id" validate:"required"`
	Author    User       `gorm:"foreignkey:AuthorID" json:"author"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at,omitempty" sql:"index"`
}

Article struct

func (*Article) Prepare

func (a *Article) Prepare()

Prepare func

func (*Article) Validate

func (a *Article) Validate() error

Validate cooler one

type ArticleInterface

type ArticleInterface interface {
	GetAllArticles() ([]Article, error)
	SaveArticle(a *Article) (*Article, error)
	FetchArticleByID(id uint64) (Article, error)
	DeleteByID(id uint64, uid uint64) (int64, error)
	UpdateArticle(a *Article, id int64, uid uint64) (int64, error)
	DeleteAllArticles() (int64, error)
}

ArticleInterface -

type AuthInterface

type AuthInterface interface {
	SignIn(string, string) (string, error)
}

AuthInterface -

type User

type User struct {
	ID        uint64    `gorm:"primary_key;AUTO_INCREMENT" json:"id"`
	Nickname  string    `gorm:"size:20;not null,unique" json:"nickname" validate:"required"`
	Email     string    `gorm:"size:20;not null,unique" json:"email" validate:"required,email"`
	Password  string    `gorm:"size:60;not null" json:"password" validate:"required"`
	CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
	Articles  []Article `json:"articles,omitempty"`
}

User struct

func (*User) BeforeSave

func (u *User) BeforeSave() error

BeforeSave the password

func (*User) Prepare

func (u *User) Prepare()

Prepare method

func (*User) Validate

func (u *User) Validate() error

Validate - cool validator TODO : use case switch statement to validate for various scenarios - when loggin in, creating user etc.

type UsersInterface

type UsersInterface interface {
	Save(*User) (*User, error)
	FindAll() ([]User, error)
	FindUserByID(uint64) (User, error)
}

UsersInterface -

Jump to

Keyboard shortcuts

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