data

package
v0.0.0-...-7f855fe Latest Latest
Warning

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

Go to latest
Published: May 8, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MongoCollectionArticle 集合
	MongoCollectionArticle = "article"
	// MongoCollectionAlbum 集合
	MongoCollectionAlbum = "album"
	// MongoCollectionFeedback 集合
	MongoCollectionFeedback = "feedback"
)

Variables

View Source
var (
	// FavoriteScore 收藏得分
	FavoriteScore = 4
	// StarScore 喜欢得分
	StarScore = 3
	// CommentScore 评论得分
	CommentScore = 3
	// HitScore 点击得分
	HitScore = 1
)
View Source
var (
	// DefaultPageIndex 默认page index
	DefaultPageIndex int64 = 1
	// DefaultPageSize 默认 page size
	DefaultPageSize int64 = 25
)

Functions

func DuplicateStructField

func DuplicateStructField(src interface{}, desc interface{}) error

DuplicateStructField 复制结构体字段:复制约束 两个名称相同,类型相同

Types

type AddAlbumRequest

type AddAlbumRequest struct {
	AlbumID     uint64 `validate:"required"`
	Title       string `validate:"required,min=4"`
	CoverName   string
	Description string
	Location    string
	PhotoList   []string //要添加的uuid文件名集合
}

AddAlbumRequest 添加相册请求

type AddArticleRequest

type AddArticleRequest struct {
	Title      string   `validate:"required,min=10"`
	Categories []string `validate:"gt=0"` //切片长度大于0
	Content    string   `validate:"required,min=50"`
}

AddArticleRequest 添加文章请求

type AddCommentRequest

type AddCommentRequest struct {
	ReplyTo uint64 `validate:"required"`
	Content string `validate:"required,min=1"`
	UserID  uint
}

AddCommentRequest 添加评论或者恢复

type AddPhotoResponse

type AddPhotoResponse struct {
	FileName         string
	OriginalFileName string
	FileSize         int
}

AddPhotoResponse 添加图片返回

type AdminArticleQuery

type AdminArticleQuery struct {
	ArticleID uint64     `schema:"article_id" mongo:"equal"`
	UserLogin string     `schema:"user_login"`
	UserID    uint       `schema:"-" mongo:"equal"`
	Title     string     `schema:"title" mongo:"like"`
	Content   string     `schema:"content" mongo:"like"`
	Status    CommonType `schema:"status" mongo:"equal"`
	PageInfo
	DateInterval
}

AdminArticleQuery 管理文章查询

type AdminArticleResponse

type AdminArticleResponse struct {
	ArticleID uint64
	UserID    uint
	UserLogin string
	Title     string
	Content   string
	CreateAt  time.Time
	UpdateAt  time.Time
	Status    CommonType
}

AdminArticleResponse ...

type AdminCommentQuery

type AdminCommentQuery struct {
	ArticleID uint64     `schema:"article_id" mongo:"equal"`
	CommentID uint64     `schema:"comment_id"`
	UserLogin string     `schema:"user_login"`
	UserID    uint       `schema:"-" mongo:"equal"`
	Status    CommonType `schema:"status" mongo:"equal"`
	PageInfo
	DateInterval
}

AdminCommentQuery ...

type AdminCommentResponse

type AdminCommentResponse struct {
	ArticleID uint64
	CommentID uint64
	UserID    uint
	UserLogin string
	Content   string
	CreateAt  time.Time
	Status    CommonType
}

AdminCommentResponse ...

type AdminPhotoQuery

type AdminPhotoQuery struct {
	AlbumID   uint64     `schema:"album_id" mongo:"equal"`
	UserLogin string     `schema:"user_login"`
	UserID    uint       `schema:"-" mongo:"equal"`
	Status    CommonType `schama:"status" mongo:"equal"`
	PageInfo
	DateInterval
}

AdminPhotoQuery ...

type AdminPhotoResponse

type AdminPhotoResponse struct {
	AlbumID           uint64
	UserID            uint
	UserLogin         string
	AlbumName         string
	PhotoName         string
	PhotoOriginalName string
	FileSize          int64
	CreateAt          time.Time
	Status            CommonType
}

AdminPhotoResponse ...

type AdminUserQuery

type AdminUserQuery struct {
	UserID    uint       `schema:"user_id"`
	UserLogin string     `schema:"user_login"`
	Status    CommonType `schema:"status"`
	PageInfo
	DateInterval
}

AdminUserQuery ...

type AdminUserResponse

type AdminUserResponse struct {
	UserID    uint
	UserLogin string
	IsAdmin   bool
	Status    string
	Blog      string
	Email     string
	Localtion string
	CreateAt  time.Time
	UpdateAt  time.Time
}

