first commit
This commit is contained in:
63
api/attendanceHandler.go
Normal file
63
api/attendanceHandler.go
Normal file
@@ -0,0 +1,63 @@
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user