время в топе и тэги креативов

This commit is contained in:
Artem Tsyrulnikov
2026-01-28 12:34:00 +03:00
parent 0b25566ffb
commit 484e52c077
26 changed files with 326 additions and 36 deletions

View File

@@ -11,22 +11,24 @@ import (
)
func (d *Database) CreatePost(ctx context.Context, post domain.Post) error {
query := `INSERT INTO post (id, channel_id, message_id, text)
VALUES ($1, $2, $3, $4)
query := `INSERT INTO post (id, channel_id, message_id, text, published_at)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (channel_id, message_id) DO UPDATE
SET text = EXCLUDED.text,
published_at = COALESCE(post.published_at, EXCLUDED.published_at),
updated_at = CURRENT_TIMESTAMP;`
txOrPool := transaction.TryExtractTX(ctx)
dto := createPostDTO{
ID: pgtype.UUID{Bytes: post.ID, Valid: true},
ChannelID: pgtype.UUID{Bytes: post.ChannelID, Valid: true},
MessageID: pgtype.Int4{Int32: int32(post.MessageID), Valid: true},
Text: pgtype.Text{String: post.Text, Valid: true},
ID: pgtype.UUID{Bytes: post.ID, Valid: true},
ChannelID: pgtype.UUID{Bytes: post.ChannelID, Valid: true},
MessageID: pgtype.Int4{Int32: int32(post.MessageID), Valid: true},
Text: pgtype.Text{String: post.Text, Valid: true},
PublishedAt: pgtype.Timestamptz{Time: post.PublishedAt, Valid: !post.PublishedAt.IsZero()},
}
_, err := txOrPool.Exec(ctx, query, dto.ID, dto.ChannelID, dto.MessageID, dto.Text)
_, err := txOrPool.Exec(ctx, query, dto.ID, dto.ChannelID, dto.MessageID, dto.Text, dto.PublishedAt)
if err != nil {
return fmt.Errorf("txOrPool.Exec: %w", err)
}
@@ -35,8 +37,9 @@ SET text = EXCLUDED.text,
}
type createPostDTO struct {
ID pgtype.UUID
ChannelID pgtype.UUID
MessageID pgtype.Int4
Text pgtype.Text
ID pgtype.UUID
ChannelID pgtype.UUID
MessageID pgtype.Int4
Text pgtype.Text
PublishedAt pgtype.Timestamptz
}

View File

@@ -3,6 +3,7 @@ package telegram
import (
"context"
"fmt"
"time"
"github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain"
"github.com/gotd/td/tg"
@@ -60,7 +61,8 @@ func extractPosts(channel domain.Channel, msgs []tg.MessageClass) []domain.Post
}
text := messageToHTML(m.Message, m.Entities)
p := domain.NewPost(channel, m.ID, text, m.Views)
publishedAt := time.Unix(int64(m.Date), 0).UTC()
p := domain.NewPost(channel, m.ID, text, m.Views, publishedAt)
posts = append(posts, p)
}
@@ -73,7 +75,7 @@ func extractDeletedPosts(channel domain.Channel, updates []tg.UpdateClass) []dom
for _, upd := range updates {
if u, ok := upd.(*tg.UpdateDeleteChannelMessages); ok {
for _, msgID := range u.Messages {
p := domain.NewPost(channel, msgID, "", 0)
p := domain.NewPost(channel, msgID, "", 0, time.Time{})
deleted = append(deleted, p)
}
}

View File

@@ -3,6 +3,7 @@ package telegram
import (
"context"
"fmt"
"time"
"github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain"
"github.com/gotd/td/tg"
@@ -39,7 +40,8 @@ func (t *Telegram) GetChannelHistory(ctx context.Context, channel domain.Channel
}
text := messageToHTML(m.Message, m.Entities)
p := domain.NewPost(channel, m.ID, text, m.Views)
publishedAt := time.Unix(int64(m.Date), 0).UTC()
p := domain.NewPost(channel, m.ID, text, m.Views, publishedAt)
placements = append(placements, p)
}