items

package
v0.0.0-...-b9b4979 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHandlers

func RegisterHandlers(mux *httprouter.Router, service Service, logger log.Logger)

RegisterHandlers registers handlers for Items API methods.

Types

type ItemFilter

type ItemFilter struct {
	StateFilter    []entity.ItemState
	RarityFilter   []string
	CategoryFilter []string
}

func NewFilter

func NewFilter(r *http.Request) ItemFilter

NewFilter creates a new item filter.

type Repository

type Repository interface {
	// GetAll returns all items in the application.
	GetAll(userId int, filters ItemFilter) ([]entity.Item, error)
	// GetOne returns user's item with specified id.
	GetOne(userId, itemId int) (entity.Item, error)
	// Update modifies the user's item status with specified id.
	Update(userId int, item *entity.Item) error
}

Repository encapsulates the logic to access items from the data source.

func NewRepository

func NewRepository(db *sql.DB, logger log.Logger) Repository

NewRepository creates a new item's repository.

type Service

type Service interface {
	// GetAll returns all items.
	GetAll(userId int, filters ItemFilter) ([]entity.Item, error)
	// GetOne returns item with specified id owned by user with specified id.
	GetOne(userId, itemId int) (entity.Item, error)
	// UpdateItemState returns item with specified id with new ItemState.
	UpdateItemState(userId, itemId int, input *UpdateItemStateRequest) (entity.Item, error)
}

Service encapsulates usecase logic for items.

func NewService

func NewService(repo Repository) Service

NewService creates a new item service.

type UpdateItemStateRequest

type UpdateItemStateRequest struct {
	ItemState entity.ItemState `json:"itemState"`
}

UpdateItemStateRequest represents the data for modifing ItemState.

Jump to

Keyboard shortcuts

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