models

package
v0.0.0-...-27cccc6 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderTime  = "time"
	OrderScore = "score"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiPostDetail

type ApiPostDetail struct {
	AuthorName       string             `json:"author_id"` // 用户名
	VoteNum          int64              `json:"vote_num"`  // 票数
	*Post                               // 嵌入帖子结构体
	*CommunityDetail `json:"community"` // 嵌入社区信息结构体
}

ApiPostDetail 帖子详情接口结构体 因为在帖子详情中我们返回给前端的信息中是author_id,前段希望拿到的是作者的名字 这样才可以进行渲染

type Community

type Community struct {
	ID   int64  `json:"id" db:"community_id"`     // 社区ID
	Name string `json:"name" db:"community_name"` // 社区名
}

Community 社区类别

type CommunityDetail

type CommunityDetail struct {
	ID           int64     `json:"id" db:"community_id"`
	Name         string    `json:"name" db:"community_name"`
	Introduction string    `json:"introduction,omitempty" db:"introduction"` // 这里的 omitempty 是当该字段为空的时候,就不展示该项内容
	CreateTime   time.Time `json:"create_time" db:"create_time"`             // 这里使用 time.Time 类型,在连接数据库的时候就要加上 parseTime=true&loc=Local
}

CommunityDetail 社区详情

type ParamCommunityPostList

type ParamCommunityPostList struct {
	ParamPostList
	CommunityID int64 `json:"community_id" form:"community_id"`
}

ParamCommunityPostList 安社区获取帖子列表query string 参数

type ParamLogin

type ParamLogin struct {
	Username string `json:"username" binding:"required"` // 用户名
	Password string `json:"password" binding:"required"` // 用户密码
}

ParamLogin 登录请求参数

type ParamPostList

type ParamPostList struct {
	CommunityID int64  `json:"community_id" form:"community_id"`   // 社区ID 可以为空
	Page        int64  `json:"page" form:"page" example:"1"`       // 页码
	Size        int64  `json:"size" form:"size" example:"10"`      // 每页数量
	Order       string `json:"order" form:"order" example:"score"` // 排序依据
}

ParamPostList 获取帖子列表2 query string 参数 communityID 可以为空 如果前端没有传社区id,communityID为空,查询所有帖子列表-->GetPostList2 如果前端传了社区id,查询对应社区的帖子列表-->

type ParamSigUp

type ParamSigUp struct {
	Username string `json:"username" binding:"required"`               // 用户名
	Password string `json:"password" binding:"required,checkPassword"` // 用户密码
	//RePassword string `json:"re_password" binding:"required,eqfield=Password"` // 确认密码
	RePassword string `json:"confirm_password" binding:"required,eqfield=Password"` // 确认密码
}

ParamSigUp 注册请求参数

type ParamVoteData

type ParamVoteData struct {
	//UserID(可以通过GetCurrentID拿到)
	PostID    string `json:"post_id" binding:"required"`              // 贴子 id
	Direction int8   `json:"direction,string" binding:"oneof=1 0 -1"` // 赞成票(1)反对票(-1)取消投票(0)
}

ParamVoteData 投票请求数据

type Post

type Post struct {
	ID          int64     `json:"id,string" db:"post_id"`                            // 帖子ID
	AuthorID    int64     `json:"author_id" db:"author_id"`                          // 用户ID
	CommunityID int64     `json:"community_id" db:"community_id" binding:"required"` // 社区ID 可以为空
	Status      int32     `json:"status" db:"status"`                                // 投票状态
	Title       string    `json:"title" db:"title" binding:"required"`               // 标题
	Conent      string    `json:"content" db:"content" binding:"required"`           // 内容
	CreateTime  time.Time `json:"create_time" db:"create_time"`                      // 创建时间
}

Post 即需要与用户传递的参数对应,也需要与数据库表对应 注意内存对齐

type User

type User struct {
	UserID   int64  `db:"user_id"`  // 用户 ID
	Username string `db:"username"` // 用户名
	Password string `db:"password"` // 邮箱
	Token    string
}

User 用户对象,定义了用户的基础信息

Jump to

Keyboard shortcuts

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