models

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const HTMLSplitTag = "\t"

Variables

View Source
var Pagination = PaginationVO{Page: 1, Size: 10}
View Source
var UserStatuses = map[string]UserStatus{
	"ActivatedStatus": ActivatedStatus,
	"InactiveStatus":  InactiveStatus,
}

Functions

func DB

func DB() *gorm.DB

func MarkTotal added in v0.2.0

func MarkTotal(userID uint) (total int64)

func PaginationScope

func PaginationScope(vo PaginationVO) func(db *gorm.DB) *gorm.DB

func Ping

func Ping() error

func RegisterGormCallBack

func RegisterGormCallBack() (err error)

Types

type BaseModel

type BaseModel struct {
	ID        uint      `gorm:"primarykey" json:"id"`
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
	DeletedAt DeletedAt `gorm:"default:0;index" json:"-"`
}

type Comment added in v0.2.0

type Comment struct {
	BaseModel
	UserID  uint   `gorm:"not null" json:"-" binding:"required"`
	User    *User  `json:"user,omitempty"`
	MarkID  uint   `gorm:"index;not null" json:"mark_id" binding:"required"`
	Content string `gorm:"type:text" json:"content" binding:"required"`
}

func CommentCreate added in v0.2.0

func CommentCreate(userID uint, markID uint, content string) (comment *Comment, err error)

func CommentDestroy added in v0.2.0

func CommentDestroy(userID uint, markID uint) (comment *Comment, err error)

func CommentFind added in v0.2.0

func CommentFind(commentID uint) (comment *Comment, err error)

func CommentFindByMarkID added in v0.2.0

func CommentFindByMarkID(userID uint, markID uint) (comment *Comment, err error)

func CommentUpdate added in v0.2.0

func CommentUpdate(userID uint, markID uint, content string) (comment *Comment, err error)

func FakeComment added in v0.2.0

func FakeComment(userID uint, markID uint) *Comment

type CommentVO added in v0.2.0

type CommentVO struct {
	Content string `json:"content" binding:"required"`
}

type DeletedAt added in v0.2.0

type DeletedAt int64

func (DeletedAt) DeleteClauses added in v0.2.0

func (DeletedAt) DeleteClauses(f *schema.Field) []clause.Interface

func (DeletedAt) MarshalJSON added in v0.2.0

func (n DeletedAt) MarshalJSON() ([]byte, error)

func (DeletedAt) QueryClauses added in v0.2.0

func (DeletedAt) QueryClauses(f *schema.Field) []clause.Interface

func (*DeletedAt) Scan added in v0.2.0

func (n *DeletedAt) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*DeletedAt) UnmarshalJSON added in v0.2.0

func (n *DeletedAt) UnmarshalJSON(b []byte) error

func (DeletedAt) Value added in v0.2.0

func (n DeletedAt) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Mark

type Mark struct {
	BaseModel
	UserID    uint      `gorm:"not null" json:"user_id" binding:"required"`
	URL       string    `gorm:"type:varchar(255);index" json:"url" binding:"required"`
	Tag       string    `gorm:"type:varchar(255);comment:color or other tag;not null" json:"tag" binding:"required"`
	HashKey   string    `gorm:"type:varchar(255);not null" json:"hash_key" binding:"required"`
	Selection Selection `gorm:"type:text;not null" json:"selection" binding:"required"`

	Comment *Comment `json:"comment,omitempty"` // has one
}

func FakeMark added in v0.2.0

func FakeMark(userID uint) *Mark

func MarkCreate added in v0.2.0

func MarkCreate(userID uint, vo *MarkCreateVO) (mark *Mark, err error)

func MarkDestroy added in v0.2.0

func MarkDestroy(userID uint, hashKey string) (mark *Mark, err error)

func MarkFind added in v0.2.0

func MarkFind(markID uint) (mark *Mark, err error)

func MarkFindByHashKey added in v0.2.0

func MarkFindByHashKey(userID uint, hashKey string) (mark *Mark, err error)

func MarkList added in v0.2.0

func MarkList(userID uint, vo PaginationVO) []Mark

func MarkQuery added in v0.2.0

func MarkQuery(userID uint, safeBase64URL string) []*Mark

func MarkUpdate added in v0.2.0

