bookmark

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound                    error = errors.New("not found")
	ErrTagNameContainsWhitespace   error = errors.New("tag name contains whitespace")
	ErrTagNameRequired             error = errors.New("tag name required")
	ErrTagNewNameEqualsCurrentName error = errors.New("new tag name is the same as current tag name")
	ErrTitleRequired               error = errors.New("title required")
	ErrUIDInvalid                  error = errors.New("invalid UID")
	ErrUIDRequired                 error = errors.New("UID required")
	ErrURLAlreadyRegistered        error = errors.New("URL already registered")
	ErrURLInvalid                  error = errors.New("invalid URL")
	ErrURLNoHost                   error = errors.New("URL has no host")
	ErrURLNoScheme                 error = errors.New("URL has no scheme")
	ErrURLRequired                 error = errors.New("URL required")
	ErrUserUUIDRequired            error = errors.New("user UUID required")
)

Functions

This section is empty.

Types

type Bookmark

type Bookmark struct {
	UID      string
	UserUUID string

	URL         string
	Title       string
	Description string

	Private bool
	Tags    []string

	CreatedAt time.Time
	UpdatedAt time.Time
}

Bookmark represents a Web bookmark.

func NewBookmark

func NewBookmark(userUUID string) *Bookmark

NewBookmark initializes and returns a new Bookmark.

func (*Bookmark) Normalize

func (b *Bookmark) Normalize()

Normalize sanitizes and normalizes all fields.

func (*Bookmark) ValidateForAddition

func (b *Bookmark) ValidateForAddition(r ValidationRepository) error

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

func (*Bookmark) ValidateForUpdate

func (b *Bookmark) ValidateForUpdate(r Repository) error

ValidateForUpdate ensures mandatory fields are properly set when updating an existing Bookmark.

type FakeRepository

type FakeRepository struct {
	Bookmarks []Bookmark
}

func (*FakeRepository) BookmarkAdd

func (r *FakeRepository) BookmarkAdd(bookmark Bookmark) error

func (*FakeRepository) BookmarkDelete

func (r *FakeRepository) BookmarkDelete(userUUID, uid string) error

func (*FakeRepository) BookmarkGetAll

func (r *FakeRepository) BookmarkGetAll(userUUID string) ([]Bookmark, error)

func (*FakeRepository) BookmarkGetByTag

func (r *FakeRepository) BookmarkGetByTag(userUUID string, tag string) ([]Bookmark, error)

func (*FakeRepository) BookmarkGetByUID

func (r *FakeRepository) BookmarkGetByUID(userUUID, uid string) (Bookmark, error)

func (*FakeRepository) BookmarkGetByURL

func (r *FakeRepository) BookmarkGetByURL(userUUID, u string) (Bookmark, error)

func (*FakeRepository) BookmarkIsURLRegistered

func (r *FakeRepository) BookmarkIsURLRegistered(userUUID, url string) (bool, error)

func (*FakeRepository) BookmarkIsURLRegisteredToAnotherUID

func (r *FakeRepository) BookmarkIsURLRegisteredToAnotherUID(userUUID, url, uid string) (bool, error)

func (*FakeRepository) BookmarkTagUpdateMany

func (r *FakeRepository) BookmarkTagUpdateMany(bookmarks []Bookmark) (int64, error)

func (*FakeRepository) BookmarkUpdate

func (r *FakeRepository) BookmarkUpdate(bookmark Bookmark) error

type Repository

type Repository interface {
	ValidationRepository

	// BookmarkAdd adds a new bookmark for the logged in user.
	BookmarkAdd(bookmark Bookmark) error

	// BookmarkDelete deletes a given bookmark for the logged in user.
	BookmarkDelete(userUUID, uid string) error

	// BookmarkGetAll returns all bookmarks for a given user UUID.
	BookmarkGetAll(userUUID string) ([]Bookmark, error)

	// BookmarkGetByTag returns all bookmarks for a given user UUID and tag.
	BookmarkGetByTag(userUUID string, tag string) ([]Bookmark, error)

	// BookmarkGetByUID returns the bookmark for a given user UUID and UID.
	BookmarkGetByUID(userUUID, uid string) (Bookmark, error)

	// BookmarkGetByURL returns the bookmark for a given user UUID and URL.
	BookmarkGetByURL(userUUID, u string) (Bookmark, error)

	// BookmarkTagUpdateMany updates a tag for collection of existing bookmarks.
	BookmarkTagUpdateMany(bookmarks []Bookmark) (int64, error)

	// BookmarkUpdate updates an existing bookmark for the logged in user.
	BookmarkUpdate(bookmark Bookmark) error
}

Repository provides access to user bookmarks.

type Service

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

Service handles operations for the bookmark domain.

func NewService

func NewService(r Repository) *Service

NewService initializes and returns a bookmark Service.

func (*Service) Add

func (s *Service) Add(bookmark Bookmark) error

Add creates a new bookmark.

func (*Service) All

func (s *Service) All(userUUID string) ([]Bookmark, error)

All returns all bookmarks for a given user.

func (*Service) ByUID

func (s *Service) ByUID(userUUID string, uid string) (Bookmark, error)

ByUID returns a bookmark for a given user and UID.

func (*Service) ByURL

func (s *Service) ByURL(userUUID string, u string) (Bookmark, error)

ByUID returns a bookmark for a given user and URL.

func (*Service) Delete

func (s *Service) Delete(userUUID, uid string) error

Delete permanently deletes a bookmark.

func (*Service) DeleteTag

func (s *Service) DeleteTag(dq TagDeleteQuery) (int64, error)

DeleteTag deletes a given tag from all bookmarks for a given user.

func (*Service) Update

func (s *Service) Update(bookmark Bookmark) error

Update updates all data for an existing bookmark.

func (*Service) UpdateTag

func (s *Service) UpdateTag(uq TagUpdateQuery) (int64, error)

UpdateTag updates a given tag for all bookmarks for a given user.

type TagDeleteQuery

type TagDeleteQuery struct {
	UserUUID string
	Name     string
}

TagDeleteQuery represents a tag deletion for all bookmarks of an authenticated user.

type TagUpdateQuery

type TagUpdateQuery struct {
	UserUUID    string
	CurrentName string
	NewName     string
}

TagUpdateQuery represents a tag name update for all bookmarks for an authenticated user.

type ValidationRepository

type ValidationRepository interface {
	// BookmarkIsURLRegistered returns whether a user has already saved a
	// bookmark with a given URL.
	BookmarkIsURLRegistered(userUUID, url string) (bool, error)

	// BookmarkIsURLRegisteredToAnotherUID returns whether a user has already
	// saved a bookmark with a given URL and a different UID.
	BookmarkIsURLRegisteredToAnotherUID(userUUID, url, uid string) (bool, error)
}

ValidationRepository provides methods for Bookmark validation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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