Add admin index page
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user