42 lines
961 B
Go
42 lines
961 B
Go
|
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
|
||
|
// in the route: `/api/group/:name`
|
||
|
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
|
||
|
}
|
||
|
|
||
|
url := handlers.GetFullHostName() + "/activity/group/" + group.Slug
|
||
|
actor := activitypub.NewPerson(url)
|
||
|
actor.PreferredUsername = group.Name
|
||
|
actor.Name = group.Name
|
||
|
actor.Summary = group.Note
|
||
|
|
||
|
c.JSON(http.StatusOK, actor)
|
||
|
}
|