парсер новый

This commit is contained in:
Artem Tsyrulnikov
2026-02-04 14:54:25 +03:00
parent 6fc6a60bce
commit d15f2d2bad
6 changed files with 187 additions and 10 deletions

View File

@@ -10,6 +10,59 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
func (d *Database) UpdateChannelIfNotAccessible(ctx context.Context, channel domain.Channel) error {
query := `UPDATE channel
SET telegram_id = $2,
username = $3,
title = $4,
access_hash = $5,
pts = 0,
is_accessible = TRUE,
invite_link = $6,
updated_at = CURRENT_TIMESTAMP
WHERE telegram_id = $1
AND is_accessible = FALSE;`
txOrPool := transaction.TryExtractTX(ctx)
username := strings.TrimSpace(channel.Username)
var usernameDTO pgtype.Text
if username != "" {
usernameDTO = pgtype.Text{String: username, Valid: true}
} else {
usernameDTO = pgtype.Text{Valid: false}
}
inviteLink := strings.TrimSpace(channel.InviteLink)
var inviteLinkDTO pgtype.Text
if inviteLink != "" {
inviteLinkDTO = pgtype.Text{String: inviteLink, Valid: true}
} else {
inviteLinkDTO = pgtype.Text{Valid: false}
}
result, err := txOrPool.Exec(ctx, query,
channel.TelegramID,
pgtype.Int8{Int64: channel.TelegramID, Valid: true},
usernameDTO,
pgtype.Text{String: channel.Title, Valid: true},
pgtype.Int8{Int64: channel.AccessHash, Valid: true},
inviteLinkDTO,
)
if err != nil {
return fmt.Errorf("txOrPool.Exec: %w", err)
}
// Log if no rows were updated (channel either doesn't exist or is already accessible)
rowsAffected := result.RowsAffected()
if rowsAffected == 0 {
// Channel doesn't exist or is already accessible - this is fine
return nil
}
return nil
}
func (d *Database) UpdateChannel(ctx context.Context, channel domain.Channel) error {
query := `UPDATE channel
SET telegram_id = $2,