diff --git a/controllers/blog.go b/controllers/blog.go index 6e8f56e..b4f35f7 100644 --- a/controllers/blog.go +++ b/controllers/blog.go @@ -18,8 +18,8 @@ along with this program. If not, see .Rawley Fow */ import ( + "encoding/json" "io/ioutil" - "log" "net/http" "github.com/gin-gonic/gin" @@ -67,12 +67,19 @@ func CreateBlogPost(c *gin.Context) { c.Status(403) return } - data, err := ioutil.ReadAll(c.Request.Body) + raw, err := ioutil.ReadAll(c.Request.Body) if err != nil { c.Status(406) return } - log.Println(data) + var data models.BlogPost + // Write the data from the request to the data variable + if json.Unmarshal([]byte(raw), &data) != nil { + c.Status(406) + return + } + // Create the blog post in the database + db.Create(&data) } func GetAllBlogPosts() *[]models.BlogPost { diff --git a/models/comment.go b/models/comment.go index ca67103..f8e9a5a 100644 --- a/models/comment.go +++ b/models/comment.go @@ -22,8 +22,8 @@ import ( type Comment struct { gorm.Model - Id uint `json:"id"` - Date string `json:"date"` - Author string `json:"author"` + Id uint `json:"id"` + Date string `json:"date"` + Author string `json:"author"` Content string `json:"content"` }