diff --git a/database/admin.go b/database/admin.go new file mode 100644 index 0000000..19bc533 --- /dev/null +++ b/database/admin.go @@ -0,0 +1,51 @@ +package database + +import ( + "context" + "github.com/gin-gonic/gin" + "github.com/jackc/pgx/v4/pgxpool" + "log" + "trikotwaschliste/models" +) + +func DbAdminMainpage(pool *pgxpool.Pool) gin.H { + var items []models.Washlist + var persons []models.Person + + witems, err := pool.Query(context.Background(), "SELECT wa.id, pe.name, ga.created_at, wa.washed \nFROM washlist wa\nINNER JOIN persons pe ON wa.personid = pe.id\nINNER JOIN gamedata ga ON wa.gamedataid = ga.id ORDER BY ga.created_at ASC") + if err != nil { + log.Println(err.Error()) + } + + var item models.Washlist + for witems.Next() { + err = witems.Scan(&item.Id, &item.Person, &item.Date, &item.Washed) + if err != nil { + log.Println(err.Error()) + } + item.DateString = item.Date.Format(layoutDE) + items = append(items, item) + } + + // get persons + wperson, err := pool.Query(context.Background(), "SELECT id, name FROM persons ORDER BY name ASC") + if err != nil { + log.Println(err.Error()) + } + + persons = append(persons, models.Person{ + Id: -1, + Name: "-- Auswählen --", + }) + var person models.Person + for wperson.Next() { + err = wperson.Scan(&person.Id, &person.Name) + if err != nil { + log.Println(err.Error()) + } + persons = append(persons, person) + } + + + return gin.H{"items": items, "persons": persons} +} diff --git a/handler/admin.go b/handler/admin.go new file mode 100644 index 0000000..91730ae --- /dev/null +++ b/handler/admin.go @@ -0,0 +1,14 @@ +package handler + +import ( + "github.com/gin-gonic/gin" + "github.com/jackc/pgx/v4/pgxpool" + "net/http" + "trikotwaschliste/database" +) + +func AdminMainPage(pool *pgxpool.Pool) gin.HandlerFunc { + return func(c *gin.Context) { + c.HTML(http.StatusAccepted, "adminindex.html", database.DbAdminMainpage(pool)) + } +} diff --git a/handler/mainpage.go b/handler/mainpage.go index 6fbd8ff..a28d5cd 100644 --- a/handler/mainpage.go +++ b/handler/mainpage.go @@ -25,6 +25,6 @@ func UploadName(pool *pgxpool.Pool) gin.HandlerFunc { func Credits() gin.HandlerFunc { return func(c *gin.Context) { - c.HTML(http.StatusAccepted, "credits.html", gin.H{"version":"1.0"}) + c.HTML(http.StatusAccepted, "credits.html", gin.H{"version":"1.1"}) } } diff --git a/html/admin/adminindex.html b/html/admin/adminindex.html new file mode 100644 index 0000000..a26d5c5 --- /dev/null +++ b/html/admin/adminindex.html @@ -0,0 +1,56 @@ + + +
+ +Person | +Datum | +Waschperson | +
---|---|---|
{{$item.Person}} | +{{$item.DateString}} | +
+
+
+
+
+ |
+