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: 8 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.BookService, us *db.UserService, ms *db.MagazineService) *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) ListMagazines

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

ListMagazines is invoked by HTTP GET /magazines.

func (*Handler) ListUserByID_Books

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

ListUserByID_Books is invoked by HTTP GET /users/{id}/books.

func (*Handler) ListUserByID_Magazines

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

ListUserByID_Magazines is invoked by HTTP GET /users/{id}/magazines.

func (*Handler) MagazineUpsert

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

MagazineUpsert is invoked by HTTP POST /magazines.

func (*Handler) SwapBook

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

SwapBook is invoked by POST /books/{id}

func (*Handler) SwapMagazine

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

SwapMagazine is invoked by POST /magazines/{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[T ResponseItemType] struct {
	Message string   `json:"message,omitempty"`
	Error   string   `json:"error,omitempty"`
	Items   []T      `json:"items,omitempty"`
	User    *db.User `json:"user,omitempty"`
}

Response contains all the response types of our handlers.

type ResponseItemType

type ResponseItemType interface {
	db.Book | db.Magazine
}

Jump to

Keyboard shortcuts

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