func MarkUpdate(userID uint, hashKey string, vo *MarkUpdateVO) (mark *Mark, err error)

func (*Mark) SelectionText added in v0.2.0

func (m *Mark) SelectionText() string

type MarkCreateVO

type MarkCreateVO struct {
	URL       string    `json:"url" binding:"required"`
	Tag       string    `json:"tag" binding:"required"`
	HashKey   string    `json:"hash_key" binding:"required"`
	Selection Selection `json:"selection" binding:"required"`
}

type MarkUpdateVO

type MarkUpdateVO struct {
	Tag string `json:"tag"`
}

type PaginationVO

type PaginationVO struct {
	Page int `json:"page" form:"page" binding:"min=1"`
	Size int `json:"size" form:"size" binding:"max=100"`
}

type Selection added in v0.2.0

type Selection struct {
	Texts       []string `json:"texts" binding:"required"`
	StartOffset int      `json:"startOffset"`
	EndOffset   int      `json:"endOffset" binding:"required"`
}

func FakeSelection added in v0.2.0

func FakeSelection() *Selection

func (*Selection) Scan added in v0.2.0

func (s *Selection) Scan(value interface{}) error

Scan from DB

func (Selection) Value added in v0.2.0

func (s Selection) Value() (driver.Value, error)

Save to DB

type Session

type Session struct {
	BaseModel
	Token     string    `json:"token" gorm:"uniqueindex;not null;type:varchar(255)"`
	ExpiredAt time.Time `json:"expired_at" gorm:"not null"`
	UserID    uint      `json:"user_id" gorm:"not null"`
	User      *User     `json:"user,omitempty"`
}

func SessionFindByToken added in v0.2.0

func SessionFindByToken(token string) (session *Session, err error)

type SessionVO

type SessionVO struct {
	Email    string `json:"email" form:"email" binding:"required,email"`
	Password string `json:"password" form:"password" binding:"min=6"`
}

type SoftDeleteDeleteClause added in v0.2.0

type SoftDeleteDeleteClause struct {
	Field *schema.Field
}

func (SoftDeleteDeleteClause) Build added in v0.2.0

func (SoftDeleteDeleteClause) MergeClause added in v0.2.0

func (sd SoftDeleteDeleteClause) MergeClause(*clause.Clause)

func (SoftDeleteDeleteClause) ModifyStatement added in v0.2.0

func (sd SoftDeleteDeleteClause) ModifyStatement(stmt *gorm.Statement)

func (SoftDeleteDeleteClause) Name added in v0.2.0

func (sd SoftDeleteDeleteClause) Name() string

type SoftDeleteQueryClause added in v0.2.0

type SoftDeleteQueryClause struct {
	Field *schema.Field
}

func (SoftDeleteQueryClause) Build added in v0.2.0

func (SoftDeleteQueryClause) MergeClause added in v0.2.0

func (sd SoftDeleteQueryClause) MergeClause(*clause.Clause)

func (SoftDeleteQueryClause) ModifyStatement added in v0.2.0

func (sd SoftDeleteQueryClause) ModifyStatement(stmt *gorm.Statement)

func (SoftDeleteQueryClause) Name added in v0.2.0

func (sd SoftDeleteQueryClause) Name() string

type User

type User struct {
	BaseModel
	Status       string `json:"status"`
	Email        string `json:"email" binding:"required"`
	Avatar       string `json:"avatar"`
	PasswordHash string `json:"-"`
	Password     string `json:"-" gorm:"-"`
}

func FakeUser

func FakeUser() *User

func UserCreate added in v0.2.0

func UserCreate(email string, password string) (u *User, err error)

func UserFindByEmail added in v0.2.0

func UserFindByEmail(email string) (u *User, err error)

func (*User) CalcPasswordHash

func (u *User) CalcPasswordHash() error

func (*User) GenerateSession

func (u *User) GenerateSession() (s *Session, err error)

func (*User) ValidPassword

func (u *User) ValidPassword() bool

type UserStatus

type UserStatus string
const (
	ActivatedStatus UserStatus = "ActivatedStatus"
	InactiveStatus  UserStatus = "InactiveStatus"
)

func (UserStatus) String

func (s UserStatus) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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