states

package
v0.0.0-...-4d2a565 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package states provides the REST API endpoints needed for CRUD operations on geospatial state objects in the backend data store

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStateCollectionResponse

func NewStateCollectionResponse(features []api.Feature) api.FeatureCollection

Translates an array of [geo.State] objects into a GeoJSON FeatureCollection

func NewStateResponse

func NewStateResponse(state geospatial.State) api.Feature

Translates the geospatial.State object from the geospatial package into a GeoJSON feature

func Router

func Router(store DataProvider) chi.Router

Maps the handler to the REST API endpoints for the state API

Types

type CreateStateRequest

type CreateStateRequest geospatial.State

Adds the Bind method to the geospatial.State object to hook into the go-chi renderer

func (*CreateStateRequest) Bind

func (sr *CreateStateRequest) Bind(r *http.Request) error

func (*CreateStateRequest) UnmarshalJSON

func (csr *CreateStateRequest) UnmarshalJSON(data []byte) error

type DataProvider

type DataProvider interface {
	GetAll() ([]geospatial.State, error)
	GetByName(name string) (geospatial.State, error)
	Create(geospatial.State) (geospatial.State, error)
	Delete(name string) error
}

Injects the dependcies required by the handler for the backend data store.

type RouteHandler

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

func (RouteHandler) CreateState

func (h RouteHandler) CreateState(w http.ResponseWriter, r *http.Request)

HTTP request handler for the POST /api/v1/state endpoint creates the [geospatialspatial.State] object and adds it to the data store

func (RouteHandler) DeleteState

func (h RouteHandler) DeleteState(w http.ResponseWriter, r *http.Request)

HTTP request handler for the DELETE /api/v1/state/{name} endpoint removes a given state from the data store

func (RouteHandler) GetState

func (h RouteHandler) GetState(w http.ResponseWriter, r *http.Request)

HTTP request handler for the /api/v1/state/{name} endpoint

func (RouteHandler) ListStates

func (h RouteHandler) ListStates(w http.ResponseWriter, r *http.Request)

HTTP request handler for the GET /api/v1/state endpoint renders the entire list of states in the data store to a GeoJSON feature collection

Jump to

Keyboard shortcuts

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