diff options
Diffstat (limited to 'controller')
-rw-r--r-- | controller/controller.go | 44 |
1 files changed, 44 insertions, 0 deletions
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) +} |