subhub/handlers/groups/post.go

32 lines
655 B
Go
Raw Normal View History

2019-09-07 14:54:53 +00:00
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 {
2019-09-19 07:14:22 +00:00
Name string `json:"name"`
Status string `json:"status"`
2019-09-07 14:54:53 +00:00
}
type createGroupResponse struct {
Slug string `json:"slug"`
}
// Create adds an group to the database
func Create(c *gin.Context) {
var body createGroupRequest
2019-09-07 16:10:28 +00:00
_ = c.BindJSON(&body)
2019-09-07 14:54:53 +00:00
2019-09-19 07:14:22 +00:00
slug, err := models.PutGroup(data.GetDB(), body.Name, body.Status)
2019-09-07 14:54:53 +00:00
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
resp := createGroupResponse{Slug: slug}
c.JSON(http.StatusOK, resp)
}