subhub/handlers/groups/get.go

42 lines
946 B
Go
Raw Normal View History

2019-09-07 14:54:53 +00:00
package groups
import (
"fmt"
"git.macaw.me/inhosin/subhub/activitypub"
"git.macaw.me/inhosin/subhub/data"
"git.macaw.me/inhosin/subhub/data/models"
"git.macaw.me/inhosin/subhub/handlers"
"github.com/gin-gonic/gin"
"net/http"
)
// Get returns a Group
//
// Expects a `{name}` url variable
2019-09-19 07:14:22 +00:00
// in the route: `/group/:name`
2019-09-07 14:54:53 +00:00
func Get(c *gin.Context) {
name := c.Param("name")
if name == "" {
c.String(http.StatusBadRequest, "Bad request! No name in URL")
return
}
group, err := models.GetGroup(data.GetDB(), name)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
if group == nil {
c.String(http.StatusNotFound, fmt.Sprintf("%s does not exits on server", name))
return
}
2019-09-19 07:14:22 +00:00
url := handlers.GetFullHostName() + "/group/" + group.Id
2019-09-07 14:54:53 +00:00
actor := activitypub.NewPerson(url)
actor.PreferredUsername = group.Name
actor.Name = group.Name
actor.Summary = group.Note
c.JSON(http.StatusOK, actor)
}