models

package
v0.0.0-...-851e7b8 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DataRemoved means this data is flushed
	// 数据是否被删除
	//
	DataRemoved = 1
	// DataAvailable means this data is unflushed
	// 用于校验数据被删除的
	//
	DataAvailable = 0
)
View Source
const (
	// MomentTypePublic is define for public moment filed
	// 类型为公开
	MomentTypePublic = 0
	// MomentTypePrivate is defined for private moment filed
	// 类型为私有,仅自己可见的
	MomentTypePrivate = 1
	// MomentTypeOnly is defined that only available for people in users selection range
	// 类型为指定某个用户集合的
	MomentTypeOnly = 3
)
View Source
const (
	// NewsCateAvailable defined for casing if current new cate is available
	NewsCateAvailable = 1

	// NewsCateUnavailable defined for casing if current new cate is not available
	NewsCateUnavailable = 0
)
View Source
const (
	// NotificationTypeComment type for comment
	NotificationTypeComment int = 1

	// NotificationTypeAt type for ating some one
	NotificationTypeAt int = 2

	// NotificationTypeThumb type for getting thumb
	NotificationTypeThumb int = 3

	// NotificationTypeSystem type for system notification
	NotificationTypeSystem int = 0
)
View Source
const (
	// UserStatusNormal means user account is normally available
	UserStatusNormal int = 1
	// UserStatusBan means this account is baned and is not going to support any usage
	UserStatusBan int = 2
	// UserStatusProtected means account is under protection
	UserStatusProtected int = 3
	// UserStatusBanTemporary means account is baned in temporary situation
	UserStatusBanTemporary int = 4

	// UserTypePersonal is personal account
	UserTypePersonal int = 1
	// UserTypeCompany is company maintained account
	UserTypeCompany int = 2
	// UserTypeOrg is orgnizations maintained account
	UserTypeOrg int = 3
)
View Source
const (
	// UserRoleNormal defined for normal user
	UserRoleNormal = 1

	// UserRoleAdmin defined for admin user
	UserRoleAdmin = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicModel

type BasicModel struct {
	//
	// 默认作为主键
	// 自动增长的ID
	//
	//
	ID uint `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
	//
	// 创建时间
	CreatedAt time.Time `json:"create_at"`
	//
	// 更新时间
	UpdatedAt time.Time `json:"update_at"`
	//
	// 逻辑删除时间
	DeletedAt *time.Time `sql:"index" json:"delete_at"`
}

BasicModel is basic DB model struction

type BasicRemoveableModel

type BasicRemoveableModel struct {
	//
	// 默认作为主键
	// 自动增长的ID
	//
	//
	ID uint `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
	//
	// 创建时间
	CreatedAt time.Time `json:"create_at"`
	//
	// 更新时间
	UpdatedAt time.Time `json:"update_at"`
}

BasicRemoveableModel struct data can be removed from database

type Comment

type Comment struct {
	BasicRemoveableModel
	// 对应用户的id
	// 查询时将直接根据用户ID查询
	UID int `gorm:"TYPE:int(25);NOT NULL;" json:"-"`
	//
	// 数据存储时 MomentID,CommentID,NewsID 仅选择其一
	//
	// 关联的momentID
	//
	MomentID int `gorm:"TYPE:int;DEFAULT:NULL;" json:"moment_id"`
	//
	// 关联的资讯ID
	//
	NewsID int `gorm:"TYPE:int;DEFAULT:NULL;" json:"news_id"`
	//
	// 关联的资讯ID
	//
	CommentID int `gorm:"TYPE:int;DEFAULT:NULL;" json:"comment_id"`
	//
	// content 评论的内容
	//
	Content string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"content"`
	//
	// 用户个人资料外联表模型
	UsersProfiles UsersProfiles `gorm:"FOREIGNKEY:uid;AssociationForeignKey:uid;association_autoupdate:false;" json:"profile"`
}

Comment record thumb data

func (*Comment) Create

func (c *Comment) Create(commentModel *Comment) (*Comment, error)

Create will create a comment 创建新的评论

func (Comment) GetID

func (c Comment) GetID() int

GetID can get current filed id

func (*Comment) List

func (c *Comment) List(user *Users, sql string, targetID, rows, page int) (*[]Comment, int, error)

List is defined to list comments by giving target id 列出指定用户的id 该方法不得用于列出他人的动态 该方法未过滤 私人动态,所以不要用于罗列他人的动态 TODO: 媒体关联查询

func (*Comment) RemoveByID

func (c *Comment) RemoveByID(user *Users, id int) (bool, error)

RemoveByID is defined to remove a comment user usersModel id commentID

func (Comment) TableName

func (Comment) TableName() string

TableName is DB model table name

type Config

type Config struct {
	BasicRemoveableModel

	//
	// configration item name
	//
	Name string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"name"`
	//
	// configration item value
	//
	Value string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"value"`
}

Config required some bootstrapper configrations

func (Config) GetID

func (c Config) GetID() int

GetID can get current filed id

func (*Config) ListAllConfig

func (c *Config) ListAllConfig() (*[]Config, error)

ListAllConfig will generate all config filed Do not add any important information on this table, it's all public

func (Config) TableName

func (Config) TableName() string

TableName is current model table name

type Contact

type Contact struct {
	BasicRemoveableModel
	// who create this filed
	UID int `gorm:"TYPE:int(25);NOT NULL;" json:"uid"` //
	// relate a user with this contact filed
	FriendUID int `gorm:"TYPE:int(25);NOT NULL;" json:"friend_uid"` //
	// comment a target contact user name as user wanted
	Comment string `gorm:"TYPE:varchar(30);NOT NULL;" json:"comment"`
	// Black means this is a blocked user contact filed
	Black int `gorm:"TYPE:int(25);DEFAULT:0;" json:"black"`
	// 用户个人资料外联表模型
	UsersProfiles UsersProfiles `gorm:"FOREIGNKEY:FriendUID;AssociationForeignKey:id;association_autoupdate:false;" json:"profile"`
}

Contact Model

func (*Contact) BlackContact

func (c *Contact) BlackContact(user *Users, id, blackType int) (bool, error)

BlackContact will update black filed blackContact contact blackType 1 black, 0 normal

func (*Contact) CountFollow

func (c *Contact) CountFollow(user *Users) (int, error)

CountFollow return someones follower amounts uid user's ID

func (*Contact) CountFollowers

func (c *Contact) CountFollowers(user *Users) (int, error)

CountFollowers return someones follower amounts uid user's ID

func (*Contact) Create

func (c *Contact) Create(contact *Contact) (*Contact, error)

Create is defined to create a contact filed by giving contact model 创建新的关注或者拉黑记录(联系人记录)

func (*Contact) CreateContactComment

func (c *Contact) CreateContactComment(comment string, uid, id int) (bool, error)

CreateContactComment will update comment filed contact new contact

func (*Contact) FindRelations

func (c *Contact) FindRelations(user *Users, friendUID int) (*[]Contact, error)

FindRelations return boolean to tell user if target user is already followed uid usermodel

func (Contact) GetID

func (c Contact) GetID() int

GetID can get current filed id

func (*Contact) ListAllAvailable

func (c *Contact) ListAllAvailable(uid int) (*[]Contact, error)

ListAllAvailable my contact that available for messaging uid user's ID

func (*Contact) ListAllBlacks

func (c *Contact) ListAllBlacks(user *Users, rows, page int) (*[]Contact, int, error)

ListAllBlacks my blocked contact for messaging uid user's ID

func (*Contact) ListFollowers

func (c *Contact) ListFollowers(user *Users, rows, page int) (*[]Contact, int, error)

ListFollowers return your fans uid user's ID

func (*Contact) Remove

func (c *Contact) Remove(user *Users, id int) (bool, error)

Remove a contact user removeContact contact

func (Contact) TableName

func (Contact) TableName() string

TableName is table name for DB model

type FeedBack

type FeedBack struct {
	BasicModel
	//
	// UID 是反馈用户的UID
	// 由于可以匿名反馈,所以用户的UID可以不填写
	UID int `gorm:"TYPE:int(25);DEFAULT:0;" json:"uid"`

	//
	// 反馈的内容
	//
	Comment string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"comment"`

	//
	// 当前的状态
	//
	Status int `gorm:"type:int(25);DEFAULT: 0" json:"status"` /** 0 未处理 1 已处理 */
	//
	// 进行处理的时间
	// 也就是工作人员确定已经给用户反馈的时间
	ProcessDate string `gorm:"TYPE:datetime;DEFAULT:NULL;" json:"process_date"`
}

FeedBack is DB feedback information model

func (*FeedBack) Create

func (f *FeedBack) Create(fd *FeedBack) (*FeedBack, error)

Create is defined to create a feedback information 创建反馈信息

func (FeedBack) TableName

func (FeedBack) TableName() string

TableName is current model table name

type Media

type Media struct {
	BasicModel
	// UID is users id
	// MEDIA的文件将从MEDIA_FILES关联查询
	//
	// 用户id
	//
	UID int `gorm:"TYPE:int(25);NOT NULL" json:"-"`

	// MeidaFiles is media files information
	//
	// 关联查询媒体
	// 从mediaFiles查询
	MeidaFiles *[]MediaFiles `gorm:"FOREIGNKEY:media_id;AssociationForeignKey:id;association_autoupdate:false;" json:"media_files"`
}

Media is defined as db media model

func (*Media) Create

func (m *Media) Create(media *Media) (*Media, error)

Create a media 创建一个新的媒体

func (Media) GetID

func (m Media) GetID() int

GetID can get current filed id

func (*Media) Remove

func (m *Media) Remove(user *Users, id int) (bool, error)

Remove a media

func (Media) TableName

func (Media) TableName() string

TableName is DB model table name

type MediaFiles

type MediaFiles struct {
	BasicModel
	//
	// MEDIA的文件将从MEDIA_FILES关联查询
	//
	// 用户id
	//
	UID int `gorm:"TYPE:int(25);NOT NULL" json:"uid"`
	//
	// MEDIA关联ID
	// 默认不能为空
	//
	MediaID int `gorm:"TYPE:int(25);NOT NULL" json:"media_id"`
	//
	// Header
	// 文件头
	//
	ContentType string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"content_type"`
	//
	// Size
	// 文件大小
	//
	Size int64 `gorm:"TYPE:int;DEFAULT:NULL;" json:"size"`
	//
	// Comment
	// 备注文件
	//
	Comment string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"comment"`
	//
	// file path(key)
	// file path not contants protocol and host
	// path should be same as oss storage key
	//
	Key string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"key"`
}

MediaFiles is media file DB model

func (*MediaFiles) Create

func (m *MediaFiles) Create(Mediafiles *MediaFiles) (*MediaFiles, error)

Create a MediaFiles 创建一个新的媒体

func (MediaFiles) GetID

func (m MediaFiles) GetID() int

GetID can get current filed id

func (*MediaFiles) RemoveByMediaID

func (m *MediaFiles) RemoveByMediaID(user *Users, mediaID int) (bool, error)

RemoveByMediaID will remove a mediaFile record by giving media_id

func (MediaFiles) TableName

func (MediaFiles) TableName() string

TableName is current model table name

type Moment

type Moment struct {
	BasicModel
	//
	// 用户id
	//
	UID int `gorm:"TYPE:int;NOT NULL" json:"-"`
	//
	// 类型
	// 类型指的是动态类型
	// 用户的动态分为 0 公开的,1私有的,2指定的,默认为0 即Public
	//
	Type int `gorm:"TYPE:int(2);DEFAULT:0;" json:"type"`
	//
	// 文字信息
	// 文字信息最长不得超过280个
	// 活在280个字节的世界里挺好
	//
	Context string `gorm:"TYPE:text(280);DEFAULT:NULL;" json:"context"`
	//
	// 关联媒体
	// 媒体ID会在查询的时候一并查询出来
	// 通常媒体信息可能为图片,视频,等,具体根据媒体模型判定
	//
	MediaID int `gorm:"TYPE:int;DEFAULT:null;" json:"media_id"`
	//
	//
	// 发送的地理位置(可选)
	// 为经纬度合集 正确格式:41.40338,2.17403
	// 其他格式都不能入库,这个在控制器数据入库的时候会进行过滤检查
	// 默认为NULL
	//
	LocationDegrees string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"location_degree"`
	//
	// 地理位置Text(即定位位置的名称,仅当前位置,而非完整的精确的 国省市 例如: 北京奥利匹克体育中心)
	//
	LocationText string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"location_text"`
	//
	// 关联的momentID
	//
	MomentID int `gorm:"TYPE:int;DEFAULT:NULL;" json:"momentID"`
	//
	// Views 动态查看次数
	//
	Views int `gorm:"TYPE:int;DEFAULT:0;" json:"views"` //当用户拉取动态详情,第一页时,对views进行计次更新
	//
	//
	// 用户个人资料外联表模型
	//
	UsersProfiles UsersProfiles `gorm:"FOREIGNKEY:uid;AssociationForeignKey:uid;association_autoupdate:false;" json:"profile"`
}

Moment is DB moment model

func (*Moment) AfterFind

func (m *Moment) AfterFind() (err error)

AfterFind 是钩子函数,每次取moment时views将被自动增加1次

func (*Moment) CountByMediaID

func (m *Moment) CountByMediaID(user *Users, mediaID int) (int, error)

CountByMediaID return a moment

func (*Moment) CountMine

func (m *Moment) CountMine(user *Users) (int, error)

CountMine returns my moment amount

func (*Moment) Create

func (m *Moment) Create(moments *Moment) (*Moment, error)

Create is defined to create a moment filed by giving moment model moments is moment model 创建新的动态

func (*Moment) FindMomentByKeyword

func (m *Moment) FindMomentByKeyword(keyword string, rows, page int) (*[]Moment, int, error)

FindMomentByKeyword will return moments

func (Moment) GetID

func (m Moment) GetID() int

GetID can get current filed id

func (*Moment) GetbyID

func (m *Moment) GetbyID(user *Users, momentID int) (*Moment, error)

GetbyID return a moment

func (*Moment) ListAllMine

func (m *Moment) ListAllMine(user *Users, rows, page int) (*[]Moment, int, error)

ListAllMine is defined to list my moment fileds 列出指定用户的id 该方法不得用于列出他人的动态 该方法未过滤 私人动态,所以不要用于罗列他人的动态 TODO: 媒体关联查询

func (*Moment) ListAllOthers

func (m *Moment) ListAllOthers(user *Users, rows, page int) (*[]Moment, error)

ListAllOthers is defined to list someone's moment fileds 列出别人的动态 TODO: 媒体关联查询

func (*Moment) ListNew

func (m *Moment) ListNew(user *Users, rows, page int) (*[]Moment, int, error)

ListNew is defined to list new moments 列出指定用户的id 该方法不得用于列出他人的动态 该方法未过滤 私人动态,所以不要用于罗列他人的动态 TODO: 限制查询范围

func (*Moment) Remove

func (m *Moment) Remove(user *Users, id uint) (bool, error)

Remove is defined to remove a moment filed 删除某条动态 动态删除后,将依旧被存档 动态将由系统在删除时间后的第60天进行物理删除(具体天数,请根据系统事务配置进行修改) 在使用该方法的时候千万要检验用户登录使用用户登录的UID进行删除请求,否则将导致安全隐患 Delete对于使用了BasicModel的数据仅进行软删除

func (Moment) TableName

func (Moment) TableName() string

TableName is DB model table name

func (*Moment) UpdateViewsbyID

func (m *Moment) UpdateViewsbyID(moment *Moment) (*Moment, error)

UpdateViewsbyID update views

type News

type News struct {
	BasicModel

	// add by user
	AddBy int `gorm:"TYPE:int(25);NOT NULL" json:"-"`

	// category Id, should nerver be null
	// news will not be publish if category id equals null
	CategoryID int `gorm:"TYPE:int(25);" json:"category_id"`

	// title
	Title string `gorm:"TYPE:varchar(25);DEFAULT:''" json:"title"` // news title

	// content
	Content string `gorm:"TYPE:text;DEFAULT:NULL;" json:"content"`

	// sourceUri
	// news from which website
	SourceURI string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"source_uri"`

	// author
	// original author information
	Author string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"author"`

	// mark this news could support any comment
	// if equals 0, all comments will not be saved and display
	CommentAvailable string `gorm:"TYPE:int(25);DEFAULT:'1'" json:"comment_available"` // news title

	// news will be expired at
	// default is null, this filed can be null
	ExpireAt string `gorm:"TYPE:datetime;DEFAULT:NULL;" json:"expire_at"`
}

News is defined for news basic model

func (News) GetID

func (n News) GetID() int

GetID can get current filed id

func (News) TableName

func (News) TableName() string

TableName is DB model table name

type NewsCates

type NewsCates struct {
	BasicRemoveableModel

	// 对应用户的id
	// 查询时将直接根据用户ID查询
	// 该分类添加的用户
	AddBy int `gorm:"TYPE:int(25);NOT NULL" json:"-"`

	// parent category Id
	// null means this category is first level category
	ParentID int `gorm:"TYPE:int(25);DEFAULT:'0'" json:"parent_id"`

	// category name
	Name string `gorm:"TYPE:varchar(25);DEFAULT:'';UNIQUE" json:"name"`

	// category theme color
	ThemeColor string `gorm:"TYPE:varchar(25);DEFAULT:'default'" json:"theme-color"`

	// when status equals 1, this category will be available, 2 should hide and forbid to add any news
	Status int `gorm:"TYPE:int(25);NOT NULL;DEFAULT:'1'" json:"status"`
}

NewsCates defined for new categories

func (*NewsCates) Create

func (n *NewsCates) Create(cate *NewsCates) (*NewsCates, error)

Create is defined to create a Category cate is NewsCates

func (NewsCates) GetID

func (n NewsCates) GetID() int

GetID can get current filed id

func (*NewsCates) ListAll

func (n *NewsCates) ListAll() (*[]NewsCates, error)

ListAll will return all available new categoriess

func (NewsCates) TableName

func (NewsCates) TableName() string

TableName is DB model table name

type Notification

type Notification struct {
	BasicRemoveableModel

	// 通知
	// 评论1 AT2 点赞3 系统0
	Type int `gorm:"TYPE:int(25);DEFAULT:0;" json:"type"`
	//
	// 对应用户的id
	// 查询时将直接根据用户ID查询
	//
	UID int `gorm:"TYPE:int(25);DEFAULT:NULL;" json:"-"`
	//
	// 是否未读
	// 1为已读,0为未读
	//
	Unread int `gorm:"TYPE:int(25);NOT NULL;DEFAULT:1;" json:"unread"`
	//
	// 评论ID
	//
	CommentID uint `gorm:"TYPE:int;DEFAULT:NULL;" json:"comment_id"`
	//
	// 动态ID
	//
	MomentID uint `gorm:"TYPE:int;DEFAULT:NULL;" json:"moment_id"`
	//
	// 关联的资讯ID
	//
	NewsID uint `gorm:"TYPE:int;DEFAULT:NULL;" json:"news_id"`
	//
	// 描述
	// 通知描述
	//
	Description string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"description"`
	//
	// 关联动态
	Moment Moment `gorm:"association_jointable_foreignkey:moment_id;" json:"moment"`
	//
	// 关联资讯
	News News `gorm:"association_jointable_foreignkey:news_id;" json:"news"`
	//
	// 关联评论
	Comment Comment `gorm:"association_jointable_foreignkey:comment_id;" json:"comment"`
}

Notification defined for Notification model

func (*Notification) Create

func (n *Notification) Create(notificationModel *Notification) (*Notification, error)

Create a Notification 创建一个新的通知 创建消息的模型包含一些逻辑检查,避免创建脏数据

func (Notification) GetID

func (n Notification) GetID() int

GetID can get current filed id

func (*Notification) Mark

func (n *Notification) Mark(user *Users, ids []int, unread int) error

Mark a notification by giving notification ids ids: []int{10, 11}

func (*Notification) MyNotifications

func (n *Notification) MyNotifications(user *Users, notificationType, rows, page int) (*[]Notification, int, error)

MyNotifications will return my notifications by giving notification type

func (*Notification) Remove

func (n *Notification) Remove(user *Users, id uint) (bool, error)

Remove a Notification 删除通知

func (Notification) TableName

func (Notification) TableName() string

TableName is DB model table name

type ReportModel

type ReportModel struct {
	BasicRemoveableModel

	// report by uid
	// reporter should login to add reports
	ReportedBy int `gorm:"TYPE:int(25);NOT NULL" json:"-"`

	// commentID
	CommentID int `gorm:"TYPE:int(25);DEFAULT:NULL" json:"comment_id"`

	// newsID
	NewsID int `gorm:"TYPE:int(25);DEFAULT:NULL" json:"news_id"`

	// newsCommentID
	NewsCommentID int `gorm:"TYPE:int(25);DEFAULT:NULL" json:"news_comment_id"`

	// newsID
	MomentID int `gorm:"TYPE:int(25);DEFAULT:NULL" json:"moment_id"`

	// report reason
	Reason string `gorm:"TYPE:text;DEFAULT:NULL;" json:"reason"`

	// 用户个人资料外联表模型
	UsersProfiles UsersProfiles `gorm:"FOREIGNKEY:uid;AssociationForeignKey:reported_by;association_autoupdate:false;" json:"profile"`
}

ReportModel defined for reports

func (*ReportModel) Create

func (r *ReportModel) Create(report *ReportModel) (*ReportModel, error)

Create is defined to create a report report is ReportModel

func (ReportModel) GetID

func (r ReportModel) GetID() int

GetID can get current filed id

func (ReportModel) TableName

func (ReportModel) TableName() string

TableName is DB model table name

type ResponseModel

type ResponseModel struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

ResponseModel is defined for http response data model

type SecurityPasswordModel

type SecurityPasswordModel struct {
	BasicModel
	//
	// 对应用户的id
	// 查询时将直接根据用户ID查询
	//
	UID int `gorm:"TYPE:int(25);NOT NULL;UNIQUE" json:"uid"`
	//
	// 支付密码
	// 支付密码算法 md5(md5(password).salt)
	// 默认为null
	//
	Password string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"-"`
	//
	// salt
	//
	Salt string `gorm:"TYPE:varchar(25);DEFAULT:NULL;" json:"-"`
	//
	// 支付密码状态
	// 该状态仅在用户交易时进行识别验证
	//
	// 通常情况下,如果账户被冻结,但是支付密码不会被冻结,因为需要为用户提供单独的资产渠道
	// 但部分用户,可能存在违规操作,为了规避风险 要做到既冻结账号,又冻结支付密码
	//
	// 1 正常
	// 2 受限制的,即不能交易,但可以通过更新后再进行交易
	// 3 永久性冻结支付密码的 无法交易 无法提取账户资产 无法更改
	//
	Status string `gorm:"TYPE:varchar(255);DEFAULT:1;" json:"status"`
}

SecurityPasswordModel is DB model for security password storage Security Password 是用来二次校验账户操作安全性的密码

类似支付密码,凡是涉及财产操作的,都需要设置 默认下不会自动创建,所以校验支付密码前,需要检测用户是否创建了支付密码 前端应当自行记录查询是否设置支付密码 并保存查询设置状态减少查询压力

func (SecurityPasswordModel) GetID

func (s SecurityPasswordModel) GetID() int

GetID can get current filed id

func (SecurityPasswordModel) TableName

func (SecurityPasswordModel) TableName() string

TableName is DB model table name

type Thumb

type Thumb struct {
	BasicRemoveableModel
	// 点赞的人UID
	// 记录点赞人的UID
	ThumbBy int `gorm:"TYPE:int(25);NOT NULL;" json:"thumbBy"`
	//
	// 数据存储时 MomentID,CommentID,NewsID 仅选择其一
	//
	// 关联的momentID
	//
	MomentID int `gorm:"TYPE:int;DEFAULT:NULL;" json:"moment_id"`
	//
	// 关联的评论ID
	//
	CommentID int `gorm:"TYPE:int;DEFAULT:NULL;" json:"comment_id"`
	//
	// 关联的资讯ID
	//
	NewsID int `gorm:"TYPE:int;DEFAULT:NULL;" json:"news_id"`
	//
	// 用户个人资料外联表模型
	UsersProfiles UsersProfiles `gorm:"FOREIGNKEY:thumb_by;AssociationForeignKey:uid;association_autoupdate:false;" json:"profile"`
}

Thumb record thumb data

func (*Thumb) CountMoment

func (t *Thumb) CountMoment(momentID int) (int, *[]Thumb, error)

CountMoment all Thumb for a moment

func (*Thumb) Create

func (t *Thumb) Create(thumb *Thumb) (*Thumb, error)

Create is defined to create a thumb filed by giving thumb model 创建新的点赞记录

func (*Thumb) FindUserCommentsThumbByID

func (t *Thumb) FindUserCommentsThumbByID(user *Users, id int) (*[]Thumb, error)

FindUserCommentsThumbByID will return thumbs

func (*Thumb) FindUserMomentsThumbByID

func (t *Thumb) FindUserMomentsThumbByID(user *Users, id int) (*[]Thumb, error)

FindUserMomentsThumbByID will return thumbs

func (*Thumb) FindUserNewsThumbByID

func (t *Thumb) FindUserNewsThumbByID(user *Users, id int) (*[]Thumb, error)

FindUserNewsThumbByID will return thumbs

func (Thumb) GetID

func (t Thumb) GetID() int

GetID can get current filed id

func (*Thumb) RemoveByID

func (t *Thumb) RemoveByID(user *Users, id int) (bool, error)

RemoveByID is defined to remove a thumb filed user usersModel id thumbId

func (Thumb) TableName

func (Thumb) TableName() string

TableName is DB model table name

type UserRoleGroup

type UserRoleGroup struct{}

UserRoleGroup defined for user role management

type Users

type Users struct {
	BasicModel
	// 账户类型
	// 账户类型分为 1 普通账户 2企业账户 3 组织或者机关单位
	Type int `gorm:"TYPE:int(25);DEFAULT:1;" json:"type"` // 0 personal 1 company 2 org

	// 是否为子账户
	// parent id如果指定了id,那么这个账号即属于二级账户
	// 默认为 NULL
	Parent int `gorm:"TYPE:int(25);DEFAULT:NULL;" json:"parent"`

	// 组织或者企业名称
	// 个人账户为NULL
	//
	// 不作为真实性验证的依据,仅作为用户注册时填写的依据
	// 组织名称不要输出,防止前端憨逼一样的用了这个字段,嘻嘻嘻嘻
	//
	Orgname string `gorm:"TYPE:varchar(100);DEFAULT:NULL;" json:"-"`

	// 用户名
	// 用户名是登录依据
	// 用户名唯一不重复
	// 用户名不得更新
	//
	// 请不要将个人资料中的nic与username混淆
	Username string `gorm:"TYPE:varchar(20);UNIQUE;" json:"username"`

	// 邮箱
	// 电子邮箱仅注册或者第三方授权登录时更新,不作为真实性验证依据
	//
	// 境外用户注册时,邮箱作为注册条件
	// 境外用户登录时,邮箱作为登录的条件
	// 邮箱是否可以登录,与countryCode有绑定关系
	Email string `gorm:"TYPE:varchar(100);DEFAULT:NULL;" json:"email"`

	// 手机号,境外用户注册不强制填写手机号
	Mobile string `gorm:"TYPE:varchar(25);UNIQUE;" json:"mobile"`

	// 国家代码 ISO标准
	CountryCode string `gorm:"TYPE:varchar(25);DEFAULT:'CN';" json:"country_code"` //defualt china CN

	// 语言代码 ISO标准
	Language string `gorm:"TYPE:varchar(25);DEFAULT:'zh-CN';" json:"language"` //defualt china zh-CN

	//
	// 电话区号
	// 电话区号前面不加0 如中国 86
	// 电话区号不加86
	// 电话区号不得更新,不得作为用户可以选择更新的选项
	CallingCode string `gorm:"TYPE:varchar(25);DEFAULT:86;" json:"calling_code"` // default china 86

	// 登录密码 md5 登录密码算法为md5(md5(password).salt)
	Password string `gorm:"TYPE:varchar(255);NOT NULL;" json:"-"`

	// 加盐
	Salt string `gorm:"TYPE:varchar(25);NOT NULL;" json:"-"`

	//
	// 用户组
	// 0 为管理用户
	// 1为普通用户
	// 其他根据后续自定义
	Group int `gorm:"TYPE:int(25);DEFAULT:1;" json:"group"` // 2 admin 1 normal ...

	// 账户状态
	//
	// 账户如果封禁时禁止登录操作,并强制清除jwt token强制下线
	// 1为正常
	// 2禁止
	// 3账户被系统保护
	// 4短时间冻结
	Status int `gorm:"TYPE:int(25);DEFAULT:1;" json:"status"` // 1 normal 2 ban 3 protected

	//
	//账户解禁的日期
	//
	ReverseDate time.Time `gorm:"TYPE:datetime;DEFAULT:NULL;" json:"reverse_date"` // 1 normal 2 ban 3 protected

	// 用户个人资料外联表模型
	UsersProfiles UsersProfiles `gorm:"FOREIGNKEY:UID;AssociationForeignKey:id;association_autoupdate:false;" json:"profile"`
}

Users is DB model for user

func (*Users) Create

func (u *Users) Create(user *Users) (*Users, error)

Create is defined to create a user user is users model 创建手机登录的临时账户 手机登录的临时账户随机生成用户名,生成规则支持匹配 如果生成的用户名不匹配会导致调用正式注册接口时,用户信息复发更改

func (*Users) FindUsers

func (u *Users) FindUsers(keyword string, rows, page int) (*[]Users, int, error)

FindUsers is get users by keyword todo: 增加关联搜索nic

func (*Users) GetByID

func (u *Users) GetByID(UID string) (*Users, error)

GetByID is defined to get a user by id UID user's is

根据用户的ID查询用户的信息

安全性提示 这个方法不得作为接口发布信息的方法 该方法如果在接口中直接输出,将导致个人信息泄露 此处将预加载用户个人资料

func (*Users) GetByMobile

func (u *Users) GetByMobile(mobile string) (*Users, error)

GetByMobile is defined to get user by mobile string mobile is users mobile phone number 根据手机号查询用户信息 安全性提示 这个方法不得作为接口发布信息的方法 该方法如果在接口中直接输出,将导致个人信息泄露

func (*Users) GetByUsername

func (u *Users) GetByUsername(username string) (*Users, error)

GetByUsername is get a user by username string username is specificated username 根据用户名查询用户信息 安全性提示 这个方法不得作为接口发布信息的方法 该方法如果在接口中直接输出,将导致个人信息泄露

func (Users) GetID

func (u Users) GetID() int

GetID can get current filed id

func (*Users) IsAvailableType

func (u *Users) IsAvailableType(typeNum int) bool

IsAvailableType will check account type is available 检测账户类型是否可用

func (*Users) IsTemporaryUsername

func (u *Users) IsTemporaryUsername(username string) bool

IsTemporaryUsername is defined to check if user name is temporary username 检测用户名是否属于临时用户名

func (*Users) MapStatusText

func (u *Users) MapStatusText(statusCode int) string

MapStatusText will return a status char for current account statusCode is users status 匹配账户状态文本 1为正常 2禁止 3账户被系统保护 4短时间冻结

func (Users) TableName

func (Users) TableName() string

TableName is table name for DB model

func (*Users) UpdateByColumn

func (u *Users) UpdateByColumn(user *Users, column string, value interface{}) error

UpdateByColumn is defined to update user information by columns specified user is users model 更新用户信息 仅更新指定字段 更新时同时更新updateTime

type UsersProfiles

type UsersProfiles struct {
	BasicModel
	// 对应用户的id
	// 查询时将直接根据用户ID查询
	UID int `gorm:"TYPE:int(25);NOT NULL;UNIQUE" json:"uid"`
	//
	// 存储头像地址
	// 默认为null
	Avatar string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"avatar"`
	// 昵称,与用户名不同,用户昵称可以随时修改,并且可以在库中重复
	Nic string `gorm:"TYPE:varchar(25);DEFAULT:NULL;" json:"nic"`
	// 性别 目前暂定 male,famle, other,
	// 后续需要计划增加性别列表,因为性别选项应该有更多
	Gender string `gorm:"TYPE:varchar(25);DEFAULT:'male';" json:"gender"` // male female others
	// 生日
	// 出生年月日,datetime
	Birthday string `gorm:"TYPE:datetime;DEFAULT:NULL;" json:"birthday"`
	// 个性签名
	Bio string `gorm:"TYPE:varchar(255);DEFAULT:NULL;" json:"bio"`
	// 保护我的内容
	Protected int `gorm:"TYPE:int;NOT NULL;DEFAULT:0;" json:"protected"`
}

UsersProfiles is DB model for user's profile profile模型中,不应当存储任何敏感的个人信息,因为这些信息都会被接口直接公开

func (*UsersProfiles) Create

func (p *UsersProfiles) Create(u *UsersProfiles) (*UsersProfiles, error)

Create is defined to create a profile filed

注意,UID一定要和 用户表的ID进行关联 非常重要 该方法仅推荐用来创建一个空的档案,在用户注册时。其他时候只允许更新,不允许使用接口单独创建

func (*UsersProfiles) GetByUID

func (p *UsersProfiles) GetByUID(UID string) (*UsersProfiles, error)

GetByUID is defined to get a profile filed by giving user's id 使用UID查询数据库中的个人资料项目 如果更新了模型,请注意过滤敏感信息,这些信息都是开放到任意查询级别的!

func (UsersProfiles) GetID

func (p UsersProfiles) GetID() int

GetID can get current filed id

func (UsersProfiles) TableName

func (UsersProfiles) TableName() string

TableName is DB model table name

func (*UsersProfiles) Update

func (p *UsersProfiles) Update(profile *UsersProfiles, data map[string]interface{}) error

Update is defined to update user information by columns specified user is users model 更新用户信息 仅更新指定字段 更新时同时更新updateTime

func (*UsersProfiles) UpdateByColumn

func (p *UsersProfiles) UpdateByColumn(profile *UsersProfiles, column string, value interface{}) error

UpdateByColumn is defined to update user information by columns specified user is users model 更新用户信息 仅更新指定字段 更新时同时更新updateTime

Jump to

Keyboard shortcuts

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