Example #1
0
func Search(ds datastore.Datastore) func(c *echo.Context) error {
	return func(c *echo.Context) error {
		cep, err := ds.SearchCep(c.Param("cep"))
		if err != nil {
			c.Error(err)
		}
		return c.JSON(http.StatusOK, cep)
	}
}
Example #2
0
func Index(ds datastore.Datastore) func(c *echo.Context) error {
	return func(c *echo.Context) error {
		ceps, err := ds.LastUpdatedCeps(10)
		if err != nil {
			c.Error(err)
		}
		return c.JSON(http.StatusOK, ceps)
	}
}
Example #3
0
func Insert(ds datastore.Datastore) func(c *echo.Context) error {
	return func(c *echo.Context) error {
		var cep model.CEP
		if err := c.Bind(&cep); err != nil {
			return err
		}
		createdCep, err := ds.CreateCep(cep)
		if err != nil {
			return err
		}
		return c.JSON(http.StatusOK, createdCep)
	}
}
Example #4
0
func Update(ds datastore.Datastore) func(c *echo.Context) error {
	return func(c *echo.Context) error {
		var cep model.CEP
		if err := c.Bind(&cep); err != nil {
			return err
		}
		cep.Value = c.Param("cep")
		updatedCep, err := ds.UpdateCep(cep)
		if err != nil {
			return err
		}
		return c.JSON(http.StatusOK, updatedCep)
	}
}