AdminUserResponse 返回

type Album

type Album struct {
	AlbumID     uint64
	UserID      uint
	Title       string
	Description string
	CoverName   string
	Location    string
	Hits        uint
	Status      CommonType
	Photos      []*Photo
	CreateAt    time.Time
	UpdateAt    time.Time
}

Album 相册

type AlbumMaintainResponse

type AlbumMaintainResponse struct {
	AlbumID   uint64
	AlbumName string `bson:"title"`
	CoverName string
	Location  string
	CreateAt  time.Time
}

AlbumMaintainResponse 相册简约信息

type Article

type Article struct {
	ArticleID uint64
	UserID    uint
	Title     string
	Content   string
	Comments  []*Comment
	Hits      uint
	Status    CommonType
	CreateAt  time.Time
	UpdateAt  time.Time
}

Article 文章 存在mongo里

func (*Article) GetLastEditDateAndUserID

func (article *Article) GetLastEditDateAndUserID() (ltime time.Time, userID uint)

GetLastEditDateAndUserID 获取最后次修改的时间 和该用户 逻辑:优先级校验 文章更新时间UpdateAt (创建时createAt和updateAt相同) (因为在mongo里是push的所以评论最新评论始终在最后面) > 文章创建时间

func (*Article) TreeView

func (article *Article) TreeView() *ArticleResponse

TreeView 将Article存在mongo里的结果转为树形结构 以便更直观的显示 实现:2个map+2个for循环 小小算法 可笑可笑 同时 **这里还会过滤一些被删除和被拉黑的评论**

type ArticleCalculate

type ArticleCalculate struct {
	ArticleID      uint64
	UserID         uint
	Hits           uint
	StarNumber     int
	CommentNumber  int
	FavoriteNumber int
}

ArticleCalculate 计算文章数据用

type ArticleCalculateDTO

type ArticleCalculateDTO struct {
	ArticleID uint64
	UserID    uint
	Hits      uint
	Comments  []*Comment
}

ArticleCalculateDTO DTO 取消序列化一些没用的东西

type ArticleMaintainQuery

type ArticleMaintainQuery struct {
	Content      string `schema:"content"`
	CategoryName string `schema:"category_name"`
	PageInfo
}

ArticleMaintainQuery 文章大概查询

type ArticleMaintainResponse

type ArticleMaintainResponse struct {
	ArticleID          uint64
	Title              string
	Categories         []string
	LastEditDate       time.Time
	LastEditDateString string
	LastEditUserID     uint
	LastEditUserLogin  string
	Hits               uint
	StarNumber         uint
	CommentNumber      uint
	FavoriteNumber     uint
	CreateAt           time.Time
}

ArticleMaintainResponse 文章大致查询

type ArticleMaintainSortRule

type ArticleMaintainSortRule []*ArticleMaintainResponse

ArticleMaintainSortRule 排序

func (ArticleMaintainSortRule) Len

func (a ArticleMaintainSortRule) Len() int

func (ArticleMaintainSortRule) Less

func (a ArticleMaintainSortRule) Less(i, j int) bool

func (ArticleMaintainSortRule) Swap

func (a ArticleMaintainSortRule) Swap(i, j int)

type ArticleResponse

type ArticleResponse struct {
	ArticleID  uint64
	UserID     uint
	UserLogin  string
	Title      string
	Content    string
	Comments   []*CommentResponse
	Hits       uint
	Stars      []*LikeResponse
	Favorities []*LikeResponse
	Status     CommonType `json:"-"`
	CreateAt   time.Time
}

ArticleResponse TreeView结构的Article

type ByRule

type ByRule []*ArticleCalculate

ByRule 排序用 排序规则: 收藏数*FavoriteScore+点赞数*StarScore+评论数*CommentScore+点击量*HitScore

func (ByRule) Len

func (a ByRule) Len() int

func (ByRule) Less

func (a ByRule) Less(i, j int) bool

func (ByRule) Swap

func (a ByRule) Swap(i, j int)

type Category

type Category struct {
	CategoryID int
	ArticleID  uint64 `db:"article_id"`
	Name       string
	CreateAt   time.Time `db:"create_at"`
	UpdateAt   time.Time `db:"update_at"`
}

Category 文章分类

type Comment

type Comment struct {
	CommentID uint64     // 评论ID
	ReplyTo   uint64     // 回复评论或者文章的ID
	UserID    uint       //用户ID
	Content   string     //内容
	Status    CommonType //状态
	CreateAt  time.Time
}

Comment 嵌套存在mongo里

type CommentCreateAtSortDESC

