schematicapi.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. //SchematicsRoutes getting all routes for the config endpoint
  9. func SchematicsRoutes() *chi.Mux {
  10. router := chi.NewRouter()
  11. router.Post("/", PostSchematicEndpoint)
  12. router.Get("/", GetSchematicsEndpoint)
  13. router.Delete("/{schematicId}", DeleteSchematicEndpoint)
  14. router.Put("/{schematicId}", UpdateSchematicEndpoint)
  15. router.Get("/{schematicId}", GetSchematicHandler)
  16. router.Get("/{schematicId}/files/{fileId}", GetSchematicFileHandler)
  17. return router
  18. }
  19. // GetTenantHandler gets a tenant
  20. func GetSchematicHandler(response http.ResponseWriter, req *http.Request) {
  21. schematicID := chi.URLParam(req, "schematicId")
  22. schematic, err := dao.GetSchematic(schematicID)
  23. if err != nil {
  24. Msg(response, http.StatusBadRequest, err.Error())
  25. return
  26. }
  27. render.JSON(response, req, schematic)
  28. }
  29. // GetTenantHandler gets a tenant
  30. func GetSchematicFileHandler(response http.ResponseWriter, req *http.Request) {
  31. //schematicID := chi.URLParam(req, "schematicId")
  32. fileID := chi.URLParam(req, "fileId")
  33. err := dao.GetFile(fileID, response)
  34. if err != nil {
  35. Msg(response, http.StatusBadRequest, err.Error())
  36. return
  37. }
  38. //render.JSON(response, req, schematic)
  39. }
  40. // GetTenantsHandler gets all tenants
  41. func GetSchematicsEndpoint(response http.ResponseWriter, req *http.Request) {
  42. /*
  43. var tenants []dto.Tenant
  44. err := dao.Get().All("tenants", &tenants)
  45. if err != nil {
  46. Msg(response, http.StatusBadRequest, err.Error())
  47. return
  48. }
  49. */
  50. render.JSON(response, req, "tenants")
  51. }
  52. func PostSchematicEndpoint(response http.ResponseWriter, req *http.Request) {
  53. }
  54. func DeleteSchematicEndpoint(response http.ResponseWriter, req *http.Request) {
  55. /*
  56. schematicID := chi.URLParam(req, "schematicId")
  57. if err != nil {
  58. Msg(response, http.StatusBadRequest, err.Error())
  59. return
  60. }
  61. */
  62. render.JSON(response, req, "tenant")
  63. }
  64. func UpdateSchematicEndpoint(response http.ResponseWriter, req *http.Request) {
  65. /*
  66. schematicID := chi.URLParam(req, "schematicId")
  67. err := dao.Get().One("tenants", chi.URLParam(req, "schematicId"), &tenant)
  68. if err != nil {
  69. Msg(response, http.StatusBadRequest, err.Error())
  70. return
  71. }
  72. */
  73. render.JSON(response, req, "tenant")
  74. }