added blog posting

This commit is contained in:
rawleyIfowler
2022-02-23 11:41:29 -06:00
parent 724f7b0034
commit 581e7e258a
2 changed files with 13 additions and 6 deletions

View File

@@ -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 {