新增订单群聊
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrDependencyUnavailable = errors.New("dependency unavailable")
|
||||
ErrConversationNotFound = errors.New("conversation not found")
|
||||
ErrPermissionDenied = errors.New("permission denied")
|
||||
ErrInvalidMessage = errors.New("invalid message")
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
repo *Repository
|
||||
}
|
||||
|
||||
func NewService(repo *Repository) *Service {
|
||||
return &Service{repo: repo}
|
||||
}
|
||||
|
||||
func (s *Service) ListConversations(principal Principal, page, pageSize int) (*PaginatedResult, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.ListConversations(principal, page, pageSize)
|
||||
}
|
||||
|
||||
func (s *Service) FindConversation(principal Principal, id uint64) (*ConversationDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.FindConversation(principal, id)
|
||||
}
|
||||
|
||||
func (s *Service) FindOrderConversation(userID uint64, orderID uint64) (*ConversationDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.FindOrderConversation(userID, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) Messages(principal Principal, conversationID uint64, page, pageSize int) (*PaginatedResult, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.Messages(principal, conversationID, page, pageSize)
|
||||
}
|
||||
|
||||
func (s *Service) SendMessage(principal Principal, conversationID uint64, req SendMessageRequest) (*MessageDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
req.Content = strings.TrimSpace(req.Content)
|
||||
if conversationID == 0 || req.Content == "" {
|
||||
return nil, ErrInvalidMessage
|
||||
}
|
||||
if len([]rune(req.Content)) > 1000 {
|
||||
return nil, ErrInvalidMessage
|
||||
}
|
||||
return s.repo.SendMessage(principal, conversationID, req)
|
||||
}
|
||||
|
||||
func (s *Service) MarkRead(principal Principal, conversationID uint64) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.MarkRead(principal, conversationID)
|
||||
}
|
||||
Reference in New Issue
Block a user