add some works
This commit is contained in:
parent
cd9ec0c774
commit
8807e5aaab
22 changed files with 1074 additions and 3 deletions
41
handlers/groups/get.go
Normal file
41
handlers/groups/get.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
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)
|
||||
}
|
32
handlers/groups/post.go
Normal file
32
handlers/groups/post.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue