user

package
v0.0.0-...-73ddb9c Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptFriendApply

func AcceptFriendApply(db *gorm.DB, applyID int64, userID int64, alias string) error

AcceptFriendApply 接受一个待确定的好友申请, alias 表示接受者给申请人的备注

func CreateFriendEntry

func CreateFriendEntry(db *gorm.DB, selfID int64, friendID int64, alias string) error

CreateFriendEntry 创建一个单向好友列表项目

`alias` 可以为 empty string

func DeleteFriendEntry

func DeleteFriendEntry(db *gorm.DB, entry *FriendEntry) error

DeleteFriendEntry 删除一个单项好友项目

func DeleteFriendEntryBi

func DeleteFriendEntryBi(db *gorm.DB, userID1 int64, userID2 int64) error

DeleteFriendEntryBi 双向删除好友

func DeleteFriendEntryByID

func DeleteFriendEntryByID(db *gorm.DB, entryID int64) error

DeleteFriendEntryByID 删除一个单项好友项目

func DeleteUser

func DeleteUser(db *gorm.DB, userID int64) error

DeleteUser 软删除一个用户,带 cascade

func GetUserCount

func GetUserCount(db *gorm.DB) (int64, error)

GetUserCount 获得当前所有的用户数量

func RejectFriendApply

func RejectFriendApply(db *gorm.DB, applyID int64, userID int64) error

RejectFriendApply 拒绝一个待确定的好友申请

Types

type FriendApply

type FriendApply struct {
	ID     int64 `gorm:"primarykey" json:"id"`
	FromID int64 `gorm:"type:bigint not null;index:idx_from;" json:"from_id"`
	ToID   int64 `gorm:"type:bigint not null;index:idx_to;" json:"to_id"`
	// Alias 表示申请人给接受者预设的备注
	Alias string `gorm:"type:varChar(127) not null" json:"alias"`
	// Remark
	Remark string           `gorm:"type:varChar(255) not null" json:"remark"`
	State  FriendApplyState `gorm:"type:smallint not null;check:state >= -1 and state <= 1" json:"state"`

	CreatedAt time.Time             `json:"created_at"`
	UpdatedAt time.Time             `json:"updated_at"`
	DeletedAt soft_delete.DeletedAt `gorm:"index" json:"deleted_at"`
}

FriendApply 好友申请项的 dao

func CreateFriendApply

func CreateFriendApply(db *gorm.DB, fromID int64, toID int64, alias string, remark string) (*FriendApply, error)

CreateFriendApply 创建一个新的待确定的好友申请 alias 表示发送者给接受者的预设备注

func GetFriendApplyByID

func GetFriendApplyByID(db *gorm.DB, applyID int64) (*FriendApply, error)

GetFriendApplyByID 根据 id 获取好友申请

func GetFriendApplyFromByUserID

func GetFriendApplyFromByUserID(db *gorm.DB, userID int64) ([]FriendApply, error)

GetFriendApplyFromByUserID 获得用户自己发送的好友申请列表

func GetFriendApplyToByUserID

func GetFriendApplyToByUserID(db *gorm.DB, userID int64) ([]FriendApply, error)

GetFriendApplyToByUserID 获得用户收到的好友申请列表

func GetUncertainFriendApply

func GetUncertainFriendApply(db *gorm.DB, fromID int64, toID int64) (*FriendApply, error)

GetUncertainFriendApply 获取一个待确定的好友申请

type FriendApplyState

type FriendApplyState int64
const (
	StateReject    FriendApplyState = -1
	StateUncertain FriendApplyState = 0
	StateAccept    FriendApplyState = 1
)

type FriendEntry

type FriendEntry struct {
	ID       int64  `gorm:"primarykey" json:"id"`
	SelfID   int64  `gorm:"uniqueIndex:idx_composited_id;index:idx_self" json:"self_id"`
	FriendID int64  `gorm:"uniqueIndex:idx_composited_id;index:idx_friend" json:"friend_id"`
	Alias    string `gorm:"type:varChar(127) not null" json:"alias"`

	CreatedAt time.Time             `json:"created_at"`
	UpdatedAt time.Time             `json:"updated_at"`
	DeletedAt soft_delete.DeletedAt `gorm:"uniqueIndex:idx_composited_id" json:"deleted_at"`
}

