42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package usecase
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain"
|
|
)
|
|
|
|
type Telegram interface {
|
|
ParseChannelMeta(ctx context.Context, username string) (domain.Channel, error)
|
|
ParseChannelMetaByInvite(ctx context.Context, inviteLink string) (domain.Channel, error)
|
|
GetChannelPTS(ctx context.Context, channel domain.Channel) (int, error)
|
|
GetChannelHistory(ctx context.Context, channel domain.Channel, limit int) ([]domain.Post, error)
|
|
GetChannelDiff(ctx context.Context, channel domain.Channel, limit int) (domain.ChannelDiff, error)
|
|
UpdatePostsViews(ctx context.Context, channel domain.Channel, posts []domain.Post) error
|
|
}
|
|
|
|
type Database interface {
|
|
CreatePost(ctx context.Context, post domain.Post) error
|
|
|
|
CreateViewsSnapshot(ctx context.Context, snapshot domain.ViewsSnapshot) error
|
|
|
|
UpdateChannelIfNotAccessible(ctx context.Context, channel domain.Channel) error
|
|
GetChannels(ctx context.Context) []domain.Channel
|
|
UpdateChannel(ctx context.Context, channel domain.Channel) error
|
|
GetChannelsWithTrackedPosts(ctx context.Context) ([]domain.Channel, error)
|
|
GetTrackedPosts(ctx context.Context, channel domain.Channel) ([]domain.Post, error)
|
|
DeletePost(ctx context.Context, p domain.Post) error
|
|
}
|
|
|
|
type UseCase struct {
|
|
telegram Telegram
|
|
database Database
|
|
}
|
|
|
|
func New(telegram Telegram, database Database) *UseCase {
|
|
return &UseCase{
|
|
telegram: telegram,
|
|
database: database,
|
|
}
|
|
}
|