Refactor backend APIs to RESTful route patterns.
Align group and conversation handlers/services with path-based endpoints, and unify response/service error handling for related modules. Made-with: Cursor
This commit is contained in:
@@ -25,23 +25,23 @@ const (
|
||||
|
||||
// 群组服务错误定义
|
||||
var (
|
||||
ErrGroupNotFound = errors.New("群组不存在")
|
||||
ErrNotGroupMember = errors.New("不是群成员")
|
||||
ErrNotGroupAdmin = errors.New("不是群管理员")
|
||||
ErrNotGroupOwner = errors.New("不是群主")
|
||||
ErrGroupFull = errors.New("群已满")
|
||||
ErrAlreadyMember = errors.New("已经是群成员")
|
||||
ErrCannotRemoveOwner = errors.New("不能移除群主")
|
||||
ErrCannotMuteOwner = errors.New("不能禁言群主")
|
||||
ErrMuted = errors.New("你已被禁言")
|
||||
ErrMuteAllEnabled = errors.New("全员禁言中")
|
||||
ErrCannotJoin = errors.New("该群不允许加入")
|
||||
ErrJoinRequestPending = errors.New("加群申请已提交")
|
||||
ErrGroupRequestNotFound = errors.New("加群请求不存在")
|
||||
ErrGroupRequestHandled = errors.New("该加群请求已处理")
|
||||
ErrNotRequestTarget = errors.New("不是邀请目标用户")
|
||||
ErrNoEligibleInvitee = errors.New("没有可邀请的用户")
|
||||
ErrNotMutualFollow = errors.New("仅支持邀请互相关注用户")
|
||||
ErrGroupNotFound = &ServiceError{Code: 404, Message: "群组不存在"}
|
||||
ErrNotGroupMember = &ServiceError{Code: 403, Message: "不是群成员"}
|
||||
ErrNotGroupAdmin = &ServiceError{Code: 403, Message: "不是群管理员"}
|
||||
ErrNotGroupOwner = &ServiceError{Code: 403, Message: "不是群主"}
|
||||
ErrGroupFull = &ServiceError{Code: 400, Message: "群已满"}
|
||||
ErrAlreadyMember = &ServiceError{Code: 400, Message: "已经是群成员"}
|
||||
ErrCannotRemoveOwner = &ServiceError{Code: 400, Message: "不能移除群主"}
|
||||
ErrCannotMuteOwner = &ServiceError{Code: 400, Message: "不能禁言群主"}
|
||||
ErrMuted = &ServiceError{Code: 403, Message: "你已被禁言"}
|
||||
ErrMuteAllEnabled = &ServiceError{Code: 403, Message: "全员禁言中"}
|
||||
ErrCannotJoin = &ServiceError{Code: 400, Message: "该群不允许加入"}
|
||||
ErrJoinRequestPending = &ServiceError{Code: 400, Message: "加群申请已提交"}
|
||||
ErrGroupRequestNotFound = &ServiceError{Code: 404, Message: "加群请求不存在"}
|
||||
ErrGroupRequestHandled = &ServiceError{Code: 400, Message: "该加群请求已处理"}
|
||||
ErrNotRequestTarget = &ServiceError{Code: 400, Message: "不是邀请目标用户"}
|
||||
ErrNoEligibleInvitee = &ServiceError{Code: 400, Message: "没有可邀请的用户"}
|
||||
ErrNotMutualFollow = &ServiceError{Code: 400, Message: "仅支持邀请互相关注用户"}
|
||||
)
|
||||
|
||||
// GroupService 群组服务接口
|
||||
|
||||
@@ -411,6 +411,31 @@ func (s *PostService) IsFavorited(ctx context.Context, postID, userID string) bo
|
||||
return s.postRepo.IsFavorited(postID, userID)
|
||||
}
|
||||
|
||||
// GetPostInteractionStatus 批量获取帖子的交互状态(点赞、收藏)
|
||||
func (s *PostService) GetPostInteractionStatus(ctx context.Context, postIDs []string, userID string) (map[string]bool, map[string]bool, error) {
|
||||
isLikedMap := make(map[string]bool)
|
||||
isFavoritedMap := make(map[string]bool)
|
||||
|
||||
if userID == "" || len(postIDs) == 0 {
|
||||
return isLikedMap, isFavoritedMap, nil
|
||||
}
|
||||
|
||||
for _, postID := range postIDs {
|
||||
isLikedMap[postID] = s.postRepo.IsLiked(postID, userID)
|
||||
isFavoritedMap[postID] = s.postRepo.IsFavorited(postID, userID)
|
||||
}
|
||||
|
||||
return isLikedMap, isFavoritedMap, nil
|
||||
}
|
||||
|
||||
// GetPostInteractionStatusSingle 获取单个帖子的交互状态
|
||||
func (s *PostService) GetPostInteractionStatusSingle(ctx context.Context, postID, userID string) (isLiked, isFavorited bool) {
|
||||
if userID == "" {
|
||||
return false, false
|
||||
}
|
||||
return s.postRepo.IsLiked(postID, userID), s.postRepo.IsFavorited(postID, userID)
|
||||
}
|
||||
|
||||
// IncrementViews 增加帖子观看量并同步到Gorse
|
||||
func (s *PostService) IncrementViews(ctx context.Context, postID, userID string) error {
|
||||
if err := s.postRepo.IncrementViews(postID); err != nil {
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrStickerAlreadyExists = errors.New("sticker already exists")
|
||||
ErrInvalidStickerURL = errors.New("invalid sticker url")
|
||||
ErrStickerAlreadyExists = &ServiceError{Code: 400, Message: "sticker already exists"}
|
||||
ErrInvalidStickerURL = &ServiceError{Code: 400, Message: "invalid sticker url"}
|
||||
)
|
||||
|
||||
// StickerService 自定义表情服务接口
|
||||
|
||||
Reference in New Issue
Block a user