This commit is contained in:
nemunaire 2022-10-02 23:24:53 +02:00
parent d481718fbc
commit 4bdab894ca
11 changed files with 331 additions and 12 deletions

37
api/actions.go Normal file
View File

@ -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()
}

86
api/alarms.go Normal file
View File

@ -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()
}

37
api/gongs.go Normal file
View File

@ -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()
}

13
api/history.go Normal file
View File

@ -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) {
})
}

47
api/quotes.go Normal file
View File

@ -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"`
}

View File

@ -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)
}

37
api/routines.go Normal file
View File

@ -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()
}

16
api/settings.go Normal file
View File

@ -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) {
})
}

37
api/tracks.go Normal file
View File

@ -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()
}

View File

@ -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()

View File

@ -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