Add admin index page

This commit is contained in:
2020-10-11 23:02:57 +02:00
parent e5c0df6f6f
commit 2a1ef7f2cb
5 changed files with 39 additions and 11 deletions

View File

@@ -5,21 +5,22 @@ import (
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v4/pgxpool"
"log"
"strconv"
"trikotwaschliste/models"
)
func DbAdminMainpage(pool *pgxpool.Pool) gin.H {
var items []models.Washlist
var items []models.WashlistAdmin
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")
witems, err := pool.Query(context.Background(), "SELECT wa.id, wa.personid, ga.created_at\nFROM washlist wa\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
var item models.WashlistAdmin
for witems.Next() {
err = witems.Scan(&item.Id, &item.Person, &item.Date, &item.Washed)
err = witems.Scan(&item.Id, &item.PersonId, &item.Date)
if err != nil {
log.Println(err.Error())
}
@@ -49,3 +50,14 @@ func DbAdminMainpage(pool *pgxpool.Pool) gin.H {
return gin.H{"items": items, "persons": persons}
}
func ChangeName(pool *pgxpool.Pool, id, personID string) bool {
sID, _ := strconv.Atoi(id)
if sID <= 0 {
return false
}
pool.Exec(context.Background(), "UPDATE washlist SET personid = $1 WHERE id = $2", id, personID)
return true
}