package webserver

import (
	"git.ctdo.de/henne/blitzer-v2/db"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

func HandleIndex(ctx *gin.Context) {
	var speedingTickets []db.SpeedingTicket
	if err := db.DB.Find(&speedingTickets).Error; err != nil {
		logrus.Error(err)
		ctx.String(500, "internal server error")
		return
	}
	err := templates.ExecuteTemplate(ctx.Writer, "index", gin.H{
		"SpeedingTickets": speedingTickets,
	})
	if err != nil {
		logrus.Error(err)
	}
}
