Event on next alarm reached

This commit is contained in:
nemunaire 2022-10-06 14:17:58 +02:00
commit fffdccc7b8
3 changed files with 56 additions and 16 deletions

View file

@ -11,7 +11,7 @@ import (
"git.nemunai.re/nemunaire/reveil/model"
)
func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *gin.RouterGroup) {
func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, resetTimer func(), router *gin.RouterGroup) {
router.GET("/alarms/next", func(c *gin.Context) {
alarm, err := reveil.GetNextAlarm(db)
if err != nil {
@ -49,6 +49,8 @@ func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *
return
}
resetTimer()
c.JSON(http.StatusOK, alarm)
})
@ -74,6 +76,8 @@ func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *
return
}
resetTimer()
c.JSON(http.StatusOK, alarm)
})
@ -116,6 +120,8 @@ func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *
return
}
resetTimer()
c.JSON(http.StatusOK, alarm)
})
@ -156,6 +162,8 @@ func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *
return
}
resetTimer()
c.JSON(http.StatusOK, alarm)
})
singleAlarmsRoutes.DELETE("", func(c *gin.Context) {
@ -166,6 +174,8 @@ func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *
return
}
resetTimer()
c.JSON(http.StatusOK, nil)
})
@ -210,6 +220,8 @@ func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *
return
}
resetTimer()
c.JSON(http.StatusOK, alarm)
})
repeatedAlarmsRoutes.DELETE("", func(c *gin.Context) {
@ -220,6 +232,8 @@ func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *
return
}
resetTimer()
c.JSON(http.StatusOK, nil)
})
@ -260,6 +274,8 @@ func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *
return
}
resetTimer()
c.JSON(http.StatusOK, alarm)
})
exceptionAlarmsRoutes.DELETE("", func(c *gin.Context) {
@ -270,6 +286,8 @@ func declareAlarmsRoutes(cfg *config.Config, db *reveil.LevelDBStorage, router *
return
}
resetTimer()
c.JSON(http.StatusOK, nil)
})
}

View file

@ -7,11 +7,11 @@ import (
"git.nemunai.re/nemunaire/reveil/model"
)
func DeclareRoutes(router *gin.Engine, cfg *config.Config, db *reveil.LevelDBStorage) {
func DeclareRoutes(router *gin.Engine, cfg *config.Config, db *reveil.LevelDBStorage, resetTimer func()) {
apiRoutes := router.Group("/api")
declareActionsRoutes(cfg, apiRoutes)
declareAlarmsRoutes(cfg, db, apiRoutes)
declareAlarmsRoutes(cfg, db, resetTimer, apiRoutes)
declareGongsRoutes(cfg, apiRoutes)
declareHistoryRoutes(cfg, apiRoutes)
declareQuotesRoutes(cfg, apiRoutes)