Documentation ¶
Index ¶
- Constants
- Variables
- func CalculateSort()
- func GenerateMongoFilter(filter bson.M, src interface{}) error
- type AdminService
- func (AdminService) ArticleQuery(query *data.AdminArticleQuery) (*data.ResultListResponse, error)
- func (AdminService) ArticleUpdate(articleID uint64, status data.CommonType) error
- func (AdminService) CommentQuery(query *data.AdminCommentQuery) (*data.ResultListResponse, error)
- func (AdminService) CommentUpdate(commentID uint64, status data.CommonType) error
- func (AdminService) GetFeedback(pageInfo *data.PageInfo) (*data.ResultListResponse, error)
- func (AdminService) PhotoQuery(query *data.AdminPhotoQuery) (*data.ResultListResponse, error)
- func (AdminService) PhotoUpdate(photoName string, status data.CommonType) error
- func (AdminService) UserQuery(query *data.AdminUserQuery) (*data.ResultListResponse, error)
- func (AdminService) UserUpdate(userID uint, status data.CommonType) error
- type AlbumService
- func (AlbumService) AddPhoto(userID uint, albumID uint64, fileName string, reader io.Reader) (*data.AddPhotoResponse, error)
- func (AlbumService) CancelNewAlbum(albumID uint64) error
- func (AlbumService) EditAlbum(userID uint, albumID uint64, albumReq *data.EditAlbumRequest) error
- func (AlbumService) GetAlbumDetail(albumID uint64) (*data.Album, error)
- func (AlbumService) GetAlbumInfo(userID uint) ([]*data.AlbumMaintainResponse, error)
- func (AlbumService) NewAlbum(userID uint, albumReq *data.AddAlbumRequest) error
- type ArticleService
- func (ArticleService) AddArticle(article *data.Article, categories []string) (uint64, error)
- func (ArticleService) AddComment(articleID uint64, commentReq *data.AddCommentRequest) (uint64, error)
- func (articleservice ArticleService) ArticleMaintainQuery(query *data.ArticleMaintainQuery) ([]*data.ArticleMaintainResponse, *data.PageInfo, error)
- func (ArticleService) CancelLikeArticle(articleID uint64, userID uint, likeType data.LikeType) error
- func (ArticleService) DeleteArticleOrComment(id uint64, userID uint) error
- func (ArticleService) EditArticle(article *data.Article, categories []string) error
- func (ArticleService) GetArticleDetail(articleID uint64) (*data.ArticleResponse, error)
- func (articleservice ArticleService) GetArticleMaintain(articleID uint64) (*data.ArticleMaintainResponse, error)
- func (articleservice ArticleService) GetFavoriteList(userID uint) ([]*data.ArticleMaintainResponse, error)
- func (ArticleService) GetUsualCategories() ([]string, error)
- func (ArticleService) LikeArticle(articleID uint64, userID uint, likeType data.LikeType) error
- type CommonService
- type UserService
Constants ¶
const ( // ArticlesLeaderBoardSize 排行榜大小 ArticlesLeaderBoardSize = 100 // CategoriesLeaderBoardSize 分类排行 CategoriesLeaderBoardSize = 20 // RedisRankKeyArticle 文章排行名 RedisRankKeyArticle = "article_rank" // RedisRankKeyUserArticleKey 每个用户的文章排行键 RedisRankKeyUserArticleKey = "user_article_rank_${user_id}" // RedisRankKeyCategoryKey redis分类排行 RedisRankKeyCategoryKey = "categories_rank" // RedisRankKeyCategoryArticleKey redis每个分类的文章排行 RedisRankKeyCategoryArticleKey = "category_article_rank_${category}" )
const UpdateAtFieldName = "updateat"
UpdateAtFieldName ...
Variables ¶
var ErrNotMyself = errors.New("friend must not be yourself")
ErrNotMyself 好友不能是自己
var ErrPageIndexOutOfRange = errors.New("page index out of range")
ErrPageIndexOutOfRange 越界错误
Functions ¶
func GenerateMongoFilter ¶
GenerateMongoFilter 利用反射 src的tag(mongo)的条件来生成filter条件 字段名的小写作为key value作为值
Types ¶
type AdminService ¶
type AdminService struct{}
AdminService 管理员服务
func (AdminService) ArticleQuery ¶
func (AdminService) ArticleQuery(query *data.AdminArticleQuery) (*data.ResultListResponse, error)
ArticleQuery 文章查询
func (AdminService) ArticleUpdate ¶
func (AdminService) ArticleUpdate(articleID uint64, status data.CommonType) error
ArticleUpdate 文章更新
func (AdminService) CommentQuery ¶
func (AdminService) CommentQuery(query *data.AdminCommentQuery) (*data.ResultListResponse, error)
CommentQuery 评论查询 由于是嵌套结构体查询 这样只有查出所有再排序过滤了...有点耗性能(归纳为经验问题)
func (AdminService) CommentUpdate ¶
func (AdminService) CommentUpdate(commentID uint64, status data.CommonType) error
CommentUpdate 评论更新
func (AdminService) GetFeedback ¶
func (AdminService) GetFeedback(pageInfo *data.PageInfo) (*data.ResultListResponse, error)
GetFeedback 查询反馈
func (AdminService) PhotoQuery ¶
func (AdminService) PhotoQuery(query *data.AdminPhotoQuery) (*data.ResultListResponse, error)
PhotoQuery 照片查询 由于是嵌套结构体查询 这样只有查出所有再排序过滤了...有点耗性能(归纳为经验问题)
func (AdminService) PhotoUpdate ¶
func (AdminService) PhotoUpdate(photoName string, status data.CommonType) error
PhotoUpdate 照片更新
func (AdminService) UserQuery ¶
func (AdminService) UserQuery(query *data.AdminUserQuery) (*data.ResultListResponse, error)
UserQuery 用户查询 整点硬性拼接
func (AdminService) UserUpdate ¶
func (AdminService) UserUpdate(userID uint, status data.CommonType) error
UserUpdate 用户更新
type AlbumService ¶
type AlbumService struct{}
AlbumService 相册服务
func (AlbumService) AddPhoto ¶
func (AlbumService) AddPhoto(userID uint, albumID uint64, fileName string, reader io.Reader) (*data.AddPhotoResponse, error)
AddPhoto 添加一张照片 逻辑 此方法有两种用途 1.写入到已经存储好的相册中 2. 写入到还未创建好的相册当中 在保存成功后需要在Mongo里查询 是否有该albumID数据
如果有 则生成一条uuid相册信息 插入其中 如果没有 则代表新建相册 需要将生成的uuid 存入redis里缓存起来 等待相册创建提交
func (AlbumService) CancelNewAlbum ¶
func (AlbumService) CancelNewAlbum(albumID uint64) error
CancelNewAlbum 取消新建相册
func (AlbumService) EditAlbum ¶
func (AlbumService) EditAlbum(userID uint, albumID uint64, albumReq *data.EditAlbumRequest) error
EditAlbum 编辑相册
func (AlbumService) GetAlbumDetail ¶
func (AlbumService) GetAlbumDetail(albumID uint64) (*data.Album, error)
GetAlbumDetail 获取相册详细信息
func (AlbumService) GetAlbumInfo ¶
func (AlbumService) GetAlbumInfo(userID uint) ([]*data.AlbumMaintainResponse, error)
GetAlbumInfo 获取相册信息
func (AlbumService) NewAlbum ¶
func (AlbumService) NewAlbum(userID uint, albumReq *data.AddAlbumRequest) error
NewAlbum 新建相册 逻辑: 1. 从redis里读出该albumID的相册集合 2. 获取用户真正要上传的图片uuid 删除不需要的图片 3. 添加数据到mongo
type ArticleService ¶
type ArticleService struct{}
ArticleService 文章服务
func (ArticleService) AddArticle ¶
AddArticle 添加文章
func (ArticleService) AddComment ¶
func (ArticleService) AddComment(articleID uint64, commentReq *data.AddCommentRequest) (uint64, error)
AddComment 添加评论
func (ArticleService) ArticleMaintainQuery ¶
func (articleservice ArticleService) ArticleMaintainQuery(query *data.ArticleMaintainQuery) ([]*data.ArticleMaintainResponse, *data.PageInfo, error)
ArticleMaintainQuery 文章大概查询 逻辑: 如果 category name 和 content都为空 直接从redis里查热门数据article id再查mongo 如果只有category name的话 从redis里查出该分类的集合 剩下的就直接查mongo #issue 这里有一个Bug 当用户新增文章时 缓存没更新的话 是查不到才添加的数据的 所以在添加文章时再掉一次重新排序这种临时的方法来解决这一问题
func (ArticleService) CancelLikeArticle ¶
func (ArticleService) CancelLikeArticle(articleID uint64, userID uint, likeType data.LikeType) error
CancelLikeArticle 取消喜欢
func (ArticleService) DeleteArticleOrComment ¶
func (ArticleService) DeleteArticleOrComment(id uint64, userID uint) error
DeleteArticleOrComment 删除文章或评论
func (ArticleService) EditArticle ¶
func (ArticleService) EditArticle(article *data.Article, categories []string) error
EditArticle 编辑文章 更新mongo 删除分类
func (ArticleService) GetArticleDetail ¶
func (ArticleService) GetArticleDetail(articleID uint64) (*data.ArticleResponse, error)
GetArticleDetail 获取文章详情
func (ArticleService) GetArticleMaintain ¶
func (articleservice ArticleService) GetArticleMaintain(articleID uint64) (*data.ArticleMaintainResponse, error)
GetArticleMaintain 获取文章大概
func (ArticleService) GetFavoriteList ¶
func (articleservice ArticleService) GetFavoriteList(userID uint) ([]*data.ArticleMaintainResponse, error)
GetFavoriteList 获取收藏夹
func (ArticleService) GetUsualCategories ¶
func (ArticleService) GetUsualCategories() ([]string, error)
GetUsualCategories 获取常用分类
func (ArticleService) LikeArticle ¶
LikeArticle 喜欢文章 两种类型 如果没有该文档 会返回mongo.ErrNoDocuments错误
type CommonService ¶
type CommonService struct{}
CommonService 小需求写这里
func (CommonService) AddFeedback ¶
func (CommonService) AddFeedback(user *data.TokenClaimsSubject, request *data.FeedbackRequest)
AddFeedback 添加反馈
type UserService ¶
type UserService struct{}
UserService ...
func (UserService) GetFriendList ¶
func (UserService) GetFriendList(userID uint) ([]*data.FriendListResponse, error)
GetFriendList 获取好友集合 逻辑
- 假设user是发送方(from_user_id) 如果status等于add:已添加 , status==wait 等待对方同意 status==decline 被对方拒绝
- 假设user是发送方(to_user_id) 如果status等于add:已添加 , status==wait 等待同意或拒绝对方请求 status==decline 已拒绝对方
func (UserService) GetUserInfo ¶
func (UserService) GetUserInfo(userID uint) (*data.UserInfo, error)
GetUserInfo 获取用户信息
func (UserService) UpdateFriendStatus ¶
func (UserService) UpdateFriendStatus(meID uint, updateReq *data.UpdateFriendStatusRequest) (err error)
UpdateFriendStatus 更新好友状态