items

package
v0.0.0-...-a5a6d41 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package items handles all the todo items

Index

Constants

View Source
const (
	// StatusDeleted is the status of the item returned after it's deleted
	StatusDeleted = "deleted"
)

Variables

View Source
var (
	// ErrCreate is returned if there's an error in creating a new item
	ErrCreate = errors.New("Sorry, an error occurred while creating")
	// ErrRead is returned if there's an error reading an item
	ErrRead = errors.New("Sorry, unable to fetch item")
	// ErrInvOwnerID is returned if the owner ID is blank or invalid
	ErrInvOwnerID = errors.New("Sorry, invalid owner ID provided")
)

Functions

This section is empty.

Types

type Item

type Item struct {
	// ID is the unique identifier of a single item
	ID string `json:"id,omitempty" bson:"id,omitempty"`
	// Title is the title of a single item
	Title string `json:"title,omitempty" bson:"title,omitempty"`
	// Description is the description of a single item
	Description string `json:"description,omitempty" bson:"description,omitempty"`
	// Status is the current status of the item, it's set only while returning a deleted item
	Status string `json:"status,omitempty" bson:"status,omitempty"`
	// OwnerID is the unique identifier of an owner
	OwnerID string `json:"-" bson:"ownerID,omitempty"`
	// Blob stores the encrypted byte of Item
	Blob []byte `json:"-" bson:"blob,omitempty"`
	// CreatedAt is a UTC timestamp of when the item was created
	CreatedAt *time.Time `json:"createdAt,omitempty" bson:"createdAt,omitempty"`
	// ModifiedAt is the UTC timestamp of when the item was last updated
	ModifiedAt *time.Time `json:"modifiedAt,omitempty" bson:"modifiedAt,omitempty"`
}

Item holds a single item

func New

func New(data map[string]string, ownerID string) (*Item, error)

New returns a new instance of Item with the provided data

func (*Item) Decrypt

func (i *Item) Decrypt(key [32]byte) error

Decrypt decrpyts an item Description with the provided key

func (*Item) Encrypt

func (i *Item) Encrypt(key [32]byte) error

Encrypt encrypts the item description and sets the Blob with encrypted bytes

type Service

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

Service holds all the dependencies of items

func NewService

func NewService(ss storage.Service, l logger.Service) Service

NewService returns a new instance of Service with all the dependencies initialized

func (*Service) Create

func (s *Service) Create(item Item) (*Item, error)

Create creates a new item

func (*Service) Delete

func (s *Service) Delete(id string) (*Item, error)

Delete deletes an item given the ID

func (*Service) List

func (s *Service) List(ownerID string, start, limit int) ([]Item, error)

List returns the list of items given the owner ID

func (*Service) Read

func (s *Service) Read(id string) (*Item, error)

Read reads an item given the item ID

func (*Service) Update

func (s *Service) Update(id string, data Item) (*Item, error)

Update updates an item given the ID

Jump to

Keyboard shortcuts

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