Init
This commit is contained in:
commit
f90fdc0598
99 changed files with 15260 additions and 0 deletions
54
api/routesTable.go
Normal file
54
api/routesTable.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue