feat(postgres):lab4 wire validate and link attachments into CreateIdempotent
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user