server

package
v0.0.0-...-35fcc39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClassificationRepo

type ClassificationRepo interface {
	GetClassifiedItems(ctx context.Context, filter *domain.ItemFilter) ([]*domain.ClassifiedItem, error)
	GetClassifiedItemsCount(ctx context.Context, filter *domain.ItemFilter) (int, error)
	GetClassifiedItem(ctx context.Context, itemID int64) (*domain.ClassifiedItem, error)
	UpdateItemFeedback(ctx context.Context, itemID int64, feedback *domain.Feedback) error
	GetTopics(ctx context.Context) ([]string, error)
	GetTopicsFiltered(ctx context.Context, minScore float64) ([]string, error)
	GetTopTopicsByScore(ctx context.Context, minScore float64, limit int) ([]repository.TopicWithScore, error)
	GetFeedbackCount(ctx context.Context) (int64, error)
	SearchItems(ctx context.Context, searchQuery string, filter *domain.ItemFilter) ([]*domain.ClassifiedItem, error)
	GetSearchItemsCount(ctx context.Context, searchQuery string, filter *domain.ItemFilter) (int, error)
}

ClassificationRepo defines the classification repository interface used by the adapter

type ConfigProvider

type ConfigProvider interface {
	GetServerConfig() (listen string, timeout time.Duration)
	GetFullConfig() *config.Config // returns the full config struct for display
}

ConfigProvider provides server configuration

type Database

type Database interface {
	GetFeeds(ctx context.Context) ([]domain.Feed, error)
	GetItems(ctx context.Context, limit, offset int) ([]domain.Item, error)
	GetClassifiedItems(ctx context.Context, minScore float64, topic string, limit int) ([]domain.ClassifiedItem, error)
	GetClassifiedItemsWithFilters(ctx context.Context, req domain.ArticlesRequest) ([]domain.ClassifiedItem, error)
	GetClassifiedItemsCount(ctx context.Context, req domain.ArticlesRequest) (int, error)
	GetClassifiedItem(ctx context.Context, itemID int64) (*domain.ClassifiedItem, error)
	UpdateItemFeedback(ctx context.Context, itemID int64, feedback string) error
	GetTopics(ctx context.Context) ([]string, error)
	GetTopicsFiltered(ctx context.Context, minScore float64) ([]string, error)
	GetTopTopicsByScore(ctx context.Context, minScore float64, limit int) ([]domain.TopicWithScore, error)
	GetActiveFeedNames(ctx context.Context, minScore float64) ([]string, error)
	GetAllFeeds(ctx context.Context) ([]domain.Feed, error)
	CreateFeed(ctx context.Context, feed *domain.Feed) error
	UpdateFeed(ctx context.Context, feedID int64, title string, fetchInterval time.Duration) error
	UpdateFeedStatus(ctx context.Context, feedID int64, enabled bool) error
	DeleteFeed(ctx context.Context, feedID int64) error
	GetSetting(ctx context.Context, key string) (string, error)
	SetSetting(ctx context.Context, key, value string) error
	SearchItems(ctx context.Context, searchQuery string, req domain.ArticlesRequest) ([]domain.ClassifiedItem, error)
	GetSearchItemsCount(ctx context.Context, searchQuery string, req domain.ArticlesRequest) (int, error)
}

Database interface for server operations

type FeedRepo

type FeedRepo interface {
	GetFeeds(ctx context.Context, enabledOnly bool) ([]domain.Feed, error)
	CreateFeed(ctx context.Context, feed *domain.Feed) error
	UpdateFeed(ctx context.Context, feedID int64, title string, fetchInterval time.Duration) error
	UpdateFeedStatus(ctx context.Context, feedID int64, enabled bool) error
	DeleteFeed(ctx context.Context, feedID int64) error
	GetActiveFeedNames(ctx context.Context, minScore float64) ([]string, error)
}

FeedRepo defines the feed repository interface used by the adapter

type ItemRepo

type ItemRepo interface {
	GetItems(ctx context.Context, limit int, minScore float64) ([]domain.Item, error)
}

ItemRepo defines the item repository interface used by the adapter

type RepositoryAdapter

type RepositoryAdapter struct {
	// contains filtered or unexported fields
}

RepositoryAdapter adapts repositories to server.Database interface

func NewRepositoryAdapter

func NewRepositoryAdapter(repos *repository.Repositories) *RepositoryAdapter

NewRepositoryAdapter creates a new repository adapter from concrete repositories

func NewRepositoryAdapterWithInterfaces

func NewRepositoryAdapterWithInterfaces(feedRepo FeedRepo, itemRepo ItemRepo, classificationRepo ClassificationRepo, settingRepo SettingRepo) *RepositoryAdapter

NewRepositoryAdapterWithInterfaces creates a new repository adapter with interface dependencies for testing

func (*RepositoryAdapter) CreateFeed

func (r *RepositoryAdapter) CreateFeed(ctx context.Context, feed *domain.Feed) error

CreateFeed adds a new feed

func (*RepositoryAdapter) DeleteFeed

func (r *RepositoryAdapter) DeleteFeed(ctx context.Context, feedID int64) error

DeleteFeed removes a feed

func (*RepositoryAdapter) GetActiveFeedNames

