парсер
This commit is contained in:
37
tg_parser/internal/adapter/database/delete_post.go
Normal file
37
tg_parser/internal/adapter/database/delete_post.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
|
||||
"github.com/TelegramExchange/tgex-parser/internal/domain"
|
||||
"github.com/TelegramExchange/tgex-parser/pkg/transaction"
|
||||
)
|
||||
|
||||
func (d *Database) DeletePost(ctx context.Context, p domain.Post) error {
|
||||
query := `UPDATE post
|
||||
SET deleted_from_channel_at = CURRENT_TIMESTAMP,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE channel_id = $1 AND message_id = $2;`
|
||||
|
||||
txOrPool := transaction.TryExtractTX(ctx)
|
||||
|
||||
dto := deletePostDTO{
|
||||
ChannelID: pgtype.UUID{Bytes: p.ChannelID, Valid: true},
|
||||
MessageID: pgtype.Int4{Int32: int32(p.MessageID), Valid: true},
|
||||
}
|
||||
|
||||
_, err := txOrPool.Exec(ctx, query, dto.ChannelID, dto.MessageID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("txOrPool.Exec: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type deletePostDTO struct {
|
||||
ChannelID pgtype.UUID
|
||||
MessageID pgtype.Int4
|
||||
}
|
||||
Reference in New Issue
Block a user