subhub/handlers/groups/post.go
2019-09-19 10:14:22 +03:00

32 lines
655 B
Go

package groups
import (
"git.macaw.me/inhosin/subhub/data"
"git.macaw.me/inhosin/subhub/data/models"
"github.com/gin-gonic/gin"
"net/http"
)
type createGroupRequest struct {
Name string `json:"name"`
Status string `json:"status"`
}
type createGroupResponse struct {
Slug string `json:"slug"`
}
// Create adds an group to the database
func Create(c *gin.Context) {
var body createGroupRequest
_ = c.BindJSON(&body)
slug, err := models.PutGroup(data.GetDB(), body.Name, body.Status)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
resp := createGroupResponse{Slug: slug}
c.JSON(http.StatusOK, resp)
}