33 lines
657 B
Go
33 lines
657 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"`
|
|
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
|
|
_ = c.BindJSON(&body)
|
|
|
|
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)
|
|
}
|