service

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: 22 Imported by: 0

Documentation

Index

Constants

View Source
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}"
)
View Source
const UpdateAtFieldName = "updateat"

UpdateAtFieldName ...

Variables

View Source
var ErrNotMyself = errors.New("friend must not be yourself")

ErrNotMyself 好友不能是自己

View Source
var ErrPageIndexOutOfRange = errors.New("page index out of range")

ErrPageIndexOutOfRange 越界错误

Functions

func CalculateSort

func CalculateSort()

CalculateSort 计算排行:包括每个用户最火的文章 最火的分类 全局最火的文章 全部存入Redis中

func GenerateMongoFilter

func GenerateMongoFilter(filter bson.M, src interface{}) error

GenerateMongoFilter 利用反射 src的tag(mongo)的条件来生成filter条件 字段名的小写作为key value作为值

Types

type AdminService

type AdminService struct{}

AdminService 管理员服务

func NewAdminService

func NewAdminService() *AdminService

NewAdminService new

func (AdminService) ArticleQuery

ArticleQuery 文章查询

func (AdminService) ArticleUpdate

func (AdminService) ArticleUpdate(articleID uint64, status data.CommonType) error

ArticleUpdate 文章更新

func (AdminService) CommentQuery

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

PhotoQuery 照片查询 由于是嵌套结构体查询 这样只有查出所有再排序过滤了...有点耗性能(归纳为经验问题)

func (AdminService) PhotoUpdate

func (AdminService) PhotoUpdate(photoName string, status data.CommonType) error

PhotoUpdate 照片更新

func (AdminService) UserQuery

UserQuery 用户查询 整点硬性拼接

func (AdminService) UserUpdate

func (AdminService) UserUpdate(userID uint, status data.CommonType) error

UserUpdate 用户更新

type AlbumService

type AlbumService struct{}

AlbumService 相册服务

func NewAlbumService

func NewAlbumService() *AlbumService

NewAlbumService ...

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 NewArticleSrrvice

func NewArticleSrrvice() *ArticleService

NewArticleSrrvice new

func (ArticleService) AddArticle

func (ArticleService) AddArticle(article *data.Article, categories []string) (uint64, error)

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

func (ArticleService) LikeArticle(articleID uint64, userID uint, likeType data.LikeType) error

LikeArticle 喜欢文章 两种类型 如果没有该文档 会返回mongo.ErrNoDocuments错误

type CommonService

type CommonService struct{}

CommonService 小需求写这里

func NewCommonService

func NewCommonService() *CommonService

NewCommonService ...

func (CommonService) AddFeedback

func (CommonService) AddFeedback(user *data.TokenClaimsSubject, request *data.FeedbackRequest)

AddFeedback 添加反馈

type UserService

type UserService struct{}

UserService ...

func NewUserService

func NewUserService() *UserService

NewUserService new

func (UserService) GetFriendList

func (UserService) GetFriendList(userID uint) ([]*data.FriendListResponse, error)

GetFriendList 获取好友集合 逻辑

  1. 假设user是发送方(from_user_id) 如果status等于add:已添加 , status==wait 等待对方同意 status==decline 被对方拒绝
  2. 假设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 更新好友状态

Jump to

Keyboard shortcuts

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