subhub/handlers/groups/post.go

33 lines
657 B
Go
Raw Permalink 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 {
Name string `json:"name"`
Note string `json:"note"`
}
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
db := data.GetDB()
slug, err := models.PutGroup(db, body.Name, body.Note)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
resp := createGroupResponse{Slug: slug}
c.JSON(http.StatusOK, resp)
}