This commit is contained in:
Vladislav Kunetskiy
2026-10-16 21:45:41 +03:00
parent 4e84354642
commit 5830eb43e8
227 changed files with 12913 additions and 499 deletions
+23 -4
View File
@@ -1,6 +1,8 @@
package domain
import (
"crypto/sha256"
"fmt"
"time"
"github.com/google/uuid"
@@ -14,12 +16,29 @@ type Message struct {
CreatedAt time.Time
}
// MessageIdempotency is the client Idempotency-Key together with the fingerprint
// of the payload it was first used with. The same key and fingerprint replay the
// stored message; the same key with another payload is a conflict.
type MessageIdempotency struct {
Key string
RequestHash [sha256.Size]byte
}
type MessageDraft struct {
ChatID uuid.UUID
SenderID uuid.UUID
Text string
ChatID uuid.UUID
SenderID uuid.UUID
Text string
Idempotency MessageIdempotency
}
func (d MessageDraft) Validate() error {
return validateNotBlank("text", d.Text)
if err := validateNotBlank("text", d.Text); err != nil {
return err
}
if d.Idempotency.Key == "" {
return fmt.Errorf("idempotency key is missing: %w", ErrValidation)
}
return nil
}