package api import ( "net/http" "github.com/go-chi/chi" "github.com/go-chi/render" "github.com/willie68/schematic-service-go/dao" ) // TagsRoutes getting all routes for the tags endpoint func TagsRoutes() *chi.Mux { router := chi.NewRouter() router.Get("/", GetTagsEndpoint) router.Get("/count", GetTagsCountEndpoint) return router } // ManufacturersRoutes getting all routes for the manufacturers endpoint func ManufacturersRoutes() *chi.Mux { router := chi.NewRouter() router.Get("/", GetManufacturersEndpoint) router.Get("/count", GetManufacturersCountEndpoint) return router } //GetTagsEndpoint getting all tags back. No paging... func GetTagsEndpoint(response http.ResponseWriter, req *http.Request) { tags := dao.GetStorage().GetTags() m := make(map[string]interface{}) m["found"] = len(tags) m["data"] = tags render.JSON(response, req, m) } //GetTagsCountEndpoint getting all tags back. No paging... func GetTagsCountEndpoint(response http.ResponseWriter, req *http.Request) { tagsCount := dao.GetStorage().GetTagsCount() m := make(map[string]interface{}) m["found"] = tagsCount render.JSON(response, req, m) } //GetManufacturersEndpoint getting all manufacturers back. No paging... func GetManufacturersEndpoint(response http.ResponseWriter, req *http.Request) { manufacturers := dao.GetStorage().GetManufacturers() m := make(map[string]interface{}) m["found"] = len(manufacturers) m["data"] = manufacturers render.JSON(response, req, m) } //GetManufacturersCountEndpoint getting all manufacturers back. No paging... func GetManufacturersCountEndpoint(response http.ResponseWriter, req *http.Request) { manufacturersCount := dao.GetStorage().GetManufacturersCount() m := make(map[string]interface{}) m["found"] = manufacturersCount render.JSON(response, req, m) }