54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"cafe/service"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// @Schemes
|
|
// @Summary get all active tables
|
|
// @Description gets all active tables as array
|
|
// @Tags tables
|
|
// @Produce json
|
|
// @Success 200 {array} service.Table
|
|
// @Router /tables [get]
|
|
func (a *Api) getTables(c *gin.Context) {
|
|
c.JSON(http.StatusOK, service.GetAllTables())
|
|
}
|
|
|
|
// @Schemes
|
|
// @Summary create new table
|
|
// @Description creates a new table and returns it
|
|
// @Tags tables
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 201 {object} service.Table "Table has been created"
|
|
// @Failure 500 {object} errorResponse "Cannot create table"
|
|
// @Router /tables [post]
|
|
func (a *Api) createTable(c *gin.Context) {
|
|
table, err := service.CreateNewTable()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, errorResponse{err.Error()})
|
|
} else {
|
|
c.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 {object} errorResponse "Cannot delete table"
|
|
// @Router /tables [delete]
|
|
func (a *Api) deleteTable(c *gin.Context) {
|
|
err := service.DeleteLatestTable()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, errorResponse{err.Error()})
|
|
} else {
|
|
c.Status(http.StatusOK)
|
|
}
|
|
}
|