func (r *RepositoryAdapter) GetActiveFeedNames(ctx context.Context, minScore float64) ([]string, error)

GetActiveFeedNames returns names of feeds that have classified articles

func (*RepositoryAdapter) GetAllFeeds

func (r *RepositoryAdapter) GetAllFeeds(ctx context.Context) ([]domain.Feed, error)

GetAllFeeds returns all feeds with full details

func (*RepositoryAdapter) GetClassifiedItem

func (r *RepositoryAdapter) GetClassifiedItem(ctx context.Context, itemID int64) (*domain.ClassifiedItem, error)

GetClassifiedItem returns a single item with classification data

func (*RepositoryAdapter) GetClassifiedItems

func (r *RepositoryAdapter) GetClassifiedItems(ctx context.Context, minScore float64, topic string, limit int) ([]domain.ClassifiedItem, error)

GetClassifiedItems returns items with classification data

func (*RepositoryAdapter) GetClassifiedItemsCount

func (r *RepositoryAdapter) GetClassifiedItemsCount(ctx context.Context, req domain.ArticlesRequest) (int, error)

GetClassifiedItemsCount returns total count of classified items matching filters

func (*RepositoryAdapter) GetClassifiedItemsWithFilters

func (r *RepositoryAdapter) GetClassifiedItemsWithFilters(ctx context.Context, req domain.ArticlesRequest) ([]domain.ClassifiedItem, error)

GetClassifiedItemsWithFilters returns items with classification data filtered by topic and feed

func (*RepositoryAdapter) GetFeedbackCount

func (r *RepositoryAdapter) GetFeedbackCount(ctx context.Context) (int64, error)

GetFeedbackCount returns the total number of feedback items

func (*RepositoryAdapter) GetFeeds

func (r *RepositoryAdapter) GetFeeds(ctx context.Context) ([]domain.Feed, error)

GetFeeds returns all feeds from repository

func (*RepositoryAdapter) GetItems

func (r *RepositoryAdapter) GetItems(ctx context.Context, limit, _ int) ([]domain.Item, error)

GetItems returns items from repository

func (*RepositoryAdapter) GetSearchItemsCount

func (r *RepositoryAdapter) GetSearchItemsCount(ctx context.Context, searchQuery string, req domain.ArticlesRequest) (int, error)

GetSearchItemsCount returns the total count of items matching the search query

func (*RepositoryAdapter) GetSetting

func (r *RepositoryAdapter) GetSetting(ctx context.Context, key string) (string, error)

GetSetting retrieves a setting value by key

func (*RepositoryAdapter) GetTopTopicsByScore

func (r *RepositoryAdapter) GetTopTopicsByScore(ctx context.Context, minScore float64, limit int) ([]domain.TopicWithScore, error)

GetTopTopicsByScore returns topics ordered by average relevance score

func (*RepositoryAdapter) GetTopics

func (r *RepositoryAdapter) GetTopics(ctx context.Context) ([]string, error)

GetTopics returns all unique topics from classified items

func (*RepositoryAdapter) GetTopicsFiltered

func (r *RepositoryAdapter) GetTopicsFiltered(ctx context.Context, minScore float64) ([]string, error)

GetTopicsFiltered returns unique topics from items with score >= minScore

func (*RepositoryAdapter) SearchItems

func (r *RepositoryAdapter) SearchItems(ctx context.Context, searchQuery string, req domain.ArticlesRequest) ([]domain.ClassifiedItem, error)

SearchItems searches for items using full-text search

func (*RepositoryAdapter) SetSetting

func (r *RepositoryAdapter) SetSetting(ctx context.Context, key, value string) error

SetSetting stores a setting value

func (*RepositoryAdapter) UpdateFeed

func (r *RepositoryAdapter) UpdateFeed(ctx context.Context, feedID int64, title string, fetchInterval time.Duration) error

UpdateFeed updates feed title and interval

func (*RepositoryAdapter) UpdateFeedStatus

func (r *RepositoryAdapter) UpdateFeedStatus(ctx context.Context, feedID int64, enabled bool) error

UpdateFeedStatus enables or disables a feed

func (*RepositoryAdapter) UpdateItemFeedback

func (r *RepositoryAdapter) UpdateItemFeedback(ctx context.Context, itemID int64, feedback string) error

UpdateItemFeedback updates user feedback for an item

type Scheduler

type Scheduler interface {
	UpdateFeedNow(ctx context.Context, feedID int64) error
	ExtractContentNow(ctx context.Context, itemID int64) error
	UpdatePreferenceSummary(ctx context.Context) error
	TriggerPreferenceUpdate()
}

Scheduler interface for on-demand operations

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents HTTP server instance

func New

func New(cfg ConfigProvider, database Database, scheduler Scheduler, version string, debug bool) *Server

New initializes a new server instance

func (*Server) GetPageSize

func (s *Server) GetPageSize() int

GetPageSize returns the configured page size for pagination

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run starts the HTTP server and handles graceful shutdown

type SettingRepo

type SettingRepo interface {
	GetSetting(ctx context.Context, key string) (string, error)
	SetSetting(ctx context.Context, key, value string) error
}

SettingRepo defines the setting repository interface used by the adapter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL