listsendpoint.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package api
  2. import (
  3. "net/http"
  4. "github.com/go-chi/chi"
  5. "github.com/go-chi/render"
  6. "github.com/willie68/schematic-service-go/dao"
  7. )
  8. // TagsRoutes getting all routes for the tags endpoint
  9. func TagsRoutes() *chi.Mux {
  10. router := chi.NewRouter()
  11. router.Get("/", GetTagsEndpoint)
  12. router.Get("/count", GetTagsCountEndpoint)
  13. return router
  14. }
  15. // ManufacturersRoutes getting all routes for the manufacturers endpoint
  16. func ManufacturersRoutes() *chi.Mux {
  17. router := chi.NewRouter()
  18. router.Get("/", GetManufacturersEndpoint)
  19. router.Get("/count", GetManufacturersCountEndpoint)
  20. return router
  21. }
  22. //GetTagsEndpoint getting all tags back. No paging...
  23. func GetTagsEndpoint(response http.ResponseWriter, req *http.Request) {
  24. tags := dao.GetStorage().GetTags()
  25. m := make(map[string]interface{})
  26. m["found"] = len(tags)
  27. m["data"] = tags
  28. render.JSON(response, req, m)
  29. }
  30. //GetTagsCountEndpoint getting all tags back. No paging...
  31. func GetTagsCountEndpoint(response http.ResponseWriter, req *http.Request) {
  32. tagsCount := dao.GetStorage().GetTagsCount()
  33. m := make(map[string]interface{})
  34. m["found"] = tagsCount
  35. render.JSON(response, req, m)
  36. }
  37. //GetManufacturersEndpoint getting all manufacturers back. No paging...
  38. func GetManufacturersEndpoint(response http.ResponseWriter, req *http.Request) {
  39. manufacturers := dao.GetStorage().GetManufacturers()
  40. m := make(map[string]interface{})
  41. m["found"] = len(manufacturers)
  42. m["data"] = manufacturers
  43. render.JSON(response, req, m)
  44. }
  45. //GetManufacturersCountEndpoint getting all manufacturers back. No paging...
  46. func GetManufacturersCountEndpoint(response http.ResponseWriter, req *http.Request) {
  47. manufacturersCount := dao.GetStorage().GetManufacturersCount()
  48. m := make(map[string]interface{})
  49. m["found"] = manufacturersCount
  50. render.JSON(response, req, m)
  51. }