type CommentCreateAtSortDESC []*AdminCommentResponse

CommentCreateAtSortDESC 根据create at 逆序排序

func (CommentCreateAtSortDESC) Len

func (a CommentCreateAtSortDESC) Len() int

func (CommentCreateAtSortDESC) Less

func (a CommentCreateAtSortDESC) Less(i, j int) bool

func (CommentCreateAtSortDESC) Swap

func (a CommentCreateAtSortDESC) Swap(i, j int)

type CommentResponse

type CommentResponse struct {
	CommentID uint64
	UserID    uint
	Content   string
	Status    CommonType
	Replies   []*CommentResponse
	CreateAt  time.Time
}

CommentResponse TreeView结构的Comment

type CommonType

type CommonType string

CommonType 通用的类型

const (
	// Normal 正常
	Normal CommonType = "Y"
	// Blocked 拉黑
	Blocked CommonType = "B"
	// Deleted 被删除
	Deleted CommonType = "D"
)

type DateInterval

type DateInterval struct {
	DateFrom *time.Time `schema:"date_from" mongo:"gt"`
	DateTo   *time.Time `schema:"date_to" mongo:"lt"`
}

DateInterval 时间区间

type EditAlbumRequest

type EditAlbumRequest struct {
	Title           string
	Description     string
	Location        string
	CoverName       string
	DeletePhotoList []string
}

EditAlbumRequest 编辑相册请求

type Feedback

type Feedback struct {
	UserID      uint
	UserLogin   string //为了后面好看 就不满足范式了
	Description string
	Contact     string
	UpdateAt    time.Time
}

Feedback 反馈

type FeedbackRequest

type FeedbackRequest struct {
	Description string `validate:"required"`
	Contact     string
}

FeedbackRequest 请求

type Friend

type Friend struct {
	FriendsID  uint `db:"friends_id"`
	FromUserID uint `db:"from_user_id"`
	ToUserID   uint `db:"to_user_id"`
	Status     FriendType
	CreateAt   time.Time `db:"create_at"`
	UpdateAt   time.Time `db:"update_at"`
}

Friend 好友列表

type FriendListResponse

type FriendListResponse struct {
	FriendUserID    uint
	FriendUserLogin string
	Status          FriendType
	Type            UpdateFriendType
	CreateAt        time.Time
	UpdateAt        time.Time
}

FriendListResponse 好友列表回复

type FriendType

type FriendType string

FriendType 好友类型

const (
	// Added 已添加
	Added FriendType = "Y"
	// Declined 已拒绝
	Declined FriendType = "D"
	// Waitting 等待中
	Waitting FriendType = "W"
)

type GenericResponse

type GenericResponse struct {
	Successed bool   // 是否成功
	Code      int    `json:",omitempty"` //状态码
	Message   string `json:",omitempty"` //消息
}

GenericResponse 通用返回题

func NewFailedResponse

func NewFailedResponse(msg string, code int) *GenericResponse

NewFailedResponse 新的错误回应(带状态码)

func NewSuccessResponse

func NewSuccessResponse() *GenericResponse

NewSuccessResponse 成功返回

type GithubTokenResponse

type GithubTokenResponse struct {
	Error            string
	ErrorDescription string `json:"error_description"`
	ErrorURI         string `json:"error_uri"`
	AccessToken      string `json:"access_token"`
	TokenType        string `json:"token_type"`
	Scope            string `json:"_,omitempty"`
}

GithubTokenResponse 请求github token的返回json数据

type GithubUserResponse

type GithubUserResponse struct {
	Login     string //登录名
	ID        uint   `json:"id"`         //用户独有ID
	NodeID    string `json:"node_id"`    //
	AvatarURL string `json:"avatar_url"` //头像url
	URL       string `json:"url"`        //用户数据url
	Blog      string `json:",omitempty"` //博客
	Email     string `json:",omitempty"` //邮箱
	Localtion string `json:",omitempty"` //位置
	Name      string `json:",omitempty"` //名称
}

GithubUserResponse github返回

type Like

type Like struct {
	LikeID    uint   `db:"like_id"`
	ArticleID uint64 `db:"article_id"`
	UserID    uint   `db:"user_id"`
	Type      LikeType
	CreateAt  time.Time `db:"create_at"`
	UpdateAt  time.Time `db:"update_at"`
}

Like 点赞或收藏

type LikeArticleRequest

type LikeArticleRequest struct {
	LikeType LikeType `validate:"required,oneof=S F"` //S 和 F
}

LikeArticleRequest 喜欢类型

type LikeDTO

type LikeDTO struct {
	Like
	UserLogin string `db:"user_login"`
}

LikeDTO 联表

