model

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserStatusNormal int = iota + 1
	UserStatusClosed
)
View Source
const MSG_READED = 1
View Source
const MSG_UNREAD = 0

Variables

This section is empty.

Functions

func NewDBEngine

func NewDBEngine(databaseSetting *setting.DatabaseSettingS) (*gorm.DB, error)

Types

type Attachment

type Attachment struct {
	*Model
	UserID    int64          `json:"user_id"`
	FileSize  int64          `json:"file_size"`
	ImgWidth  int            `json:"img_width"`
	ImgHeight int            `json:"img_height"`
	Type      AttachmentType `json:"type"`
	Content   string         `json:"content"`
}

func (*Attachment) Create

func (a *Attachment) Create(db *gorm.DB) (*Attachment, error)

type AttachmentType

type AttachmentType int
const (
	ATTACHMENT_TYPE_IMAGE AttachmentType = iota + 1
	ATTACHMENT_TYPE_VIDEO
	ATTACHMENT_TYPE_OTHER
)

type Captcha

type Captcha struct {
	*Model
	Phone     string `json:"phone"`
	Captcha   string `json:"captcha"`
	UseTimes  int    `json:"use_times"`
	ExpiredOn int64  `json:"expired_on"`
}

func (*Captcha) Create

func (c *Captcha) Create(db *gorm.DB) (*Captcha, error)

func (*Captcha) Get

func (c *Captcha) Get(db *gorm.DB) (*Captcha, error)

func (*Captcha) Update

func (c *Captcha) Update(db *gorm.DB) error

type Comment

type Comment struct {
	*Model
	PostID int64  `json:"post_id"`
	UserID int64  `json:"user_id"`
	IP     string `json:"ip"`
	IPLoc  string `json:"ip_loc"`
}

func (*Comment) Count

func (c *Comment) Count(db *gorm.DB, conditions *ConditionsT) (int64, error)

func (*Comment) Create

func (c *Comment) Create(db *gorm.DB) (*Comment, error)

func (*Comment) Delete

func (c *Comment) Delete(db *gorm.DB) error

func (*Comment) Format

func (c *Comment) Format() *CommentFormated

func (*Comment) Get

func (c *Comment) Get(db *gorm.DB) (*Comment, error)

func (*Comment) List

func (c *Comment) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([]*Comment, error)

type CommentContent

type CommentContent struct {
	*Model
	CommentID int64        `json:"comment_id"`
	UserID    int64        `json:"user_id"`
	Content   string       `json:"content"`
	Type      PostContentT `json:"type"`
	Sort      int64        `json:"sort"`
}

func (*CommentContent) Create

func (c *CommentContent) Create(db *gorm.DB) (*CommentContent, error)

func (*CommentContent) List

func (c *CommentContent) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([]*CommentContent, error)

type CommentFormated

type CommentFormated struct {
	ID         int64                   `json:"id"`
	PostID     int64                   `json:"post_id"`
	UserID     int64                   `json:"user_id"`
	User       *UserFormated           `json:"user"`
	Contents   []*CommentContent       `json:"contents"`
	Replies    []*CommentReplyFormated `json:"replies"`
	IPLoc      string                  `json:"ip_loc"`
	CreatedOn  int64                   `json:"created_on"`
	ModifiedOn int64                   `json:"modified_on"`
}

type CommentReply

type CommentReply struct {
	*Model
	CommentID int64  `json:"comment_id"`
	UserID    int64  `json:"user_id"`
	AtUserID  int64  `json:"at_user_id"`
	Content   string `json:"content"`
	IP        string `json:"ip"`
	IPLoc     string `json:"ip_loc"`
}

func (*CommentReply) Create

func (c *CommentReply) Create(db *gorm.DB) (*CommentReply, error)

func (*CommentReply) Delete

func (c *CommentReply) Delete(db *gorm.DB) error

func (*CommentReply) Format

func (c *CommentReply) Format() *CommentReplyFormated

