todo

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IDGenerator

type IDGenerator interface {
	// Generate generates a new ID.
	Generate() (string, error)
}

IDGenerator generates a new ID.

type InMemoryStore

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

InMemoryStore keeps items in the memory. Use it in tests or for development/demo purposes.

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

NewInMemoryStore returns a new in-memory item store.

func (*InMemoryStore) DeleteAll

func (s *InMemoryStore) DeleteAll(_ context.Context) error

DeleteItems deletes all items from the store.

func (*InMemoryStore) DeleteOne

func (s *InMemoryStore) DeleteOne(_ context.Context, id string) error

DeleteOne deletes a single item by its ID.

func (*InMemoryStore) GetAll

func (s *InMemoryStore) GetAll(_ context.Context) ([]Item, error)

GetAll returns all items.

func (*InMemoryStore) GetOne

func (s *InMemoryStore) GetOne(_ context.Context, id string) (Item, error)

GetOne returns a single item by its ID.

func (*InMemoryStore) Store

func (s *InMemoryStore) Store(_ context.Context, item Item) error

Store stores an item.

type Item

type Item struct {
	ID        string
	Title     string
	Completed bool
	Order     int
}

Item is a note describing a task to be done.

type ItemUpdate

type ItemUpdate struct {
	Title     *string
	Completed *bool
	Order     *int
}

ItemUpdate contains updates of an existing item.

type NewItem

type NewItem struct {
	Title string
	Order int
}

NewItem contains the details of a new Item.

type NotFoundError

type NotFoundError struct {
	ID string
}

NotFoundError is returned if an item cannot be found.

func (NotFoundError) Details

func (e NotFoundError) Details() []interface{}

Details returns error details.

func (NotFoundError) Error

func (NotFoundError) Error() string

Error implements the error interface.

func (NotFoundError) NotFound

func (NotFoundError) NotFound() bool

NotFound tells a client that this error is related to a resource being not found. Can be used to translate the error to eg. status code.

func (NotFoundError) ServiceError

func (NotFoundError) ServiceError() bool

ServiceError tells the transport layer whether this error should be translated into the transport format or an internal error should be returned instead.

type Service

type Service interface {
	// AddItem adds a new item to the list.
	AddItem(ctx context.Context, newItem NewItem) (item Item, err error)

	// ListItems returns a list of items.
	ListItems(ctx context.Context) (items []Item, err error)

	// DeleteItems deletes all items from the list.
	DeleteItems(ctx context.Context) error

	// GetItem returns the details of an item.
	GetItem(ctx context.Context, id string) (item Item, err error)

	// UpdateItem updates an existing item.
	UpdateItem(ctx context.Context, id string, itemUpdate ItemUpdate) (item Item, err error)

	// DeleteItem deletes an item from the list.
	DeleteItem(ctx context.Context, id string) error
}

Service manages a todo list.

func NewService

func NewService(idgenerator IDGenerator, store Store) Service

NewService returns a new Service.

type Store

type Store interface {
	// Store stores an item.
	Store(ctx context.Context, item Item) error

	// GetAll returns all items.
	GetAll(ctx context.Context) ([]Item, error)

	// DeleteItems deletes all items in the store.
	DeleteAll(ctx context.Context) error

	// GetOne returns a single item by its ID.
	GetOne(ctx context.Context, id string) (Item, error)

	// DeleteOne deletes a single item by its ID.
	DeleteOne(ctx context.Context, id string) error
}

Store persists items.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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