feat(message): store messages in Postgres

This commit is contained in:
kk10
2026-10-05 13:26:21 +03:00
parent 04f7c046b6
commit 385a8c0312
6 changed files with 82 additions and 36 deletions
+3 -2
View File
@@ -12,6 +12,7 @@ import (
var ErrInvalidCursor = errors.New("invalid cursor")
type Cursor struct {
ChatID uuid.UUID `json:"chat_id"`
CreatedAt time.Time `json:"created_at"`
ID uuid.UUID `json:"id"`
}
@@ -21,7 +22,7 @@ func encodeCursor(cursor Cursor) string {
return base64.RawURLEncoding.EncodeToString(data)
}
func decodeCursor(raw string) (Cursor, error) {
func decodeCursor(raw string, chatID uuid.UUID) (Cursor, error) {
data, err := base64.RawURLEncoding.DecodeString(raw)
if err != nil {
return Cursor{}, ErrInvalidCursor
@@ -32,7 +33,7 @@ func decodeCursor(raw string) (Cursor, error) {
return Cursor{}, ErrInvalidCursor
}
if cursor.ID == uuid.Nil || cursor.CreatedAt.IsZero() {
if cursor.ID == uuid.Nil || cursor.CreatedAt.IsZero() || cursor.ChatID != chatID {
return Cursor{}, ErrInvalidCursor
}