func (*CommentReply) Get

func (c *CommentReply) Get(db *gorm.DB) (*CommentReply, error)

func (*CommentReply) List

func (c *CommentReply) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([]*CommentReply, error)

type CommentReplyFormated

type CommentReplyFormated struct {
	ID         int64         `json:"id"`
	CommentID  int64         `json:"comment_id"`
	UserID     int64         `json:"user_id"`
	User       *UserFormated `json:"user"`
	AtUserID   int64         `json:"at_user_id"`
	AtUser     *UserFormated `json:"at_user"`
	Content    string        `json:"content"`
	IPLoc      string        `json:"ip_loc"`
	CreatedOn  int64         `json:"created_on"`
	ModifiedOn int64         `json:"modified_on"`
}

type ConditionsT

type ConditionsT map[string]interface{}

type Message

type Message struct {
	*Model
	SenderUserID   int64    `json:"sender_user_id"`
	ReceiverUserID int64    `json:"receiver_user_id"`
	Type           MessageT `json:"type"`
	Brief          string   `json:"brief"`
	Content        string   `json:"content"`
	PostID         int64    `json:"post_id"`
	CommentID      int64    `json:"comment_id"`
	ReplyID        int64    `json:"reply_id"`
	IsRead         int8     `json:"is_read"`
}

func (*Message) Count

func (m *Message) Count(db *gorm.DB, conditions *ConditionsT) (int64, error)

func (*Message) Create

func (m *Message) Create(db *gorm.DB) (*Message, error)

func (*Message) Format

func (m *Message) Format() *MessageFormated

func (*Message) Get

func (m *Message) Get(db *gorm.DB) (*Message, error)

func (*Message) List

func (c *Message) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([]*Message, error)

func (*Message) Update

func (m *Message) Update(db *gorm.DB) error

type MessageFormated

type MessageFormated struct {
	ID             int64         `json:"id"`
	SenderUserID   int64         `json:"sender_user_id"`
	SenderUser     *UserFormated `json:"sender_user"`
	ReceiverUserID int64         `json:"receiver_user_id"`
	Type           MessageT      `json:"type"`
	Brief          string        `json:"brief"`
	Content        string        `json:"content"`
	PostID         int64         `json:"post_id"`
	Post           *PostFormated `json:"post"`
	CommentID      int64         `json:"comment_id"`
	Comment        *Comment      `json:"comment"`
	ReplyID        int64         `json:"reply_id"`
	Reply          *CommentReply `json:"reply"`
	IsRead         int8          `json:"is_read"`
	CreatedOn      int64         `json:"created_on"`
	ModifiedOn     int64         `json:"modified_on"`
}

type MessageT

type MessageT int8
const (
	MESSAGE_POST MessageT = iota + 1
	MESSAGE_COMMENT
	MESSAGE_REPLY
	MESSAGE_WHISPER
)
const MESSAGE_SYSTEM MessageT = 99

type Model

type Model struct {
	ID         int64                 `gorm:"primary_key" json:"id"`
	CreatedOn  int64                 `json:"created_on"`
	ModifiedOn int64                 `json:"modified_on"`
	DeletedOn  int64                 `json:"deleted_on"`
	IsDel      soft_delete.DeletedAt `gorm:"softDelete:flag" json:"is_del"`
}

公共Model

func (*Model) BeforeCreate

func (m *Model) BeforeCreate(tx *gorm.DB) (err error)

func (*Model) BeforeUpdate

func (m *Model) BeforeUpdate(tx *gorm.DB) (err error)

type Post

type Post struct {
	*Model
	UserID          int64  `json:"user_id"`
	CommentCount    int64  `json:"comment_count"`
	CollectionCount int64  `json:"collection_count"`
	UpvoteCount     int64  `json:"upvote_count"`
	IsTop           int    `json:"is_top"`
	IsEssence       int    `json:"is_essence"`
	IsLock          int    `json:"is_lock"`
	LatestRepliedOn int64  `json:"latest_replied_on"`
	Tags            string `json:"tags"`
	AttachmentPrice int64  `json:"attachment_price"`
	IP              string `json:"ip"`
	IPLoc           string `json:"ip_loc"`
}

