Working on next alarm retrieval
This commit is contained in:
parent
6e54ad1a87
commit
9a06d04ce0
8 changed files with 261 additions and 40 deletions
|
|
@ -13,7 +13,13 @@ import (
|
|||
|
||||
func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *gin.RouterGroup) {
|
||||
router.GET("/alarms/next", func(c *gin.Context) {
|
||||
alarm, err := reveil.GetNextAlarm(db)
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, alarm)
|
||||
})
|
||||
|
||||
router.GET("/alarms/single", func(c *gin.Context) {
|
||||
|
|
@ -24,7 +30,6 @@ func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *
|
|||
}
|
||||
|
||||
c.JSON(http.StatusOK, alarms)
|
||||
|
||||
})
|
||||
router.POST("/alarms/single", func(c *gin.Context) {
|
||||
var alarm reveil.AlarmSingle
|
||||
|
|
@ -100,7 +105,7 @@ func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *
|
|||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "End date is already passed."})
|
||||
return
|
||||
}
|
||||
if !time.Time(*alarm.End).After(time.Time(*alarm.Start)) {
|
||||
if time.Time(*alarm.Start).After(time.Time(*alarm.End)) {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Start is defined after End. Please verify your inputs."})
|
||||
return
|
||||
}
|
||||
|
|
@ -184,7 +189,11 @@ func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *
|
|||
})
|
||||
|
||||
repeatedAlarmsRoutes.GET("", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, c.MustGet("alarm"))
|
||||
alarm := c.MustGet("alarm").(*reveil.AlarmRepeated)
|
||||
alarm.FillExcepts(db)
|
||||
alarm.NextTime = alarm.GetNextOccurence(db)
|
||||
|
||||
c.JSON(http.StatusOK, alarm)
|
||||
})
|
||||
repeatedAlarmsRoutes.PUT("", func(c *gin.Context) {
|
||||
oldalarm := c.MustGet("alarm").(*reveil.AlarmRepeated)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue