package api import ( "net/http" "vegan-barcode/internal/database" "vegan-barcode/internal/utils" "github.com/gin-gonic/gin" "github.com/labstack/gommon/log" "github.com/sirupsen/logrus" "github.com/vingarcia/ksql" ) // TODO Figure out where this should be // This exists so that you don't have to individually pass around the logger and database. type ApiService struct { db *ksql.DB log *logrus.Logger } var s *ApiService // TODO: Service should get moved somewhere else. Not sure on naming. func BindRoutes() { s = &ApiService{db: database.InitializeDatabase(), log: utils.InitializeLogger()} // s = &ApiService{db: &ksql.DB{}, log: utils.InitializeLogger()} router := gin.Default() router.GET("/test/:id", s.runTest) router.GET("/", s.runTest) // // Search for item info // router.GET("/claims/{barcode}", runTest) // // by user ID or worker // router.DELETE("/claims/{barcode}", deleteClaims) // // Update item info // router.GET("/test", runTest) // // Add new item info router.Run("localhost:8080") } func (s *ApiService) runTest(c *gin.Context) { queryParam := c.Param("id") log.Debug("Test was successful.") c.JSON(http.StatusOK, gin.H{"message": "Hello World!", "query_param": queryParam}) } // func claimsByBarcode(c *gin.Context) { // system := c.DefaultQuery("system", "upc") // barcode := c.Query("barcode") // } // // deleteClaims will delete // func deleteClaims(c *gin.Context) { // userID := c.Param("user") // workerID := c.Param("worker") // // TODO query database // database.DB.Query() // c.JSON(http.StatusOK, gin.H{"message": "Hello World!"}) // }