1package controller
2
3import (
4 "net/http"
5
6 "github.com/gin-gonic/gin"
7 "gitlab.com/gabrielgio/midr/db"
8)
9
10func GetEntries(c *gin.Context) {
11 var entries []db.YdlEntry
12 db.DB.Find(&entries)
13 c.HTML(http.StatusOK, "index", entries)
14}
15
16func GetEntry(c *gin.Context) {
17 var entry db.YdlEntry
18 id := c.Param("id")
19 where := "id = " + id
20 db.DB.Where(where).FirstOrInit(&entry)
21 c.HTML(http.StatusOK, "entry", entry)
22}
23
24func UpdateEntry(c *gin.Context) {
25 var entry db.YdlEntry
26 c.ShouldBind(&entry)
27 db.DB.Save(&entry)
28 c.HTML(http.StatusOK, "entry", entry)
29}
30
31func CreateEntry(c *gin.Context) {
32 var entry db.YdlEntry
33 c.ShouldBind(&entry)
34 db.DB.Create(&entry)
35 c.Redirect(http.StatusFound, "/")
36
37}
38
39func DeleteEntry(c *gin.Context) {
40 var entry db.YdlEntry
41 id := c.Param("id")
42 db.DB.Delete(&entry, id)
43 c.HTML(http.StatusOK, "entry", entry)
44}