PostIndex done

This commit is contained in:
2024-02-21 19:33:41 -06:00
parent 4e4d52527f
commit 455de5a771
3 changed files with 13 additions and 1 deletions

View File

@@ -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,
})
}

BIN
go-crud

Binary file not shown.

View File

@@ -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")
} }