51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package controller
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
// @Schemes
|
|
// @Summary get all active tables
|
|
// @Description gets all active tables as array
|
|
// @Tags tables
|
|
// @Produce json
|
|
// @Success 200 {array} Table
|
|
// @Router /tables [get]
|
|
func (c *Controller) GetTables(ctx echo.Context) error {
|
|
return ctx.JSON(http.StatusOK, c.GetAllTables())
|
|
}
|
|
|
|
// @Schemes
|
|
// @Summary create new table
|
|
// @Description creates a new table and returns it
|
|
// @Tags tables
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 201 {object} Table "Table has been created"
|
|
// @Failure 500 "Internal Server Error"
|
|
// @Router /tables [post]
|
|
func (c *Controller) CreateTable(ctx echo.Context) error {
|
|
table, err := c.CreateNewTable()
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
|
|
}
|
|
return ctx.JSON(http.StatusCreated, table)
|
|
}
|
|
|
|
// @Schemes
|
|
// @Summary delete the latest table
|
|
// @Description deletes the latest table from the database
|
|
// @Tags tables
|
|
// @Produce json
|
|
// @Success 200 "OK"
|
|
// @Failure 500 "Internal Server Error"
|
|
// @Router /tables [delete]
|
|
func (c *Controller) DeleteTable(ctx echo.Context) error {
|
|
err := c.DeleteLatestTable()
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
|
|
}
|
|
return ctx.NoContent(http.StatusOK)
|
|
}
|