mirror of
https://github.com/andatoshiki/shikigrid.git
synced 2026-06-05 19:56:27 +00:00
34 lines
751 B
Go
34 lines
751 B
Go
package api
|
|
|
|
import (
|
|
"github.com/evilsocket/islazy/log"
|
|
"github.com/andatoshiki/shikigrid/models"
|
|
"net/http"
|
|
)
|
|
|
|
func (api *API) ListUnits(w http.ResponseWriter, r *http.Request) {
|
|
page, err := pageNum(r)
|
|
if err != nil {
|
|
ERROR(w, http.StatusUnprocessableEntity, err)
|
|
return
|
|
}
|
|
|
|
units, total, pages := models.GetPagedUnits(page)
|
|
|
|
JSON(w, http.StatusOK, map[string]interface{}{
|
|
"records": total,
|
|
"pages": pages,
|
|
"units": units,
|
|
})
|
|
}
|
|
|
|
func (api *API) UnitsByCountry(w http.ResponseWriter, r *http.Request) {
|
|
if results, err := models.GetUnitsByCountry(); err != nil {
|
|
log.Warning("error getting units by country: %v", err)
|
|
ERROR(w, http.StatusInternalServerError, err)
|
|
return
|
|
} else {
|
|
JSON(w, http.StatusOK, results)
|
|
}
|
|
}
|