aboutsummaryrefslogtreecommitdiff
path: root/controller
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2022-06-06 02:49:05 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2022-06-06 02:49:05 +0200
commitf13a07aa433298de91e1c4aff68f72be6d851be2 (patch)
tree5ebb10ed5f91b251ccc16c74a631448b5abb6145 /controller
downloadmdir-f13a07aa433298de91e1c4aff68f72be6d851be2.tar.gz
mdir-f13a07aa433298de91e1c4aff68f72be6d851be2.tar.bz2
mdir-f13a07aa433298de91e1c4aff68f72be6d851be2.zip
Initial commit
Diffstat (limited to 'controller')
-rw-r--r--controller/controller.go44
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)
+}