func (*Post) Count

func (p *Post) Count(db *gorm.DB, conditions *ConditionsT) (int64, error)

func (*Post) Create

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

func (*Post) Delete

func (s *Post) Delete(db *gorm.DB) error

func (*Post) Format

func (p *Post) Format() *PostFormated

func (*Post) Get

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

func (*Post) List

func (p *Post) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([]*Post, error)

func (*Post) Update

func (p *Post) Update(db *gorm.DB) error

type PostAttachmentBill

type PostAttachmentBill struct {
	*Model
	PostID     int64 `json:"post_id"`
	UserID     int64 `json:"user_id"`
	PaidAmount int64 `json:"paid_amount"`
}

func (*PostAttachmentBill) Create

func (p *PostAttachmentBill) Create(db *gorm.DB) (*PostAttachmentBill, error)

func (*PostAttachmentBill) Get

type PostCollection

type PostCollection struct {
	*Model
	PostID int64 `json:"post_id"`
	UserID int64 `json:"user_id"`
}

func (*PostCollection) Count

func (p *PostCollection) Count(db *gorm.DB, conditions *ConditionsT) (int64, error)

func (*PostCollection) Create

func (p *PostCollection) Create(db *gorm.DB) (*PostCollection, error)

func (*PostCollection) Delete

func (p *PostCollection) Delete(db *gorm.DB) error

func (*PostCollection) Get

func (p *PostCollection) Get(db *gorm.DB) (*PostCollection, error)

func (*PostCollection) List

func (p *PostCollection) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([]*PostCollection, error)

type PostContent

type PostContent struct {
	*Model
	PostID  int64        `json:"post_id"`
	UserID  int64        `json:"user_id"`
	Content string       `json:"content"`
	Type    PostContentT `json:"type"`
	Sort    int64        `json:"sort"`
}

func (*PostContent) Create

func (p *PostContent) Create(db *gorm.DB) (*PostContent, error)

func (*PostContent) Format

func (p *PostContent) Format() *PostContentFormated

func (*PostContent) Get

func (p *PostContent) Get(db *gorm.DB) (*PostContent, error)

func (*PostContent) List

func (p *PostContent) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([]*PostContent, error)

type PostContentFormated

type PostContentFormated struct {
	ID      int64        `json:"id"`
	PostID  int64        `json:"post_id"`
	Content string       `json:"content"`
	Type    PostContentT `json:"type"`
	Sort    int64        `json:"sort"`
}

type PostContentT

type PostContentT int
const (
	CONTENT_TYPE_TITLE PostContentT = iota + 1
	CONTENT_TYPE_TEXT
	CONTENT_TYPE_IMAGE
	CONTENT_TYPE_VIDEO
	CONTENT_TYPE_AUDIO
	CONTENT_TYPE_LINK
	CONTENT_TYPE_ATTACHMENT
	CONTENT_TYPE_CHARGE_ATTACHMENT
)

type PostFormated

type PostFormated struct {
	ID              int64                  `json:"id"`
	UserID          int64                  `json:"user_id"`
	User            *UserFormated          `json:"user"`
	Contents        []*PostContentFormated `json:"contents"`
	CommentCount    int64                  `json:"comment_count"`
	CollectionCount int64                  `json:"collection_count"`
	UpvoteCount     int64                  `json:"upvote_count"`
	IsTop           int                    `json:"is_top"`
	IsEssence       int                    `json:"is_essence"`
	IsLock          int                    `json:"is_lock"`
	LatestRepliedOn int64                  `json:"latest_replied_on"`
	CreatedOn       int64                  `json:"created_on"`
	ModifiedOn      int64                  `json:"modified_on"`
	Tags            map[string]int8        `json:"tags"`
	AttachmentPrice int64                  `json:"attachment_price"`
	IPLoc           string                 `json:"ip_loc"`
}

