feed

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Feed
	ErrFeedNotFound             error = errors.New("feed: not found")
	ErrFeedSlugInvalid          error = errors.New("feed: invalid slug")
	ErrFeedSlugRequired         error = errors.New("feed: slug required")
	ErrFeedTitleRequired        error = errors.New("feed: title required")
	ErrFeedUUIDInvalid          error = errors.New("feed: invalid UUID")
	ErrFeedUUIDRequired         error = errors.New("feed: UUID required")
	ErrFeedURLInvalid           error = errors.New("feed: invalid URL")
	ErrFeedURLNoScheme          error = errors.New("feed: missing URL scheme")
	ErrFeedURLNoHost            error = errors.New("feed: missing URL host")
	ErrFeedURLRequired          error = errors.New("feed: URL required")
	ErrFeedURLUnsupportedScheme error = errors.New("feed: unsupported URL scheme")

	// Feed Category
	ErrCategoryAlreadyRegistered error = errors.New("category: already registered")
	ErrCategoryNameRequired      error = errors.New("category: name required")
	ErrCategoryNotFound          error = errors.New("category: Not Found")
	ErrCategorySlugInvalid       error = errors.New("category: invalid slug")
	ErrCategorySlugRequired      error = errors.New("category: slug required")
	ErrCategoryUserUUIDRequired  error = errors.New("category: UserUUID required")
	ErrCategoryUUIDInvalid       error = errors.New("category: invalid UUID")
	ErrCategoryUUIDRequired      error = errors.New("category: UUID required")

	// Feed Entry
	ErrEntryNotFound             error = errors.New("entry: not found")
	ErrEntryTitleRequired        error = errors.New("entry: title required")
	ErrEntryURLInvalid           error = errors.New("entry: invalid URL")
	ErrEntryURLNoScheme          error = errors.New("entry: missing URL scheme")
	ErrEntryURLNoHost            error = errors.New("entry: missing URL host")
	ErrEntryURLRequired          error = errors.New("entry: URL required")
	ErrEntryURLUnsupportedScheme error = errors.New("entry: unsupported URL scheme")
	ErrEntryUUIDInvalid          error = errors.New("entry: invalid UUID")

	// Feed Entry Metadata
	ErrEntryMetadataNotFound error = errors.New("entry-metadata: not found")

	// Feed Subscription
	ErrSubscriptionAlreadyRegistered error = errors.New("subscription: already registered")
	ErrSubscriptionNotFound          error = errors.New("subscription: not found")
	ErrSubscriptionUUIDRequired      error = errors.New("subscription: UUID required")

	// Feed user
	ErrUserUUIDRequired error = errors.New("user: UUID required")
)

Functions

This section is empty.

Types

type Category

type Category struct {
	UUID     string
	UserUUID string

	Name string
	Slug string

	CreatedAt time.Time
	UpdatedAt time.Time
}

Categories allow users to group feed subscriptions.

func NewCategory

func NewCategory(userUUID string, name string) (Category, error)

NewCategory initializes and returns a new feed category.

func (*Category) Normalize

func (c *Category) Normalize()

Normalize sanitizes and normalizes all fields.

func (*Category) ValidateForAddition

func (c *Category) ValidateForAddition(v ValidationRepository) error

ValidateForAddition ensures mandatory fields are properly set when adding a Category.

func (*Category) ValidateForDeletion

func (c *Category) ValidateForDeletion(v ValidationRepository) error

ValidateForDeletion ensures mandatory fields are properly set when deleting a Category.

func (*Category) ValidateForUpdate

func (c *Category) ValidateForUpdate(v ValidationRepository) error

ValidateForUpdate ensures mandatory fields are properly set when editing a Category.

type Entry

type Entry struct {
	UID      string
	FeedUUID string

	URL   string
	Title string

	PublishedAt time.Time
	UpdatedAt   time.Time
}

Entry represents an entry of a syndication feed (Atom or RSS).

func NewEntry

func NewEntry(feedUUID string, URL string, Title string, PublishedAt time.Time, UpdatedAt time.Time) Entry

NewEntry creates and initializes a new Entry

func NewEntryFromItem

func NewEntryFromItem(feedUUID string, now time.Time, item *gofeed.Item) Entry

NewEntryFromItem creates and initializes a new Entry from a gofeed.Item.

func (*Entry) Normalize

func (e *Entry) Normalize()

Normalize sanitizes and normalizes all fields.

func (*Entry) ValidateForAddition

func (e *Entry) ValidateForAddition() error

ValidateForAddition ensures mandatory fields are properly set when adding an new Entry.

type EntryMetadata

type EntryMetadata struct {
	UserUUID string
	EntryUID string

	Read bool
}

