bing work with gorm
This commit is contained in:
parent
8807e5aaab
commit
61b976259a
7 changed files with 203 additions and 13 deletions
|
@ -19,7 +19,7 @@ type createGroupResponse struct {
|
|||
// Create adds an group to the database
|
||||
func Create(c *gin.Context) {
|
||||
var body createGroupRequest
|
||||
c.BindJSON(&body)
|
||||
_ = c.BindJSON(&body)
|
||||
|
||||
db := data.GetDB()
|
||||
slug, err := models.PutGroup(db, body.Name, body.Note)
|
||||
|
|
53
handlers/note/get.go
Normal file
53
handlers/note/get.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue