api

package
v0.0.0-...-3040c09 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Router

func Router(service DeckService, log *log.Logger) (http.Handler, error)

func Start

func Start(ctx context.Context, addr string, service DeckService, log *log.Logger) error

Types

type DeckHandler

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

func NewDeckHandler

func NewDeckHandler(service DeckService, log *log.Logger) (*DeckHandler, error)

func (*DeckHandler) CreateDeck

func (h *DeckHandler) CreateDeck(w http.ResponseWriter, r *http.Request)

CreateDeck godoc

@Summary		Creates a new deck
@Description	Creates new decks with all cards or specific ones. Also, it's possible to shuffle the deck.
@Accept			json
@Produce		json
@Param			shuffled	query		bool	false	"Shuffle cards on the deck."
@Param			cards		query		array	false	"The card codes to be added to the deck."
@Success		200			{object}	deck.CreateDeckResponse
@Failure		400			{object}	HttpError
@Failure		404			{object}	HttpError
@Failure		422			{object}	HttpError
@Failure		500			{object}	HttpError
@Router			/ [post]

func (*DeckHandler) DrawCard

func (h *DeckHandler) DrawCard(w http.ResponseWriter, r *http.Request)

DrawCard godoc

@Summary		Draws a card from the deck
@Description	Draws one or more cards from the deck
@Param			id		path	string	true	"The ID (uuid) of the deck."
@Param			count	query	int		true	"The number of cards to draw from the deck."
@Accept			json
@Produce		json
@Success		200	{object}	deck.DrawCardResponse
@Failure		400	{object}	HttpError
@Failure		404	{object}	HttpError
@Failure		422	{object}	HttpError
@Failure		500	{object}	HttpError
@Router			/{id}/draw [get]

func (*DeckHandler) OpenDeck

func (h *DeckHandler) OpenDeck(w http.ResponseWriter, r *http.Request)

OpenDeck godoc

@Summary		Opens an existing deck
@Description	Returns an existing opened deck with all cards.
@Accept			json
@Produce		json
@Param			id	path		string	true	"The ID (uuid) of the deck."
@Success		200	{object}	deck.OpenDeckResponse
@Failure		400	{object}	HttpError
@Failure		404	{object}	HttpError
@Failure		422	{object}	HttpError
@Failure		500	{object}	HttpError
@Router			/{id} [get]

type DeckService

type DeckService interface {
	CreateDeck(ctx context.Context, shuffled bool, cards []string) (*deck.CreateDeckResponse, error)
	OpenDeck(ctx context.Context, id string) (*deck.OpenDeckResponse, error)
	DrawCard(ctx context.Context, id string, count int64) (*deck.DrawCardResponse, error)
}

type HttpError

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

Jump to

Keyboard shortcuts

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