30 lines
692 B
Go
30 lines
692 B
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/jackc/pgx/v4/pgxpool"
|
|
"log"
|
|
"trikotwaschliste/models"
|
|
)
|
|
|
|
func DbMainpage(pool *pgxpool.Pool) gin.H {
|
|
var items []models.Washlist
|
|
|
|
witems, err := pool.Query(context.Background(), "SELECT 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")
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
}
|
|
|
|
var item models.Washlist
|
|
for witems.Next() {
|
|
err = witems.Scan(&item.Person, &item.Date, &item.IsWashed)
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
}
|
|
items = append(items, item)
|
|
}
|
|
|
|
return gin.H{"items": items}
|
|
}
|