38 lines
848 B
Go
38 lines
848 B
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
|
|
"github.com/TelegramExchange/pkg/transaction"
|
|
"github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain"
|
|
)
|
|
|
|
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
|
|
}
|