type PostStar

type PostStar struct {
	*Model
	PostID int64 `json:"post_id"`
	UserID int64 `json:"user_id"`
}

func (*PostStar) Count

func (p *PostStar) Count(db *gorm.DB, conditions *ConditionsT) (int64, error)

func (*PostStar) Create

func (p *PostStar) Create(db *gorm.DB) (*PostStar, error)

func (*PostStar) Delete

func (p *PostStar) Delete(db *gorm.DB) error

func (*PostStar) Get

func (p *PostStar) Get(db *gorm.DB) (*PostStar, error)

func (*PostStar) List

func (p *PostStar) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([]*PostStar, error)

type Tag

type Tag struct {
	*Model
	UserID   int64  `json:"user_id"`
	Tag      string `json:"tag"`
	QuoteNum int64  `json:"quote_num"`
}

func (*Tag) Create

func (t *Tag) Create(db *gorm.DB) (*Tag, error)

func (*Tag) Format

func (t *Tag) Format() *TagFormated

func (*Tag) Get

func (t *Tag) Get(db *gorm.DB) (*Tag, error)

func (*Tag) List

func (t *Tag) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([]*Tag, error)

func (*Tag) Update

func (t *Tag) Update(db *gorm.DB) error

type TagFormated

type TagFormated struct {
	ID       int64         `json:"id"`
	UserID   int64         `json:"user_id"`
	User     *UserFormated `json:"user"`
	Tag      string        `json:"tag"`
	QuoteNum int64         `json:"quote_num"`
}

type User

type User struct {
	*Model
	Nickname string `json:"nickname"`
	Username string `json:"username"`
	Phone    string `json:"phone"`
	Password string `json:"password"`
	Salt     string `json:"salt"`
	Status   int    `json:"status"`
	Avatar   string `json:"avatar"`
	Balance  int64  `json:"balance"`
	IsAdmin  bool   `json:"is_admin"`
}

func (*User) Create

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

func (*User) Format

func (u *User) Format() *UserFormated

func (*User) Get

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

func (*User) List

func (u *User) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([]*User, error)

func (*User) Update

func (u *User) Update(db *gorm.DB) error

type UserFormated

type UserFormated struct {
	ID       int64  `json:"id"`
	Nickname string `json:"nickname"`
	Username string `json:"username"`
	Status   int    `json:"status"`
	Avatar   string `json:"avatar"`
	IsAdmin  bool   `json:"is_admin"`
}

type WalletRecharge

type WalletRecharge struct {
	*Model
	UserID      int64  `json:"user_id"`
	Amount      int64  `json:"amount"`
	TradeNo     string `json:"trade_no"`
	TradeStatus string `json:"trade_status"`
}

func (*WalletRecharge) Create

func (p *WalletRecharge) Create(db *gorm.DB) (*WalletRecharge, error)

func (*WalletRecharge) Get

func (p *WalletRecharge) Get(db *gorm.DB) (*WalletRecharge, error)

type WalletStatement

type WalletStatement struct {
	*Model
	UserID          int64  `json:"user_id"`
	ChangeAmount    int64  `json:"change_amount"`
	BalanceSnapshot int64  `json:"balance_snapshot"`
	Reason          string `json:"reason"`
	PostID          int64  `json:"post_id"`
}

func (*WalletStatement) Count

func (w *WalletStatement) Count(db *gorm.DB, conditions *ConditionsT) (int64, error)

func (*WalletStatement) Create

func (w *WalletStatement) Create(db *gorm.DB) (*WalletStatement, error)

func (*WalletStatement) Get

func (w *WalletStatement) Get(db *gorm.DB) (*WalletStatement, error)

func (*WalletStatement) List

func (w *WalletStatement) List(db *gorm.DB, conditions *ConditionsT, offset, limit int) ([]*WalletStatement, error)

Jump to

Keyboard shortcuts

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