From f13a07aa433298de91e1c4aff68f72be6d851be2 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Mon, 6 Jun 2022 02:49:05 +0200 Subject: Initial commit --- controller/controller.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 controller/controller.go (limited to 'controller') diff --git a/controller/controller.go b/controller/controller.go new file mode 100644 index 0000000..f89d267 --- /dev/null +++ b/controller/controller.go @@ -0,0 +1,44 @@ +package controller + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "gitlab.com/gabrielgio/midr/db" +) + +func GetEntries(c *gin.Context) { + var entries []db.YdlEntry + db.DB.Find(&entries) + c.HTML(http.StatusOK, "index", entries) +} + +func GetEntry(c *gin.Context) { + var entry db.YdlEntry + id := c.Param("id") + where := "id = " + id + db.DB.Where(where).FirstOrInit(&entry) + c.HTML(http.StatusOK, "entry", entry) +} + +func UpdateEntry(c *gin.Context) { + var entry db.YdlEntry + c.ShouldBind(&entry) + db.DB.Save(&entry) + c.HTML(http.StatusOK, "entry", entry) +} + +func CreateEntry(c *gin.Context) { + var entry db.YdlEntry + c.ShouldBind(&entry) + db.DB.Create(&entry) + c.Redirect(http.StatusFound, "/") + +} + +func DeleteEntry(c *gin.Context) { + var entry db.YdlEntry + id := c.Param("id") + db.DB.Delete(&entry, id) + c.HTML(http.StatusOK, "entry", entry) +} -- cgit v1.2.3