handler

package
v0.0.0-...-9da9030 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

PAckage handler implements router and endpoints for REST API

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRenderResp        = errors.New("can't render response")
	ErrOrderNotFound     = errors.New("order not found")
	ErrTripNotFound      = errors.New("trip not found")
	ErrLaunchpadNotFound = errors.New("launchpad not found")
	ErrOrderCtxEmpty     = errors.New("order was lost")
)

Functions

func ErrInternalServer

func ErrInternalServer(err error) render.Renderer

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

func ErrNotFound

func ErrNotFound(err error) render.Renderer

func ErrRender

func ErrRender(err error) render.Renderer

func OrdersListResponse

func OrdersListResponse(orders []*core.Order) []render.Renderer

func SendRequestID

func SendRequestID(next http.Handler) http.Handler

SendRequestID is a middleware for sending X-Request-Id to the client

Types

type CreateOrderRequest

type CreateOrderRequest struct {
	*dto.Order
	*dto.User
	FirstName     string `json:"first_name"`
	LastName      string `json:"last_name"`
	Gender        string `json:"gender"`
	Birthday      string `json:"birthday"`
	LaunchpadID   string `json:"launchpad_id"`
	DestinationID string `json:"destination_id"`
	LaunchDate    string `json:"launch_date"`
}

func (*CreateOrderRequest) Bind

func (co *CreateOrderRequest) Bind(r *http.Request) error

type Deps

type Deps struct {
	Services
	Log *zap.Logger
}

Deps represents external dependencies for rest handlers

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	ErrorText string `json:"error,omitempty"` // application-level error message, for debugging
}

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

type Handler

type Handler struct {
	Order *OrderHandler
	// contains filtered or unexported fields
}

Handler represents rest modules of API

func New

func New(deps Deps) *Handler

New returns instance of rest handler

func (*Handler) Logger

func (h *Handler) Logger() func(next http.Handler) http.Handler

Logger is a middleware that logs the start and end of each request, along with some useful data about what was requested, what the response status was, and how long it took to return.

func (*Handler) Recoverer

func (h *Handler) Recoverer(next http.Handler) http.Handler

Recoverer is a middleware for recovering after panics during handling http requests

func (*Handler) Routes

func (h *Handler) Routes() *chi.Mux

Routes creates, composes, and returns rest routes for API

type LaunchpadService

type LaunchpadService interface {
	GetForDate(launchpadID string, date time.Time) (core.Launchpad, error)
}

type OrderHandler

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

OrderHandler represents handler for rest endpoints related to order entity

func NewOrderHandler

func NewOrderHandler(services Services, log *zap.Logger) *OrderHandler

NewOrderHandler returns new instance of orders handler

type OrderResponse

type OrderResponse struct {
	*core.Order
}

func (*OrderResponse) Render

func (or *OrderResponse) Render(w http.ResponseWriter, r *http.Request) error

type OrderService

type OrderService interface {
	GetByID(orderID string) (core.Order, error)
	GetAll() ([]*core.Order, error)
	Create(userID string, data *dto.Order) (core.Order, error)
	RemoveByID(orderID string) error
}

type Services

type Services struct {
	Launchpad LaunchpadService
	Order     OrderService
	Trip      TripService
	User      UserService
}

type TripService

type TripService interface {
	GetByDestination(destinationID string) (core.Trip, error)
}

type UserService

type UserService interface {
	FindOrCreate(data *dto.User) (core.User, error)
}

Jump to

Keyboard shortcuts

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