hero

package
v0.0.0-...-d36a70f Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(dbConn *database.DB, id string) error

Delete removes a hero. The id should be a valid bson ObjectIdHex.

func Update

func Update(dbConn *database.DB, uHero UpdateHero, userID string) error

Update will update a hero in the heroes collection

Types

type CreateHero

type CreateHero struct {
	Name        string   `bson:"name" json:"name"`
	SuperPowers []string `bson:"superpowers" json:"superpowers"`
	Gender      string   `bson:"gender" json:"gender"`
	Metadata    `bson:",inline"`
}

CreateHero holds values for creating users.

type Filters

type Filters struct {
	SuperPowers []string `form:"superpowers" json:"superpowers" query:"superpowers"`
}

Filters represent restrictions that can be applied when listing heroes.

type Hero

type Hero struct {
	ID          bson.ObjectId `bson:"_id" json:"id"`
	Name        string        `bson:"name" json:"name"`
	SuperPowers []string      `bson:"superpowers" json:"superpowers"`
	Gender      string        `bson:"gender" json:"gender"`
	Metadata    `bson:",inline"`
}

Hero holds value for /v1/heroes endpoint

func Create

func Create(dbConn *database.DB, cH *CreateHero) (*Hero, error)

Create creates new hero in DB

func Retrieve

func Retrieve(dbConn *database.DB, heroID string) (*Hero, error)

Retrieve finds a hero by ID. The id needs to be a valid bson ObjectIdHex.

type ListResults

type ListResults struct {
	Heroes        []Hero `json:"items"`
	Count         int    `json:"count"`
	Total         int    `json:"total"`
	PreviousIndex *int   `json:"previousIndex,omitempty"`
	Index         int    `json:"index"`
	NextIndex     *int   `json:"nextIndex,omitempty"`
}

ListResults holds a list of heroes and pagination information.

func List

func List(dbConn *database.DB, filters Filters, paging pagination.Paging) (*ListResults, error)

List returns a list of heroes from the database and applies query string parameters

type Metadata

type Metadata struct {
	Created      time.Time `bson:"created" json:"created"`
	LastModified time.Time `bson:"lastModified" json:"lastModified"`
	IsRemoved    bool      `bson:"isRemoved" json:"-"`
}

Metadata fields for a hero

type UpdateHero

type UpdateHero CreateHero

UpdateHero is what we accept from users to update a Hero record.

Jump to

Keyboard shortcuts

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