From 7ae8d1a6af2e322c60f69528f7979764c42130c5 Mon Sep 17 00:00:00 2001 From: b3t0 Date: Wed, 21 Feb 2024 20:27:14 -0600 Subject: [PATCH] PostsDelete done --- controllers/postController.go | 11 +++++++++++ main.go | 1 + 2 files changed, 12 insertions(+) diff --git a/controllers/postController.go b/controllers/postController.go index 120462f..0647367 100644 --- a/controllers/postController.go +++ b/controllers/postController.go @@ -85,3 +85,14 @@ func PostsUpdate(c *gin.Context) { }) } + +func PostsDelete(c *gin.Context) { + // Get the id off the url + id := c.Param("id") + + // Delete the posts + initializers.DB.Delete(&models.Post{}, id) + + // Responmd + c.Status(200) +} diff --git a/main.go b/main.go index 3c8e567..c93da0f 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ func main() { r.PUT("/posts/:id", controllers.PostsUpdate) r.GET("/posts", controllers.PostsIndex) r.GET("/posts/:id", controllers.PostsShow) + r.DELETE("/posts/:id", controllers.PostsDelete) r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") }