Documentation ¶
Index ¶
- Variables
- type Repository
- type RepositoryInMemory
- func (r *RepositoryInMemory) SubmissionCreate(submission *Submission) error
- func (r *RepositoryInMemory) SubmissionGetByID(id int) (*Submission, error)
- func (r *RepositoryInMemory) SubmissionGetByMinResolution(minResolution *monitor.Resolution) ([]*Submission, error)
- func (r *RepositoryInMemory) SubmissionGetByPostID(postID string) (*Submission, error)
- func (r *RepositoryInMemory) SubmissionGetRandom(minResolution *monitor.Resolution) (*Submission, error)
- func (r *RepositoryInMemory) SubmissionIsPostIDRegistered(postID string) (bool, error)
- func (r *RepositoryInMemory) SubmissionSearch(text string) ([]*Submission, error)
- func (r *RepositoryInMemory) SubredditCreate(subreddit *Subreddit) error
- func (r *RepositoryInMemory) SubredditGetAll() ([]*Subreddit, error)
- func (r *RepositoryInMemory) SubredditGetByID(id int) (*Subreddit, error)
- func (r *RepositoryInMemory) SubredditGetByName(name string) (*Subreddit, error)
- func (r *RepositoryInMemory) SubredditGetStats() ([]SubredditStats, error)
- func (r *RepositoryInMemory) SubredditIsNameRegistered(name string) (bool, error)
- type Service
- func (s *Service) ByID(id int) (*Submission, error)
- func (s *Service) ByMinResolution(minResolution *monitor.Resolution) ([]*Submission, error)
- func (s *Service) ByPostID(postID string) (*Submission, error)
- func (s *Service) Create(submission *Submission) error
- func (s *Service) Random(minResolution *monitor.Resolution) (*Submission, error)
- func (s *Service) Search(text string) ([]*Submission, error)
- func (s *Service) Stats() ([]SubredditStats, error)
- func (s *Service) SubredditByName(name string) (*Subreddit, error)
- func (s *Service) SubredditCreate(sr *Subreddit) error
- func (s *Service) SubredditGetOrCreateByName(name string) (*Subreddit, error)
- type Submission
- type Subreddit
- type SubredditStats
- type ValidationRepository
Constants ¶
This section is empty.
Variables ¶
var ( ErrSubmissionIDInvalid error = errors.New("submission: invalid ID") ErrSubmissionNotFound error = errors.New("submission: not found") ErrSubmissionPostIDAlreadyRegistered error = errors.New("submission: post ID already registered") ErrSubmissionPostIDEmpty error = errors.New("submission: empty post ID") ErrSubmissionSearchTextEmpty error = errors.New("submission: empty search text") ErrSubmissionTitleEmpty error = errors.New("submission: empty title") ErrSubredditIDInvalid error = errors.New("subreddit: invalid ID") ErrSubredditNameAlreadyRegistered error = errors.New("subreddit: name already registered") ErrSubredditNameEmpty error = errors.New("subreddit: empty name") ErrSubredditNotFound error = errors.New("subreddit: not found") )
Functions ¶
This section is empty.
Types ¶
type Repository ¶
type Repository interface { ValidationRepository // SubmissionGetByID returns the Submission for a given ID. SubmissionGetByID(id int) (*Submission, error) // SubmissionGetByMinResolution returns all Submissions whose attached image's resolution // is greater or equal to the specified constraints. SubmissionGetByMinResolution(minResolution *monitor.Resolution) ([]*Submission, error) // SubmissionGetByPostID returns the Submission for a given Reddit post ID. SubmissionGetByPostID(postID string) (*Submission, error) // SubmissionSearch returns all submissions whose title contains the specified text. // The search SHOULD BE case-insensitive. SubmissionSearch(text string) ([]*Submission, error) // SubmissionGetRandom returns a randomly selected Submission whose attached image's // resolution is greater or equal to the specified constraints. // The Submission SHOULD NOT already be present in the History. SubmissionGetRandom(minResolution *monitor.Resolution) (*Submission, error) // SubmissionCreate creates and persists a Submission. SubmissionCreate(submission *Submission) error // SubredditGetAll returns all persisted Subreddits. SubredditGetAll() ([]*Subreddit, error) // SubredditGetStats returns the aggregated usage statistics for all Subreddits. SubredditGetStats() ([]SubredditStats, error) // SubredditGetByID returns the Subreddit for a given ID. SubredditGetByID(id int) (*Subreddit, error) // SubredditGetByName returns the Subreddit for a given Name. SubredditGetByName(name string) (*Subreddit, error) // SubredditCreate creates and persists a Subreddit. SubredditCreate(subreddit *Subreddit) error }
Repository defines the basic operations available to access and persist Reddit Submissions.
type RepositoryInMemory ¶
type RepositoryInMemory struct {
// contains filtered or unexported fields
}
repositoryInMemory provides an in-memory Repository for testing.
func NewRepositoryInMemory ¶
func NewRepositoryInMemory(submissions []*Submission, subreddits []*Subreddit) *RepositoryInMemory
func (*RepositoryInMemory) SubmissionCreate ¶
func (r *RepositoryInMemory) SubmissionCreate(submission *Submission) error
func (*RepositoryInMemory) SubmissionGetByID ¶
func (r *RepositoryInMemory) SubmissionGetByID(id int) (*Submission, error)
func (*RepositoryInMemory) SubmissionGetByMinResolution ¶
func (r *RepositoryInMemory) SubmissionGetByMinResolution(minResolution *monitor.Resolution) ([]*Submission, error)
func (*RepositoryInMemory) SubmissionGetByPostID ¶
func (r *RepositoryInMemory) SubmissionGetByPostID(postID string) (*Submission, error)
func (*RepositoryInMemory) SubmissionGetRandom ¶
func (r *RepositoryInMemory) SubmissionGetRandom(minResolution *monitor.Resolution) (*Submission, error)
func (*RepositoryInMemory) SubmissionIsPostIDRegistered ¶
func (r *RepositoryInMemory) SubmissionIsPostIDRegistered(postID string) (bool, error)
func (*RepositoryInMemory) SubmissionSearch ¶
func (r *RepositoryInMemory) SubmissionSearch(text string) ([]*Submission, error)
func (*RepositoryInMemory) SubredditCreate ¶
func (r *RepositoryInMemory) SubredditCreate(subreddit *Subreddit) error
func (*RepositoryInMemory) SubredditGetAll ¶
func (r *RepositoryInMemory) SubredditGetAll() ([]*Subreddit, error)
func (*RepositoryInMemory) SubredditGetByID ¶
func (r *RepositoryInMemory) SubredditGetByID(id int) (*Subreddit, error)
func (*RepositoryInMemory) SubredditGetByName ¶
func (r *RepositoryInMemory) SubredditGetByName(name string) (*Subreddit, error)
func (*RepositoryInMemory) SubredditGetStats ¶
func (r *RepositoryInMemory) SubredditGetStats() ([]SubredditStats, error)
func (*RepositoryInMemory) SubredditIsNameRegistered ¶
func (r *RepositoryInMemory) SubredditIsNameRegistered(name string) (bool, error)
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles domain operations for Submission and Subreddit management.
func NewService ¶
func NewService(repository Repository) *Service
NewService creates and initializes a Submission and Subreddit Service.
func (*Service) ByID ¶
func (s *Service) ByID(id int) (*Submission, error)
ByPostID returns the Submission matching a given ID.
func (*Service) ByMinResolution ¶
func (s *Service) ByMinResolution(minResolution *monitor.Resolution) ([]*Submission, error)
ByMinResolution returns all Submissions whose size is greater or equal to the provided minimum resolution.
func (*Service) ByPostID ¶
func (s *Service) ByPostID(postID string) (*Submission, error)
ByPostID returns the Submission matching a given post ID.
func (*Service) Create ¶
func (s *Service) Create(submission *Submission) error
Creates creates a new Submission.
func (*Service) Random ¶
func (s *Service) Random(minResolution *monitor.Resolution) (*Submission, error)
Random returns a randomly selected Submission with a size greater or equal to the provided minimum resolution.
func (*Service) Search ¶
func (s *Service) Search(text string) ([]*Submission, error)
Search returns all Submissions whose title match the search string.
func (*Service) Stats ¶
func (s *Service) Stats() ([]SubredditStats, error)
Stats returns statistics about how many Submissions were gathered per Subreddit.
func (*Service) SubredditByName ¶
SubredditByName returns the SUbreddit for a given name.
func (*Service) SubredditCreate ¶
SubredditCreate creates a new Subreddit.
type Submission ¶
type Submission struct { ID int Subreddit *Subreddit // Reddit post metadata Author string Permalink string PostID string PostedAt time.Time Score int Title string // Attached image metadata ImageDomain string ImageURL string ImageNSFW bool // Local image metadata ImageFilename string ImageHeightPx int ImageWidthPx int }
Submission represents the metadata for a Reddit post with an image attachment, and the metadata for the corresponding local file.
func (*Submission) Normalize ¶
func (s *Submission) Normalize()
Normalize sanitizes and normalizes all fields.
func (*Submission) PermalinkURL ¶
func (s *Submission) PermalinkURL() string
PermalinkURL returns the Reddit permalink for this submission's post.
func (*Submission) User ¶
func (s *Submission) User() string
User returns the Reddit-formatted username for this submission's author.
func (*Submission) ValidateForAddition ¶
func (s *Submission) ValidateForAddition(r ValidationRepository) error
ValidateForAddition ensures mandatory fields are properly set when adding an new Submission.
type Subreddit ¶
Subreddit represents a Reddit subreddit.
func (*Subreddit) Normalize ¶
func (sr *Subreddit) Normalize()
Normalize sanitizes and normalizes all fields.
func (*Subreddit) ValidateForAddition ¶
func (sr *Subreddit) ValidateForAddition(r ValidationRepository) error
ValidateForAddition ensures mandatory fields are properly set when adding an new Subreddit.
type SubredditStats ¶
SubredditStats holds the aggregated usage statistics for a given Subreddit.
type ValidationRepository ¶
type ValidationRepository interface { // SubmissionIsPostIDRegistered returns whether this Submission was previously saved. SubmissionIsPostIDRegistered(postID string) (bool, error) // SubredditIsNameRegistered returns whether this Subreddit was previously saved. SubredditIsNameRegistered(name string) (bool, error) }
ValidationRepository provides methods for Submission validation.