added blog posting
This commit is contained in:
@@ -18,8 +18,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.Rawley Fow
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -67,12 +67,19 @@ func CreateBlogPost(c *gin.Context) {
|
|||||||
c.Status(403)
|
c.Status(403)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(c.Request.Body)
|
raw, err := ioutil.ReadAll(c.Request.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Status(406)
|
c.Status(406)
|
||||||
return
|
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 {
|
func GetAllBlogPosts() *[]models.BlogPost {
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ import (
|
|||||||
|
|
||||||
type Comment struct {
|
type Comment struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Id uint `json:"id"`
|
Id uint `json:"id"`
|
||||||
Date string `json:"date"`
|
Date string `json:"date"`
|
||||||
Author string `json:"author"`
|
Author string `json:"author"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user