This commit is contained in:
inhosin 2019-09-19 10:14:22 +03:00
parent 61b976259a
commit d6387c3528
9 changed files with 69 additions and 81 deletions

View file

@ -13,7 +13,7 @@ import (
// Get returns a Group
//
// Expects a `{name}` url variable
// in the route: `/api/group/:name`
// in the route: `/group/:name`
func Get(c *gin.Context) {
name := c.Param("name")
if name == "" {
@ -31,7 +31,7 @@ func Get(c *gin.Context) {
return
}
url := handlers.GetFullHostName() + "/activity/group/" + group.Slug
url := handlers.GetFullHostName() + "/group/" + group.Id
actor := activitypub.NewPerson(url)
actor.PreferredUsername = group.Name
actor.Name = group.Name

View file

@ -8,8 +8,8 @@ import (
)
type createGroupRequest struct {
Name string `json:"name"`
Note string `json:"note"`
Name string `json:"name"`
Status string `json:"status"`
}
type createGroupResponse struct {
@ -21,8 +21,7 @@ func Create(c *gin.Context) {
var body createGroupRequest
_ = c.BindJSON(&body)
db := data.GetDB()
slug, err := models.PutGroup(db, body.Name, body.Note)
slug, err := models.PutGroup(data.GetDB(), body.Name, body.Status)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return

View file

@ -1,53 +0,0 @@
package note
import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/gorilla/mux"
"net/http"
"net/url"
)
// Get returns a Note
//
// Expects a `{noteid}` url variable
// in the route: `/api/note/{noteid}`
func Get(c *gin.Context) {
noteId := c.Param("noteid")
if noteId == "" {
c.String(http.StatusInternalServerError, "Bad request, no slug in url")
return
}
// Attempt to grab the Note
note, err := models.GetNote(data.GetPool(), noteId)
// 500 because something went wrong with the database
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// 404 because something we couldn't find the show
if show == nil {
http.Error(w, slug+" does not exist on this server", http.StatusNotFound)
return
}
// Convert to an ActivityPub object
url, err := url.Parse(handlers.GetFullHostname() + "/api/show/" + slug)
actor := activity.NewOrganization(show.Name, url)
// Turn the show into JSON
bytes, err := json.Marshal(actor)
// 500 because something went wrong marshaling the show
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Success!
w.Write(bytes)
}

44
handlers/status/get.go Normal file
View file

@ -0,0 +1,44 @@
package status
import (
"github.com/gin-gonic/gin"
_ "github.com/gorilla/mux"
)
// Get returns a Note
//
// Expects a `{statusid}` url variable
// in the route: `/status/{statusid}`
func Get(c *gin.Context) {
/*
statusId := c.Param("statusid")
if statusId == "" {
c.String(http.StatusInternalServerError, "Bad request, no status id in url")
return
}
// Attempt to grab the Activity
status, err := models.GetActivity(data.GetDB(), statusId)
// 500 because something went wrong with the database
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
// 404 because something we couldn't find the status
if status == nil {
c.String(http.StatusNotFound, statusId+" does not exist on this server")
return
}
// Convert to an ActivityPub object
url, err := url.Parse(handlers.GetFullHostName() + "/status/" + statusId)
o := activitypub.NewAnounceObject()
activity := activitypub.NewCreateActivity(0)
c.JSON(http.StatusOK, activity)
//w.Write(bytes)
*/
}

View file

@ -33,11 +33,6 @@ func Get(c *gin.Context) {
c.String(http.StatusBadRequest, "Account not found")
}
// bytes, err := json.Marshal(actor)
// if err != nil {
// http.Error(w, err.Error(), http.StatusBadRequest)
// return
// }
c.JSON(http.StatusOK, actor)
}