EntryMetadata tracks user-specific metadata for a given feed entry.

type FakeRepository

type FakeRepository struct {
	Categories      []Category
	Entries         []Entry
	EntriesMetadata []EntryMetadata
	Feeds           []Feed
	Subscriptions   []Subscription
}

func (*FakeRepository) FeedCategoryCreate

func (r *FakeRepository) FeedCategoryCreate(category Category) error

func (*FakeRepository) FeedCategoryDelete

func (r *FakeRepository) FeedCategoryDelete(userUUID string, categoryUUID string) error

func (*FakeRepository) FeedCategoryGetByName

func (r *FakeRepository) FeedCategoryGetByName(userUUID string, name string) (Category, error)

func (*FakeRepository) FeedCategoryGetBySlug

func (r *FakeRepository) FeedCategoryGetBySlug(userUUID string, slug string) (Category, error)

func (*FakeRepository) FeedCategoryGetByUUID

func (r *FakeRepository) FeedCategoryGetByUUID(userUUID string, categoryUUID string) (Category, error)

func (*FakeRepository) FeedCategoryGetMany

func (r *FakeRepository) FeedCategoryGetMany(userUUID string) ([]Category, error)

func (*FakeRepository) FeedCategoryNameAndSlugAreRegistered

func (r *FakeRepository) FeedCategoryNameAndSlugAreRegistered(userUUID string, name string, slug string) (bool, error)

func (*FakeRepository) FeedCategoryNameAndSlugAreRegisteredToAnotherCategory

func (r *FakeRepository) FeedCategoryNameAndSlugAreRegisteredToAnotherCategory(userUUID string, categoryUUID string, name string, slug string) (bool, error)

func (*FakeRepository) FeedCategoryUpdate

func (r *FakeRepository) FeedCategoryUpdate(category Category) error

func (*FakeRepository) FeedCreate

func (r *FakeRepository) FeedCreate(feed Feed) error

func (*FakeRepository) FeedEntryCreateMany

func (r *FakeRepository) FeedEntryCreateMany(entries []Entry) (int64, error)

func (*FakeRepository) FeedEntryGetN

func (r *FakeRepository) FeedEntryGetN(feedUUID string, n uint) ([]Entry, error)

func (*FakeRepository) FeedEntryMarkAllAsRead

func (r *FakeRepository) FeedEntryMarkAllAsRead(userUUID string) error

func (*FakeRepository) FeedEntryMarkAllAsReadByCategory

func (r *FakeRepository) FeedEntryMarkAllAsReadByCategory(userUUID string, categoryUUID string) error

func (*FakeRepository) FeedEntryMarkAllAsReadBySubscription

func (r *FakeRepository) FeedEntryMarkAllAsReadBySubscription(userUUID string, subscriptionUUID string) error

func (*FakeRepository) FeedEntryMetadataCreate

func (r *FakeRepository) FeedEntryMetadataCreate(newEntryMetadata EntryMetadata) error

func (*FakeRepository) FeedEntryMetadataGetByUID

func (r *FakeRepository) FeedEntryMetadataGetByUID(userUUID string, entryUID string) (EntryMetadata, error)

func (*FakeRepository) FeedEntryMetadataUpdate

func (r *FakeRepository) FeedEntryMetadataUpdate(updatedEntryMetadata EntryMetadata) error

func (*FakeRepository) FeedGetBySlug

func (r *FakeRepository) FeedGetBySlug(feedSlug string) (Feed, error)

func (*FakeRepository) FeedGetByURL

func (r *FakeRepository) FeedGetByURL(feedURL string) (Feed, error)

func (*FakeRepository) FeedSubscriptionCreate

func (r *FakeRepository) FeedSubscriptionCreate(subscription Subscription) (Subscription, error)

func (*FakeRepository) FeedSubscriptionDelete

func (r *FakeRepository) FeedSubscriptionDelete(userUUID string, subscriptionUUID string) error

func (*FakeRepository) FeedSubscriptionGetByFeed

func (r *FakeRepository) FeedSubscriptionGetByFeed(userUUID string, feedUUID string) (Subscription, error)

func (*FakeRepository) FeedSubscriptionGetByUUID

func (r *FakeRepository) FeedSubscriptionGetByUUID(userUUID string, subscriptionUUID string) (Subscription, error)

func (*FakeRepository) FeedSubscriptionIsRegistered

func (r *FakeRepository) FeedSubscriptionIsRegistered(userUUID string, feedUUID string) (bool, error)

func (*FakeRepository) FeedSubscriptionUpdate

func (r *FakeRepository) FeedSubscriptionUpdate(subscription Subscription) error

type Feed

