forked from mtusi2026/mtusi2026lab4
лаба 4 на оценку 5
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
"mtusi2026lab4/internal/domain"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type canonicalMessageRequest struct {
|
||||
@@ -15,13 +17,21 @@ type canonicalMessageRequest struct {
|
||||
}
|
||||
|
||||
func (s *Service) SendMessage(ctx context.Context, command SendMessageCommand) (domain.Message, error) {
|
||||
if err := domain.ValidateMessageText(command.Text); err != nil {
|
||||
attachmentIDs := append([]string(nil), command.AttachmentIDs...)
|
||||
if attachmentIDs == nil {
|
||||
attachmentIDs = make([]string, 0)
|
||||
}
|
||||
|
||||
if err := domain.ValidateMessageInput(command.Text, attachmentIDs); err != nil {
|
||||
return domain.Message{}, fmt.Errorf("%w: %v", ErrInvalidInput, err)
|
||||
}
|
||||
for index, attachmentID := range attachmentIDs {
|
||||
attachmentIDs[index] = uuid.MustParse(attachmentID).String()
|
||||
}
|
||||
|
||||
canonicalBody, err := json.Marshal(canonicalMessageRequest{
|
||||
Text: command.Text,
|
||||
AttachmentIDs: make([]string, 0),
|
||||
AttachmentIDs: attachmentIDs,
|
||||
})
|
||||
if err != nil {
|
||||
return domain.Message{}, fmt.Errorf("canonicalize message request: %w", err)
|
||||
@@ -31,6 +41,7 @@ func (s *Service) SendMessage(ctx context.Context, command SendMessageCommand) (
|
||||
ActorID: command.ActorID,
|
||||
ChatID: command.ChatID,
|
||||
Text: command.Text,
|
||||
AttachmentIDs: attachmentIDs,
|
||||
Method: command.Method,
|
||||
CanonicalPath: command.CanonicalPath,
|
||||
Key: command.IdempotencyKey,
|
||||
|
||||
Reference in New Issue
Block a user