type LikeResponse

type LikeResponse struct {
	UserID    uint
	UserLogin string
	CreateAt  time.Time
}

LikeResponse 喜欢 回复

type LikeType

type LikeType string

LikeType 喜欢的类型

const (
	// Star 点赞
	Star LikeType = "S"
	// Favorite 收藏
	Favorite LikeType = "F"
)

type MongoCondition

type MongoCondition string

MongoCondition 过滤条件

var (
	// MongoTag tag name
	MongoTag = "mongo"

	// MongoEqual 相等
	MongoEqual MongoCondition = "equal"

	// MongoLessThan 小于
	MongoLessThan MongoCondition = "lt"

	// MongoGreatThan 大于
	MongoGreatThan MongoCondition = "gt"

	// MongoLike like
	MongoLike MongoCondition = "like"
)

type PageInfo

type PageInfo struct {
	PageIndex int64 `schema:"page_index"`
	PageSize  int64 `schema:"page_size"`
	Total     int64
}

PageInfo 分页信息

type Photo

type Photo struct {
	Name         string
	OriginalName string
	FileSize     int64
	Status       CommonType
	CreateAt     time.Time
	UpdateAt     time.Time
}

Photo 相片

type PhotoCreateAtSortDESC

type PhotoCreateAtSortDESC []*AdminPhotoResponse

func (PhotoCreateAtSortDESC) Len

func (a PhotoCreateAtSortDESC) Len() int

func (PhotoCreateAtSortDESC) Less

func (a PhotoCreateAtSortDESC) Less(i, j int) bool

func (PhotoCreateAtSortDESC) Swap

func (a PhotoCreateAtSortDESC) Swap(i, j int)

type ResultListResponse

type ResultListResponse struct {
	GenericResponse
	ResultList interface{} `json:",omitempty"` //结果集
	PageInfo   `json:",omitempty"`
}

ResultListResponse 多结果集返回

func NewPageInfoResultListResponse

func NewPageInfoResultListResponse(data interface{}, pageInfo *PageInfo) *ResultListResponse

NewPageInfoResultListResponse 返回一个分页信息的数据

func NewResultListResponse

func NewResultListResponse(data interface{}) *ResultListResponse

NewResultListResponse 结果集返回

type ResultResponse

type ResultResponse struct {
	GenericResponse
	Result interface{} `json:",omitempty"` //结果集
}

ResultResponse 单结果返回

func NewResultResponse

func NewResultResponse(data interface{}) *ResultResponse

NewResultResponse 结果返回

type TokenClaimsSubject

type TokenClaimsSubject struct {
	UserID      uint
	UserLogin   string
	IsAdmin     bool
	GithubToken string
}

TokenClaimsSubject token负荷 主体

type UpdateFriendStatus

type UpdateFriendStatus string

UpdateFriendStatus 更新好友请求状态

const (
	// Yes 添加
	Yes UpdateFriendStatus = "Y"
	// Decline 拒绝
	Decline UpdateFriendStatus = "D"
)

type UpdateFriendStatusRequest

type UpdateFriendStatusRequest struct {
	FriendUserLogin string             `validate:"required"`
	Status          UpdateFriendStatus `validate:"required,oneof=Y D"`
	Type            UpdateFriendType   `validate:"required,oneof=S R"`
}

UpdateFriendStatusRequest 更新好友状态请求

type UpdateFriendType

type UpdateFriendType string

UpdateFriendType 更新好友状态请求类型

const (
	// Send 请求发送方
	Send UpdateFriendType = "S"
	// Receive 请求接收方
	Receive UpdateFriendType = "R"
)

type User

type User struct {
	UserID    uint   `db:"user_id"`
	UserLogin string `db:"user_login"`
	IsAdmin   bool   `db:"is_admin"`
	Status    string
	Email     sql.NullString
	Location  sql.NullString
	Blog      sql.NullString
	CreateAt  time.Time `db:"create_at"`
	UpdateAt  time.Time `db:"update_at"`
}

User 用户

type UserInfo

type UserInfo struct {
	UserID           uint
	UserLogin        string
	Email            string
	DaysJoined       uint
	FavoritedNumber  uint
	StaredNumber     uint
	CreateAt         time.Time
	ArticleMaintains []*ArticleMaintainResponse
	AlbumMaintains   []*AlbumMaintainResponse
}

UserInfo 用户页用户信息

type UserResponse

type UserResponse struct {
	Login     string
	NodeID    string
	AvatarURL string
	URL       string
	Blog      string
	Email     string
	Localtion string
	Name      string
}

UserResponse 返回给前端 不一样的json序列化

Jump to

Keyboard shortcuts

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