Files
memberDB/api/attendanceHandler.go
Adrian Zürcher 75ea1362a8 first commit
2025-10-08 15:02:07 +02:00

64 lines
1.0 KiB
Go

package api
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
)
func (a *APIHandler) StartNewEvent(c *gin.Context) {
if !a.databaseOpened(c) {
return
}
name := c.Query("name")
if name == "" {
c.JSON(http.StatusBadRequest, gin.H{
"message": "missing query 'name'",
})
return
}
if err := a.DbHandler.StartNewEvent(name); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"message": err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{
"message": "New Event added " + name,
})
}
func (a *APIHandler) GetEventById(c *gin.Context) {
if !a.databaseOpened(c) {
return
}
var i int
var err error
id := c.Query("id")
if id != "" {
i, err = strconv.Atoi(id)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"message": err.Error(),
})
return
}
}
events, err := a.DbHandler.GetEvent(i)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"message": err.Error(),
})
return
}
c.JSON(http.StatusOK, events)
}