ручное парсер

This commit is contained in:
Artem Tsyrulnikov
2026-02-04 13:38:03 +03:00
parent 09145e510a
commit 6fc6a60bce
10 changed files with 145 additions and 110 deletions

View File

@@ -11,19 +11,21 @@ import (
)
func (d *Database) GetChannelsWithTrackedPosts(ctx context.Context) ([]domain.Channel, error) {
query := `SELECT DISTINCT
query := `SELECT DISTINCT
c.id,
c.telegram_id,
c.username,
c.title,
c.access_hash,
c.pts,
c.invite_link
c.invite_link,
c.is_accessible
FROM channel c
INNER JOIN placement p ON p.channel_id = c.id
INNER JOIN placement_post pp ON pp.placement_id = p.id
INNER JOIN post po ON po.id = pp.post_id
WHERE po.deleted_from_channel_at IS NULL;`
WHERE po.deleted_from_channel_at IS NULL
AND c.is_accessible = true;`
txOrPool := transaction.TryExtractTX(ctx)
@@ -50,13 +52,14 @@ WHERE po.deleted_from_channel_at IS NULL;`
}
type getChannelsWithTrackedPostsDTO struct {
ID pgtype.UUID
TelegramID pgtype.Int8
Username pgtype.Text
Title pgtype.Text
AccessHash pgtype.Int8
Pts pgtype.Int4
InviteLink pgtype.Text
ID pgtype.UUID
TelegramID pgtype.Int8
Username pgtype.Text
Title pgtype.Text
AccessHash pgtype.Int8
Pts pgtype.Int4
InviteLink pgtype.Text
IsAccessible pgtype.Bool
}
func (dto *getChannelsWithTrackedPostsDTO) destination() []any {
@@ -68,17 +71,19 @@ func (dto *getChannelsWithTrackedPostsDTO) destination() []any {
&dto.AccessHash,
&dto.Pts,
&dto.InviteLink,
&dto.IsAccessible,
}
}
func (dto *getChannelsWithTrackedPostsDTO) toDomain() domain.Channel {
return domain.Channel{
ID: dto.ID.Bytes,
TelegramID: domain.NormalizeChatID(dto.TelegramID.Int64),
Username: dto.Username.String,
Title: dto.Title.String,
AccessHash: dto.AccessHash.Int64,
Pts: int(dto.Pts.Int32),
InviteLink: dto.InviteLink.String,
ID: dto.ID.Bytes,
TelegramID: domain.NormalizeChatID(dto.TelegramID.Int64),
Username: dto.Username.String,
Title: dto.Title.String,
AccessHash: dto.AccessHash.Int64,
Pts: int(dto.Pts.Int32),
InviteLink: dto.InviteLink.String,
IsAccessible: dto.IsAccessible.Bool,
}
}

View File

@@ -5,11 +5,9 @@ import (
"fmt"
"strings"
"github.com/jackc/pgx/v5/pgtype"
"github.com/rs/zerolog/log"
"github.com/TelegramExchange/pkg/transaction"
"github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain"
"github.com/jackc/pgx/v5/pgtype"
)
func (d *Database) UpdateChannel(ctx context.Context, channel domain.Channel) error {
@@ -42,15 +40,6 @@ WHERE id = $1;`
inviteLinkDTO = pgtype.Text{Valid: false}
}
// Log warning if both identity fields are empty (will violate CHECK constraint)
if !usernameDTO.Valid && !inviteLinkDTO.Valid {
log.Warn().
Str("channel_id", channel.ID.String()).
Int64("telegram_id", channel.TelegramID).
Str("title", channel.Title).
Msg("UpdateChannel: both username and invite_link are empty, this may violate CHECK constraint")
}
dto := updateChannelDTO{
ID: pgtype.UUID{Bytes: channel.ID, Valid: true},
TelegramID: pgtype.Int8{Int64: channel.TelegramID, Valid: true},