bookssvc

package
v0.0.0-...-a1f6b74 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidBook = errors.New("Invalid Book")
)

Functions

func DecodeDeleteBookRequest

func DecodeDeleteBookRequest(_ context.Context, r *http.Request) (interface{}, error)

func DecodeGetBookRequest

func DecodeGetBookRequest(_ context.Context, r *http.Request) (interface{}, error)

func DecodePostBookRequest

func DecodePostBookRequest(_ context.Context, r *http.Request) (interface{}, error)

func DecodePutBookRequest

func DecodePutBookRequest(_ context.Context, r *http.Request) (interface{}, error)

func EncodeBookResponse

func EncodeBookResponse(_ context.Context, w http.ResponseWriter, response interface{}) error

func EncodeErrorResponse

func EncodeErrorResponse(_ context.Context, err error, w http.ResponseWriter)

func MakeDeleteBookENdpoint

func MakeDeleteBookENdpoint(svc BooksService) endpoint.Endpoint

func MakeGetBookENdpoint

func MakeGetBookENdpoint(svc BooksService) endpoint.Endpoint

func MakeHandler

func MakeHandler(svc BooksService, logger log.Logger) http.Handler

func MakePostBookEndpoint

func MakePostBookEndpoint(svc BooksService) endpoint.Endpoint

func MakePutBookEndpoint

func MakePutBookEndpoint(svc BooksService) endpoint.Endpoint

Types

type Book

type Book struct {
	ID               int       `json:"id"`
	Title            string    `json:"title"`
	Author           string    `json:"author"`
	AverageRating    float32   `json:"average_rating"`
	ISBN             string    `json:"isbn"`
	ISBN13           string    `json:"isbn13"`
	LanguageCode     string    `json:"language_code"`
	NumPages         int       `json:"num_pages"`
	RatingsCount     int       `json:"ratings_count"`
	TextReviewsCount int       `json:"text_reviews_count"`
	PublicationDate  time.Time `json:"publication_date"`
	Publisher        string    `json:"publisher"`
}

Book represents a single book record

type BookServiceInstance

type BookServiceInstance struct {
	Db *gorm.DB
}

BookServiceInstance implements the BookService interface

func (BookServiceInstance) DeleteBook

func (svc BookServiceInstance) DeleteBook(ctx context.Context, id int) error

DeleteBook

func (BookServiceInstance) GetBook

func (svc BookServiceInstance) GetBook(ctx context.Context, id int) (Book, error)

GetBook

func (BookServiceInstance) PostBook

func (svc BookServiceInstance) PostBook(ctx context.Context, b Book) (int, error)

PostBook adds the book to the database

func (BookServiceInstance) PutBook

func (svc BookServiceInstance) PutBook(ctx context.Context, id int, b Book) error

PutBook

type BooksService

type BooksService interface {
	PostBook(ctx context.Context, b Book) (int, error)
	GetBook(ctx context.Context, id int) (Book, error)
	PutBook(ctx context.Context, id int, b Book) error
	DeleteBook(ctx context.Context, id int) error
}

BookService is a CRUD interface for books

type DeleteBookRequest

type DeleteBookRequest struct {
	ID int `json:"id"`
}

DeleteBookRequest is the rpc request to delete a book record

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse is sent when the endpoint could not complete the request

type GetBookRequest

type GetBookRequest struct {
	ID int `json:"id"`
}

GetBookRequest is the rpc request message to get a book by id

type GetBookResponse

type GetBookResponse struct {
	Book Book `json:"book"`
}

GetBookResponse is the rpc response of the get request

type PostBookRequest

type PostBookRequest struct {
	Book Book `json:"book"`
}

PostBookRequest is RPC request message to post a new book

type PostBookResponse

type PostBookResponse struct {
	ID int `json:"id"`
}

PostBookResponse is a RPC response message to the post request

type PutBookRequest

type PutBookRequest struct {
	ID   int  `json:"id"`
	Book Book `json:"book"`
}

PutBookRequest is the rpc request to update an existing book

Jump to

Keyboard shortcuts

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