From a9be05854c69c706aa4609a8ee51a1f90bbfa0a0 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Sun, 2 Oct 2022 23:24:53 +0200 Subject: [PATCH] Mock API --- api/actions.go | 37 +++++++++++++++++++++ api/alarms.go | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ api/gongs.go | 37 +++++++++++++++++++++ api/history.go | 13 ++++++++ api/quotes.go | 47 ++++++++++++++++++++++++++ api/routes.go | 19 +++++------ api/routines.go | 37 +++++++++++++++++++++ api/settings.go | 16 +++++++++ api/tracks.go | 37 +++++++++++++++++++++ config/cli.go | 10 +++++- config/config.go | 4 +++ 11 files changed, 331 insertions(+), 12 deletions(-) create mode 100644 api/actions.go create mode 100644 api/alarms.go create mode 100644 api/gongs.go create mode 100644 api/history.go create mode 100644 api/quotes.go create mode 100644 api/routines.go create mode 100644 api/settings.go create mode 100644 api/tracks.go diff --git a/api/actions.go b/api/actions.go new file mode 100644 index 0000000..0f79a27 --- /dev/null +++ b/api/actions.go @@ -0,0 +1,37 @@ +package api + +import ( + "net/http" + + "github.com/gin-gonic/gin" + + "git.nemunai.re/nemunaire/reveil/config" +) + +func declareActionsRoutes(cfg *config.Config, router *gin.RouterGroup) { + router.GET("/actions", func(c *gin.Context) { + + }) + router.POST("/actions", func(c *gin.Context) { + + }) + + actionsRoutes := router.Group("/actions/:gid") + actionsRoutes.Use(actionHandler) + + actionsRoutes.GET("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("action")) + }) + actionsRoutes.PUT("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("action")) + }) + actionsRoutes.DELETE("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("action")) + }) +} + +func actionHandler(c *gin.Context) { + c.Set("action", nil) + + c.Next() +} diff --git a/api/alarms.go b/api/alarms.go new file mode 100644 index 0000000..bcb82db --- /dev/null +++ b/api/alarms.go @@ -0,0 +1,86 @@ +package api + +import ( + "net/http" + + "github.com/gin-gonic/gin" + + "git.nemunai.re/nemunaire/reveil/config" +) + +func declareAlarmsRoutes(cfg *config.Config, router *gin.RouterGroup) { + router.GET("/alarms/next", func(c *gin.Context) { + + }) + + router.POST("/alarms", func(c *gin.Context) { + + }) + + router.GET("/alarms/manuals", func(c *gin.Context) { + + }) + router.GET("/alarms/usuals", func(c *gin.Context) { + + }) + router.GET("/alarms/excepts", func(c *gin.Context) { + + }) + + manualAlarmsRoutes := router.Group("/alarms/manuals/:aid") + manualAlarmsRoutes.Use(manualAlarmHandler) + + manualAlarmsRoutes.GET("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("alarm")) + }) + manualAlarmsRoutes.PUT("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("alarm")) + }) + manualAlarmsRoutes.DELETE("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("alarm")) + }) + + usualAlarmsRoutes := router.Group("/alarms/usuals/:aid") + usualAlarmsRoutes.Use(usualAlarmHandler) + + usualAlarmsRoutes.GET("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("alarm")) + }) + usualAlarmsRoutes.PUT("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("alarm")) + }) + usualAlarmsRoutes.DELETE("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("alarm")) + }) + + exceptAlarmsRoutes := router.Group("/alarms/excepts/:aid") + exceptAlarmsRoutes.Use(exceptAlarmHandler) + + exceptAlarmsRoutes.GET("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("alarm")) + }) + exceptAlarmsRoutes.PUT("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("alarm")) + }) + exceptAlarmsRoutes.DELETE("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("alarm")) + }) +} + +func manualAlarmHandler(c *gin.Context) { + c.Set("alarm", nil) + + c.Next() +} + +func usualAlarmHandler(c *gin.Context) { + c.Set("alarm", nil) + + c.Next() +} + +func exceptAlarmHandler(c *gin.Context) { + c.Set("alarm", nil) + + c.Next() +} diff --git a/api/gongs.go b/api/gongs.go new file mode 100644 index 0000000..985b777 --- /dev/null +++ b/api/gongs.go @@ -0,0 +1,37 @@ +package api + +import ( + "net/http" + + "github.com/gin-gonic/gin" + + "git.nemunai.re/nemunaire/reveil/config" +) + +func declareGongsRoutes(cfg *config.Config, router *gin.RouterGroup) { + router.GET("/gongs", func(c *gin.Context) { + + }) + router.POST("/gongs", func(c *gin.Context) { + + }) + + gongsRoutes := router.Group("/gongs/:gid") + gongsRoutes.Use(gongHandler) + + gongsRoutes.GET("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("gong")) + }) + gongsRoutes.PUT("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("gong")) + }) + gongsRoutes.DELETE("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("gong")) + }) +} + +func gongHandler(c *gin.Context) { + c.Set("gong", nil) + + c.Next() +} diff --git a/api/history.go b/api/history.go new file mode 100644 index 0000000..0df39bc --- /dev/null +++ b/api/history.go @@ -0,0 +1,13 @@ +package api + +import ( + "github.com/gin-gonic/gin" + + "git.nemunai.re/nemunaire/reveil/config" +) + +func declareHistoryRoutes(cfg *config.Config, router *gin.RouterGroup) { + router.GET("/stats", func(c *gin.Context) { + + }) +} diff --git a/api/quotes.go b/api/quotes.go new file mode 100644 index 0000000..e3b43d6 --- /dev/null +++ b/api/quotes.go @@ -0,0 +1,47 @@ +package api + +import ( + "net/http" + + "github.com/gin-gonic/gin" + + "git.nemunai.re/nemunaire/reveil/config" +) + +func declareQuotesRoutes(cfg *config.Config, router *gin.RouterGroup) { + router.GET("/quoteoftheday", func(c *gin.Context) { + + }) + + router.GET("/quotes", func(c *gin.Context) { + + }) + router.POST("/quotes", func(c *gin.Context) { + + }) + + quotesRoutes := router.Group("/quotes/:qid") + quotesRoutes.Use(quoteHandler) + + quotesRoutes.GET("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("quote")) + }) + quotesRoutes.PUT("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("quote")) + }) + quotesRoutes.DELETE("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("quote")) + }) +} + +func quoteHandler(c *gin.Context) { + c.Set("quote", nil) + + c.Next() +} + +type Quote struct { + Id int `json:"id"` + Content string `json:"content"` + Author string `json:"author"` +} diff --git a/api/routes.go b/api/routes.go index 86b1b91..4db1252 100644 --- a/api/routes.go +++ b/api/routes.go @@ -1,23 +1,20 @@ package api import ( - "net/http" - "github.com/gin-gonic/gin" "git.nemunai.re/nemunaire/reveil/config" - //"git.nemunai.re/nemunaire/reveil/model" ) func DeclareRoutes(router *gin.Engine, cfg *config.Config) { apiRoutes := router.Group("/api") - apiRoutes.GET("/test", func(c *gin.Context) { - c.JSON(http.StatusOK, "test") - }) - - //declareFilesRoutes(cfg, apiAuthRoutes) - //declareIngredientsRoutes(cfg, apiAuthRoutes) - //declareRecipesRoutes(cfg, apiAuthRoutes) - //declareUsersRoutes(cfg, apiAuthRoutes) + declareActionsRoutes(cfg, apiRoutes) + declareAlarmsRoutes(cfg, apiRoutes) + declareGongsRoutes(cfg, apiRoutes) + declareHistoryRoutes(cfg, apiRoutes) + declareQuotesRoutes(cfg, apiRoutes) + declareRoutinesRoutes(cfg, apiRoutes) + declareTracksRoutes(cfg, apiRoutes) + declareSettingsRoutes(cfg, apiRoutes) } diff --git a/api/routines.go b/api/routines.go new file mode 100644 index 0000000..4be776e --- /dev/null +++ b/api/routines.go @@ -0,0 +1,37 @@ +package api + +import ( + "net/http" + + "github.com/gin-gonic/gin" + + "git.nemunai.re/nemunaire/reveil/config" +) + +func declareRoutinesRoutes(cfg *config.Config, router *gin.RouterGroup) { + router.GET("/routines", func(c *gin.Context) { + + }) + router.POST("/routines", func(c *gin.Context) { + + }) + + routinesRoutes := router.Group("/routines/:gid") + routinesRoutes.Use(routineHandler) + + routinesRoutes.GET("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("routine")) + }) + routinesRoutes.PUT("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("routine")) + }) + routinesRoutes.DELETE("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("routine")) + }) +} + +func routineHandler(c *gin.Context) { + c.Set("routine", nil) + + c.Next() +} diff --git a/api/settings.go b/api/settings.go new file mode 100644 index 0000000..3aa2f32 --- /dev/null +++ b/api/settings.go @@ -0,0 +1,16 @@ +package api + +import ( + "github.com/gin-gonic/gin" + + "git.nemunai.re/nemunaire/reveil/config" +) + +func declareSettingsRoutes(cfg *config.Config, router *gin.RouterGroup) { + router.GET("/settings", func(c *gin.Context) { + + }) + router.PUT("/settings", func(c *gin.Context) { + + }) +} diff --git a/api/tracks.go b/api/tracks.go new file mode 100644 index 0000000..be54d2e --- /dev/null +++ b/api/tracks.go @@ -0,0 +1,37 @@ +package api + +import ( + "net/http" + + "github.com/gin-gonic/gin" + + "git.nemunai.re/nemunaire/reveil/config" +) + +func declareTracksRoutes(cfg *config.Config, router *gin.RouterGroup) { + router.GET("/tracks", func(c *gin.Context) { + + }) + router.POST("/tracks", func(c *gin.Context) { + + }) + + tracksRoutes := router.Group("/tracks/:tid") + tracksRoutes.Use(trackHandler) + + tracksRoutes.GET("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("track")) + }) + tracksRoutes.PUT("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("track")) + }) + tracksRoutes.DELETE("", func(c *gin.Context) { + c.JSON(http.StatusOK, c.MustGet("track")) + }) +} + +func trackHandler(c *gin.Context) { + c.Set("track", nil) + + c.Next() +} diff --git a/config/cli.go b/config/cli.go index 172c537..8b4ad88 100644 --- a/config/cli.go +++ b/config/cli.go @@ -10,6 +10,10 @@ func (c *Config) declareFlags() { flag.StringVar(&c.BaseURL, "baseurl", c.BaseURL, "URL prepended to each URL") flag.StringVar(&c.Bind, "bind", c.Bind, "Bind port/socket") flag.StringVar(&c.DevProxy, "dev", c.DevProxy, "Use ui directory instead of embedded assets") + flag.StringVar(&c.TracksDir, "tracks-dir", c.TracksDir, "Path to the directory containing the tracks") + flag.StringVar(&c.GongsDir, "gongs-dir", c.GongsDir, "Path to the directory containing the gongs") + flag.StringVar(&c.ActionsDir, "actions-dir", c.ActionsDir, "Path to the directory containing the actions") + flag.StringVar(&c.RoutinesDir, "routines-dir", c.RoutinesDir, "Path to the directory containing the routines") // Others flags are declared in some other files when they need specials configurations } @@ -17,7 +21,11 @@ func (c *Config) declareFlags() { func Consolidated() (cfg *Config, err error) { // Define defaults options cfg = &Config{ - Bind: "127.0.0.1:8080", + Bind: "127.0.0.1:8080", + TracksDir: "./tracks/", + GongsDir: "./gongs/", + ActionsDir: "./actions/", + RoutinesDir: "./routines/", } cfg.declareFlags() diff --git a/config/config.go b/config/config.go index 45119f5..a85fb0d 100644 --- a/config/config.go +++ b/config/config.go @@ -10,6 +10,10 @@ type Config struct { Bind string ExternalURL URL BaseURL string + TracksDir string + GongsDir string + ActionsDir string + RoutinesDir string } // parseLine treats a config line and place the read value in the variable