type Feed struct {
	UUID string

	FeedURL string
	Title   string
	Slug    string

	ETag         string
	LastModified time.Time

	CreatedAt time.Time
	UpdatedAt time.Time
	FetchedAt time.Time
}

Feed represents a Web syndication feed (Atom or RSS).

func NewFeed

func NewFeed(feedURL string) (Feed, error)

NewFeed initializes and returns a new Feed.

func (*Feed) Normalize

func (f *Feed) Normalize()

Normalize sanitizes and normalizes all fields.

func (*Feed) ValidateForCreation

func (f *Feed) ValidateForCreation() error

ValidateForCreation ensures mandatory fields are set when creating a new Feed.

func (*Feed) ValidateSlug

func (f *Feed) ValidateSlug() error

ValidateSlug ensures the slug is normalized and valid.

func (*Feed) ValidateURL

func (f *Feed) ValidateURL() error

ValidateURL validates the URL is properly formed and uses a supported scheme.

type Repository

type Repository interface {
	ValidationRepository

	// FeedCreate creates a new Feed.
	FeedCreate(feed Feed) error

	// FeedGetBySlug returns the Feed for a given slug.
	FeedGetBySlug(feedSlug string) (Feed, error)

	// FeedGetByURL returns the Feed for a given URL.
	FeedGetByURL(feedURL string) (Feed, error)

	// FeedCategoryCreate creates a new Category.
	FeedCategoryCreate(category Category) error

	// FeedCategoryDelete deletes an existing Category and related Subscriptions.
	FeedCategoryDelete(userUUID string, categoryUUID string) error

	// FeedCategoryGetByName returns the Category for a given user and name.
	FeedCategoryGetByName(userUUID string, name string) (Category, error)

	// FeedCategoryGetBySlug returns the Category for a given user and slug.
	FeedCategoryGetBySlug(userUUID string, slug string) (Category, error)

	// FeedCategoryGetByUUID returns the Category for a given user and UUID.
	FeedCategoryGetByUUID(userUUID string, categoryUUID string) (Category, error)

	// FeedCategoryGetMany returns all categories for a giver user.
	FeedCategoryGetMany(userUUID string) ([]Category, error)

	// FeedCategoryUpdate updates an existing Category.
	FeedCategoryUpdate(category Category) error

	// FeedEntryCreateMany creates a collection of new Entries.
	FeedEntryCreateMany(entries []Entry) (int64, error)

	// FeedEntryGetN returns at most N entries for a given Feed.
	FeedEntryGetN(feedUUID string, n uint) ([]Entry, error)

	// FeedEntryMarkAllAsRead marks all entries as "read" for a given User.
	FeedEntryMarkAllAsRead(userUUID string) error

	// FeedEntryMarkAllAsReadByCategory marks all entries as "read" for a given User and Category.
	FeedEntryMarkAllAsReadByCategory(userUUID string, categoryUUID string) error

	// FeedEntryMarkAllAsReadBySubscription marks all entries as "read" for a given User and Subscription.
	FeedEntryMarkAllAsReadBySubscription(userUUID string, subscriptionUUID string) error

	// FeedEntryMetadataCreate creates a new EntryStatus.
	FeedEntryMetadataCreate(entryMetadata EntryMetadata) error

	// FeedEntryMetadataGetByUID returns the EntryStatus for a given user and Entry.
	FeedEntryMetadataGetByUID(userUUID string, entryUID string) (EntryMetadata, error)

	// FeedEntryMetadataUpdate updates an existing EntryStatus.
	FeedEntryMetadataUpdate(entryMetadata EntryMetadata) error

	// FeedSubscriptionCreate creates a new Feed subscription for a given user.
	FeedSubscriptionCreate(subscription Subscription) (Subscription, error)

	// FeedSubscriptionDelete deletes a given Feed subscription.
	FeedSubscriptionDelete(userUUID string, subscriptionUUID string) error

	// FeedSubscriptionGetByFeed returns the Subscription for a given user and feed.
	FeedSubscriptionGetByFeed(userUUID string, feedUUID string) (Subscription, error)

	// FeedSubscriptionGetByUUID returns the Subscription for a given user and UUID.
	FeedSubscriptionGetByUUID(userUUID string, subscriptionUUID string) (Subscription, error)

	// FeedSubscriptionUpdate updates an existing Subscription.
	FeedSubscriptionUpdate(subscription Subscription) error
}

Repository provides access to user feeds.

type Service

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

Service handles operations for the feed domain.

func NewService

func NewService(r Repository, client *fetching.Client) *Service

NewService initializes and returns a Feed Service.

func (*Service) Categories

func (s *Service) Categories(userUUID string) ([]Category, error)

Categories returns all categories for a given user.

