feat(postgres):lab4 wire validate and link attachments into CreateIdempotent

This commit is contained in:
Голиков Maximillian Антон
2026-10-19 20:00:11 +03:00
parent 936747fe76
commit 6cc487b0f3
+8 -1
View File
@@ -108,7 +108,10 @@ func (r *MessageRepo) CreateIdempotent(
}, nil
}
// 4) Слот наш — вставляем сообщение в той же транзакции.
if err := r.validateAttachments(ctx, tx, fresh.ChatID, fresh.AttachmentIDs); err != nil {
return nil, err
}
if _, err := tx.Exec(ctx, `
INSERT INTO messages (id, chat_id, sender_id, text, created_at)
VALUES ($1::uuid, $2::uuid, $3::uuid, $4, $5)
@@ -122,6 +125,10 @@ func (r *MessageRepo) CreateIdempotent(
return nil, mapError(err)
}
if err := r.linkAttachments(ctx, tx, fresh.ID, fresh.AttachmentIDs); err != nil {
return nil, err
}
if err := tx.Commit(ctx); err != nil {
return nil, mapError(err)
}