handlers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureServer

func ConfigureServer(handler *Handler) *mux.Router

ConfigureServer configures the routes of this server and binds handler functions to them

Types

type Handler

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

Handler contains the handler and all its dependencies.

func NewHandler

func NewHandler(bs *db.BookRepository, us *db.UserService) *Handler

NewHandler initialises a new handler, given dependencies.

func (*Handler) BookUpsert

func (h *Handler) BookUpsert(w http.ResponseWriter, r *http.Request)

BookUpsert is invoked by HTTP POST /books.

func (*Handler) Index

func (h *Handler) Index(w http.ResponseWriter, r *http.Request)

Index is invoked by HTTP GET /.

func (*Handler) ListBooks

func (h *Handler) ListBooks(w http.ResponseWriter, r *http.Request)

ListBooks is invoked by HTTP GET /books.

func (*Handler) ListUserByID

func (h *Handler) ListUserByID(w http.ResponseWriter, r *http.Request)

ListUserByID is invoked by HTTP GET /users/{id}.

func (*Handler) SwapBook

func (h *Handler) SwapBook(w http.ResponseWriter, r *http.Request)

SwapBook is invoked by POST /books/{id}

func (*Handler) UserUpsert

func (h *Handler) UserUpsert(w http.ResponseWriter, r *http.Request)

UserUpsert is invoked by HTTP POST /users.

type Response

type Response struct {
	Message string    `json:"message,omitempty"`
	Error   string    `json:"error,omitempty"`
	Books   []db.Book `json:"books,omitempty"`
	User    *db.User  `json:"user,omitempty"`
}

Response contains all the response types of our handlers.

Jump to

Keyboard shortcuts

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