func (*Service) CategoryBySlug

func (s *Service) CategoryBySlug(userUUID string, slug string) (Category, error)

CategoryBySlug returns the category for a given user and slug.

func (*Service) CategoryByUUID

func (s *Service) CategoryByUUID(userUUID string, categoryUUID string) (Category, error)

CategoryByUUID returns the category for a given user and UUID.

func (*Service) CreateCategory

func (s *Service) CreateCategory(userUUID string, name string) (Category, error)

CreateCategory creates a new Category for a given User.

func (*Service) DeleteCategory

func (s *Service) DeleteCategory(userUUID string, categoryUUID string) error

DeleteCategory deletes a Category, related Subscriptions and EntryStatuses.

func (*Service) DeleteSubscription

func (s *Service) DeleteSubscription(userUUID string, subscriptionUUID string) error

func (*Service) FeedBySlug

func (s *Service) FeedBySlug(userUUID string, slug string) (Feed, error)

FeedBySlug returns the Feed for a given slug.

func (*Service) GetOrCreateCategory

func (s *Service) GetOrCreateCategory(userUUID string, name string) (Category, bool, error)

GetOrCreateCategory returns an existing Category or creates it.

func (*Service) GetOrCreateFeedAndEntries

func (s *Service) GetOrCreateFeedAndEntries(feedURL string) (Feed, bool, error)

GetOrCreateFeedAndEntries returns an existing feed, or creates it (along with its entries).

func (*Service) GetOrCreateSubscription

func (s *Service) GetOrCreateSubscription(newSubscription Subscription) (Subscription, bool, error)

GetOrCreateSubscription returns an existing subscription or creates it.

func (*Service) MarkAllEntriesAsRead

func (s *Service) MarkAllEntriesAsRead(userUUID string) error

MarkAllEntriesAsRead marks all entries as "read" for a given User.

func (*Service) MarkAllEntriesAsReadByCategory

func (s *Service) MarkAllEntriesAsReadByCategory(userUUID string, categoryUUID string) error

MarkAllEntriesAsReadByCategory marks all entries as "read" for a given User and Category.

func (*Service) MarkAllEntriesAsReadBySubscription

func (s *Service) MarkAllEntriesAsReadBySubscription(userUUID string, subscriptionUUID string) error

MarkAllEntriesAsReadBySubscription marks all entries as "read" for a given User and Subscription.

func (*Service) Subscribe

func (s *Service) Subscribe(userUUID string, categoryUUID string, feedURL string) error

Subscribe creates a new Feed if needed, and creates the corresponding Subscription for a given user.

func (*Service) SubscriptionByFeed

func (s *Service) SubscriptionByFeed(userUUID string, feedUUID string) (Subscription, error)

func (*Service) ToggleEntryRead

func (s *Service) ToggleEntryRead(userUUID string, entryUID string) error

ToggleEntryRead toggles the "read" status for a given User and Entry.

func (*Service) UpdateCategory

func (s *Service) UpdateCategory(category Category) error

UpdateCategory updates an existing Category.

func (*Service) UpdateSubscription

func (s *Service) UpdateSubscription(subscription Subscription) error

type Subscription

type Subscription struct {
	UUID         string
	CategoryUUID string
	FeedUUID     string
	UserUUID     string

	CreatedAt time.Time
	UpdatedAt time.Time
}

Subscription represents a given user's subscription to a Feed.

func NewSubscription

func NewSubscription(categoryUUID string, feedUUID string, userUUID string) (Subscription, error)

NewSubscription initializes and returns a new Subscription.

func (*Subscription) ValidateForCreation

func (s *Subscription) ValidateForCreation(v ValidationRepository) error

type ValidationRepository

type ValidationRepository interface {
	// FeedCategoryNameAndSlugAreRegistered returns whether a user has already registered
	// a Category with the same name or slug.
	FeedCategoryNameAndSlugAreRegistered(userUUID string, name string, slug string) (bool, error)

	// FeedCategoryNameAndSlugAreRegistered returns whether a user has already registered
	// another Category with the same name or slug.
	FeedCategoryNameAndSlugAreRegisteredToAnotherCategory(userUUID string, categoryUUID string, name string, slug string) (bool, error)

	// FeedSubscriptionIsRegistered returns whether a user has already registered
	// a Subscription to a given Feed.
	FeedSubscriptionIsRegistered(userUUID string, feedUUID string) (bool, error)
}

ValidationRepository provides methods for Feed and Subscription validation.

Directories

Path Synopsis
Package fetching provides a HTTP Client to fetch syndication feeds from remote servers.
Package fetching provides a HTTP Client to fetch syndication feeds from remote servers.

Jump to

Keyboard shortcuts

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