PostIndex done
This commit is contained in:
@@ -25,8 +25,19 @@ func PostsCreate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Return it
|
//Return it
|
||||||
|
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"post": post,
|
"post": post,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PostsIndex(c *gin.Context) {
|
||||||
|
// Get the post
|
||||||
|
var posts []models.Post
|
||||||
|
initializers.DB.Find(&posts)
|
||||||
|
|
||||||
|
// Respond with them
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"posts": posts,
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
1
main.go
1
main.go
@@ -15,6 +15,7 @@ func main() {
|
|||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
|
|
||||||
r.POST("/posts", controllers.PostsCreate)
|
r.POST("/posts", controllers.PostsCreate)
|
||||||
|
r.GET("/posts", controllers.PostsIndex)
|
||||||
|
|
||||||
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
|
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user