maybe

package
v0.0.0-...-9790b92 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is used when a specific Product is requested but does not exist.
	ErrNotFound = errors.New("not found")

	// ErrInvalidID occurs when an ID is not in a valid form.
	ErrInvalidID = errors.New("ID is not in its proper form")

	// ErrInvalidTag occurs when a tag cannot be found in the dabase and cannot be created.
	ErrInvalidTag = errors.New("tag not found")

	// ErrForbidden occurs when a user tries to do something that is forbidden to them according to access control policies.
	ErrForbidden = errors.New("attempted action is not allowed")
)

Functions

This section is empty.

Types

type Info

type Info struct {
	ID          string `db:"maybe_id"`
	UserID      string `db:"user_id"`
	Title       string `db:"title"`
	Url         string `db:"url"`
	Description string `db:"description"`
	Tags        []Tag  `db:"tags"`
	DateCreated string `db:"created_at"`
	DateUpdated string `db:"updated_at"`
}

Info is the model for maybes.

type Infos

type Infos []Info

type NewOrUpdateMaybe

type NewOrUpdateMaybe struct {
	Title       string
	Url         string
	Description string
	Tags        []string
}

NewOrUpdateMaybe is the data for creating a new maybe or updating an existing maybe. Adding Tags is optional.

type NewTag

type NewTag struct {
	Name string `db:"name"`
}

NewTag is the data for creating a new tag.

type RepositoryDb

type RepositoryDb struct {
	Db *sqlx.DB
}

RepositoryDb defines the repository for the maybe service.

func New

func New(db *sqlx.DB) RepositoryDb

New returns a pointer to a maybe repo.

func (RepositoryDb) Create

func (r RepositoryDb) Create(nm NewOrUpdateMaybe, userID string) (Info, error)

Create adds a new maybe to the database with pre-filled ID and date fields.

func (RepositoryDb) Delete

func (r RepositoryDb) Delete(maybeID string) error

Delete removes a maybe with given ID and its tags from the database.

func (RepositoryDb) Query

func (r RepositoryDb) Query(userID string) (Infos, error)

Query retrieves all maybes from the database for the current user.

func (RepositoryDb) QueryByID

func (r RepositoryDb) QueryByID(maybeID string, userID string) (Info, error)

QuerybyID retrieves a book by ID from the database.

func (RepositoryDb) QueryByTag

func (r RepositoryDb) QueryByTag(tagID string, userID string) (Infos, error)

QueryByTag queries the database for all maybes of a certain tag for the current user.

func (RepositoryDb) QueryTags

func (r RepositoryDb) QueryTags(userID string) (Tags, error)

QueryTags returns all (unique) tags for a given user.

func (RepositoryDb) Update

func (r RepositoryDb) Update(um NewOrUpdateMaybe, maybeID string, userID string) error

Update updates an existing maybe.

type Tag

type Tag struct {
	ID   string `db:"tag_id"`
	Name string `db:"name"`
}

Tag is the model for a tag.

type Tags

type Tags []Tag

Jump to

Keyboard shortcuts

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