FriendEntry 好友列表项的 dao

func GetFriendEntry

func GetFriendEntry(db *gorm.DB, selfID int64, friendID int64) (*FriendEntry, error)

GetFriendEntry 查找两个好友

func GetFriendEntrySelfByUserID

func GetFriendEntrySelfByUserID(db *gorm.DB, userID int64) ([]FriendEntry, error)

GetFriendEntrySelfByUserID 获得用户自己的好友列表

func ModifyFriendEntryAlias

func ModifyFriendEntryAlias(db *gorm.DB, selfID int64, friendID int64, newAlias string) (*FriendEntry, error)

ModifyFriendEntryAlias 修改好友备注名

type Meta

type Meta struct {
}

Meta 额外的用户信息

type User

type User struct {
	ID int64 `gorm:"primarykey" json:"id"`

	NickName string `gorm:"type:varChar(255) not null" json:"nickname"`
	Email    string `gorm:"type:varChar(255) not null" json:"email"`
	Mobile   string `gorm:"type:varChar(31) not null;uniqueIndex:idx_mobile" json:"mobile"`
	Avatar   string `gorm:"type:varChar(255) not null" json:"avatar"`
	Bio      string `gorm:"type:text not null" json:"bio"`
	Password string `gorm:"type:text not null" json:"-"`

	AllowSearchByName  bool `gorm:"type:boolean not null;default:true" json:"allow_search_by_name"`
	AllowShowPhone     bool `gorm:"type:boolean not null;default:true" json:"allow_show_phone"`
	AllowSearchByPhone bool `gorm:"type:boolean not null;default:true" json:"allow_search_by_phone"`
	Meta
	// 好友列表项(自己拥有的好友)
	FriendEntrySelf []FriendEntry `gorm:"foreignKey:SelfID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"`
	// 好友列表项(自己作为其他人的好友)
	FriendEntryFriend []FriendEntry `gorm:"foreignKey:FriendID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"`
	// 好友申请项(自己发出)
	FriendApplyFrom []FriendApply `gorm:"foreignKey:FromID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"`
	// 好友申请项(自己接收)
	FriendApplyTo []FriendApply `gorm:"foreignKey:ToID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"`

	CreatedAt time.Time             `json:"created_at"`
	UpdatedAt time.Time             `json:"updated_at"`
	DeletedAt soft_delete.DeletedAt `gorm:"uniqueIndex:idx_mobile" json:"deleted_at"`
}

User 用户的 dao

func CreateUser

func CreateUser(db *gorm.DB, user *User) (*User, error)

CreateUser 创建一个新用户

func GetUserByID

func GetUserByID(db *gorm.DB, userID int64) (*User, error)

GetUserByID 通过 UserID 查找一个用户

Throw: gorm.ErrRecordNotFound

func GetUserByMobile

func GetUserByMobile(db *gorm.DB, mobile string) (*User, error)

GetUserByMobile 通过 Mobile 查找一个用户

Throw: gorm.ErrRecordNotFound

func GetUserLikeNickName

func GetUserLikeNickName(db *gorm.DB, nickName string) ([]User, error)

GetUserLikeNickName 根据模糊搜索寻找用户

func GetUserLikeNickNameWithOffsetAndLimit

func GetUserLikeNickNameWithOffsetAndLimit(db *gorm.DB, nickName string, offset int64, limit int64) ([]User, error)

GetUserLikeNickNameWithOffsetAndLimit 根据模糊搜索寻找用户,带分页

func (*User) UpdateFrom

func (user *User) UpdateFrom(db *gorm.DB) error

UpdateFrom 根据主键,从数据库中获取数据

func (*User) UpdateTo

func (user *User) UpdateTo(db *gorm.DB) error

UpdateTo 根据主键,写入到数据库

Jump to

Keyboard shortcuts

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