api

package
v0.0.0-...-35212e5 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RespondWithMessage

func RespondWithMessage(w http.ResponseWriter, status int, message string)

RespondWithMessage sends message string to response writer

Types

type Config

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

Config stores application configuration

type GetProductResponse

type GetProductResponse struct {
	Product Product `json:"product"`
}

GetProductResponse is a response for GetProductHandler

type GetProductsResponse

type GetProductsResponse struct {
	Products []Product `json:"products"`
}

GetProductsResponse is a response for GetProductsHandler

type GetShoppingCartHandler

type GetShoppingCartHandler struct {
	Products []Product `json:"products"`
	Subtotal float64   `json:"price"`
}

AddProductToShoppingCartResponse is a response for AddProductToShoppingCartHandler

type Product

type Product struct {
	mgm.DefaultModel `bson:",inline"`
	Title            string  `json:"title"`
	Price            float64 `json:"price"`
}

Product is a sellable element

func NewProduct

func NewProduct(title string, price float64) Product

func ReturnProductSlice

func ReturnProductSlice(r *http.Request) []Product

type Server

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

Server keeps track of router, config and more

func (*Server) AddProductHandler

func (s *Server) AddProductHandler(w http.ResponseWriter, r *http.Request)

AddProductHandler creates a new product

func (*Server) AddProductToShoppingCartHandler

func (s *Server) AddProductToShoppingCartHandler(w http.ResponseWriter, r *http.Request)

func (*Server) AuthGoogleLogin

func (s *Server) AuthGoogleLogin(w http.ResponseWriter, r *http.Request)

AuthGoogleLogin redirects user to Google login page

func (*Server) AuthGoogleRedirect

func (s *Server) AuthGoogleRedirect(w http.ResponseWriter, r *http.Request)

AuthGoogleRedirect handles redirect from Google and signs in user

func (*Server) DeleteProductFromShoppingCartHandler

func (s *Server) DeleteProductFromShoppingCartHandler(w http.ResponseWriter, r *http.Request)

func (*Server) DeleteProductHandler

func (s *Server) DeleteProductHandler(w http.ResponseWriter, r *http.Request)

DeleteProductHandler deletes a product

func (*Server) GetProductHandler

func (s *Server) GetProductHandler(w http.ResponseWriter, r *http.Request)

GetProductHandler returns product by id

func (*Server) GetProductsHandler

func (s *Server) GetProductsHandler(w http.ResponseWriter, r *http.Request)

GetProductsHandler returns all products

func (*Server) GetShoppingCartHandler

func (s *Server) GetShoppingCartHandler(w http.ResponseWriter, r *http.Request)

func (*Server) HomeHandler

func (s *Server) HomeHandler(w http.ResponseWriter, r *http.Request) error

HomeHandler gives basic details about API

func (*Server) JWTAuthentication

func (s *Server) JWTAuthentication(next http.Handler) http.Handler

JWTAuthentication is a middleware that checks authentication

func (*Server) LoginHandler

func (s *Server) LoginHandler(w http.ResponseWriter, r *http.Request) error

LoginHandler handles user login

func (*Server) SignUpHandler

func (s *Server) SignUpHandler(w http.ResponseWriter, r *http.Request) error

SignUpHandler handles user sign up

func (*Server) Start

func (s *Server) Start()

Start the server on port 8080

type ShoppingCart

type ShoppingCart struct {
	mgm.DefaultModel `bson:",inline"`
	Products         []Product `json:"products"`
	Subtotal         float64   `json:"price"`
}

func NewShoppingCart

func NewShoppingCart(products []Product, subtotal float64) ShoppingCart

type TokenClaims

type TokenClaims struct {
	UserID string
	jwt.StandardClaims
}

TokenClaims is used to create JWT token

type User

type User struct {
	mgm.DefaultModel `bson:",inline"`
	Email            string `json:"email"`
	Password         string `json:"-"`
	GoogleUserID     string `json:"-" bson:"google_user_id"`
}

User is used to store user information

func NewUser

func NewUser(email, password, googleUserID string) User

type UserCredentials

type UserCredentials struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

UserCredentials are used for signup and login

type UserError

type UserError struct {
	StatusCode int    `json:"-"`
	Message    string `json:"message"`
	Cause      error  `json:"-"`
}

UserError is used to indicate user what went wrong

func (UserError) Error

func (e UserError) Error() string

Jump to

Keyboard shortcuts

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