62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func (a *Api) SetupRouter() {
|
|
api := a.Router.Group("/api")
|
|
{
|
|
tableGroup := api.Group("/tables")
|
|
{
|
|
tableGroup.GET("", a.getTables)
|
|
tableGroup.POST("", a.createTable)
|
|
tableGroup.DELETE("", a.deleteTable)
|
|
}
|
|
orderGroup := api.Group("/orders")
|
|
{
|
|
orderGroup.GET("", a.getOrders)
|
|
orderGroup.POST("", a.createOrder)
|
|
orderGroup.DELETE("", a.deleteOrder)
|
|
orderGroup.PUT("", a.updateOrder)
|
|
orderGroup.GET("/ws", a.serveWs)
|
|
orderItemGroup := orderGroup.Group("/items")
|
|
{
|
|
orderItemGroup.GET("", a.getOrderItems)
|
|
orderItemGroup.POST("", a.createOrderItem)
|
|
orderItemGroup.PUT("", a.updateOrderItem)
|
|
orderItemGroup.DELETE("/:id", a.deleteOrderItem)
|
|
}
|
|
}
|
|
billGroup := api.Group("/bills")
|
|
{
|
|
billGroup.GET("", a.getBills)
|
|
billGroup.POST("", a.createBill)
|
|
billGroup.DELETE("/:id", a.deleteBill)
|
|
billItemGroup := billGroup.Group("/items")
|
|
{
|
|
billItemGroup.GET("", a.getBillItems)
|
|
}
|
|
}
|
|
userGroup := api.Group("/users")
|
|
{
|
|
userGroup.GET("/:username", a.getUser)
|
|
userGroup.PUT("", a.updateUser)
|
|
}
|
|
health := api.Group("/health")
|
|
{
|
|
health.Use(authHeader())
|
|
health.GET("", func(c *gin.Context) {
|
|
c.Status(http.StatusOK)
|
|
})
|
|
}
|
|
}
|
|
|
|
a.Router.NoRoute(func(c *gin.Context) {
|
|
c.HTML(http.StatusOK, "index.html", nil)
|
|
})
|
|
logrus.WithField("amount", len(a.Router.Routes())).Debug("Routes initialized")
|
|
}
|