store

package
v0.0.0-...-94b5027 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const COLLECTION = "store"

COLLECTION is the name of the collection in DB

View Source
const DBNAME = "dummyStore"

DBNAME the name of the DB instance

View Source
const SERVER = "mongodb://gautam:gautam@ds157233.mlab.com:57233/dummystore"

SERVER the DB server

Variables

This section is empty.

Functions

func AuthenticationMiddleware

func AuthenticationMiddleware(next http.HandlerFunc) http.HandlerFunc

Middleware handler to handle all requests for authentication

func NewRouter

func NewRouter() *mux.Router

NewRouter configures a new router to the API

Types

type Controller

type Controller struct {
	Repository Repository
}

Controller ...

func (*Controller) AddProduct

func (c *Controller) AddProduct(w http.ResponseWriter, r *http.Request)

AddProduct POST /

func (*Controller) DeleteProduct

func (c *Controller) DeleteProduct(w http.ResponseWriter, r *http.Request)

DeleteProduct DELETE /

func (*Controller) GetProduct

func (c *Controller) GetProduct(w http.ResponseWriter, r *http.Request)

GetProduct GET - Gets a single product by ID /

func (*Controller) GetToken

func (c *Controller) GetToken(w http.ResponseWriter, req *http.Request)

Get Authentication token GET /

func (*Controller) Index

func (c *Controller) Index(w http.ResponseWriter, r *http.Request)

Index GET /

func (*Controller) SearchProduct

func (c *Controller) SearchProduct(w http.ResponseWriter, r *http.Request)

SearchProduct GET /

func (*Controller) UpdateProduct

func (c *Controller) UpdateProduct(w http.ResponseWriter, r *http.Request)

UpdateProduct PUT /

type Exception

type Exception struct {
	Message string `json:"message"`
}

type JwtToken

type JwtToken struct {
	Token string `json:"token"`
}

type Product

type Product struct {
	ID     int    `bson:"_id"`
	Title  string `json:"title"`
	Image  string `json:"image"`
	Price  uint64 `json:"price"`
	Rating uint8  `json:"rating"`
}

Product represents an e-comm item

type Products

type Products []Product

Products is an array of Product objects

type Repository

type Repository struct{}

Repository ...

func (Repository) AddProduct

func (r Repository) AddProduct(product Product) bool

AddProduct adds a Product in the DB

func (Repository) DeleteProduct

func (r Repository) DeleteProduct(id int) string

DeleteProduct deletes an Product

func (Repository) GetProductById

func (r Repository) GetProductById(id int) Product

GetProductById returns a unique Product

func (Repository) GetProducts

func (r Repository) GetProducts() Products

GetProducts returns the list of Products

func (Repository) GetProductsByString

func (r Repository) GetProductsByString(query string) Products

GetProductsByString takes a search string as input and returns products

func (Repository) UpdateProduct

func (r Repository) UpdateProduct(product Product) bool

UpdateProduct updates a Product in the DB

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

Route defines a route

type Routes

type Routes []Route

Routes defines the list of routes of our API

type User

type User struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

Jump to

Keyboard shortcuts

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