admin: Transmit sync errors to interface
This commit is contained in:
parent
20f5656a74
commit
1f3f0fd55b
1 changed files with 12 additions and 5 deletions
|
|
@ -15,6 +15,13 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func flatifySyncErrors(errs []error) (ret []string) {
|
||||||
|
for _, err := range errs {
|
||||||
|
ret = append(ret, err.Error())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func declareSyncRoutes(router *gin.RouterGroup) {
|
func declareSyncRoutes(router *gin.RouterGroup) {
|
||||||
apiSyncRoutes := router.Group("/sync")
|
apiSyncRoutes := router.Group("/sync")
|
||||||
|
|
||||||
|
|
@ -71,7 +78,7 @@ func declareSyncRoutes(router *gin.RouterGroup) {
|
||||||
|
|
||||||
apiSyncRoutes.POST("/themes", func(c *gin.Context) {
|
apiSyncRoutes.POST("/themes", func(c *gin.Context) {
|
||||||
_, errs := sync.SyncThemes(sync.GlobalImporter)
|
_, errs := sync.SyncThemes(sync.GlobalImporter)
|
||||||
c.JSON(http.StatusOK, errs)
|
c.JSON(http.StatusOK, flatifySyncErrors(errs))
|
||||||
})
|
})
|
||||||
|
|
||||||
apiSyncThemesRoutes := apiSyncRoutes.Group("/themes/:thid")
|
apiSyncThemesRoutes := apiSyncRoutes.Group("/themes/:thid")
|
||||||
|
|
@ -135,7 +142,7 @@ func declareSyncExercicesRoutes(router *gin.RouterGroup) {
|
||||||
theme := c.MustGet("theme").(*fic.Theme)
|
theme := c.MustGet("theme").(*fic.Theme)
|
||||||
exceptions := sync.LoadException(sync.GlobalImporter, theme)
|
exceptions := sync.LoadException(sync.GlobalImporter, theme)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, sync.SyncExercices(sync.GlobalImporter, theme, exceptions))
|
c.JSON(http.StatusOK, flatifySyncErrors(sync.SyncExercices(sync.GlobalImporter, theme, exceptions)))
|
||||||
})
|
})
|
||||||
apiSyncExercicesRoutes := router.Group("/exercices/:eid")
|
apiSyncExercicesRoutes := router.Group("/exercices/:eid")
|
||||||
apiSyncExercicesRoutes.Use(ExerciceHandler)
|
apiSyncExercicesRoutes.Use(ExerciceHandler)
|
||||||
|
|
@ -147,7 +154,7 @@ func declareSyncExercicesRoutes(router *gin.RouterGroup) {
|
||||||
exercice := c.MustGet("exercice").(*fic.Exercice)
|
exercice := c.MustGet("exercice").(*fic.Exercice)
|
||||||
|
|
||||||
_, _, errs := sync.SyncExercice(sync.GlobalImporter, theme, exercice.Path, nil, exceptions)
|
_, _, errs := sync.SyncExercice(sync.GlobalImporter, theme, exercice.Path, nil, exceptions)
|
||||||
c.JSON(http.StatusOK, errs)
|
c.JSON(http.StatusOK, flatifySyncErrors(errs))
|
||||||
})
|
})
|
||||||
apiSyncExercicesRoutes.POST("/files", func(c *gin.Context) {
|
apiSyncExercicesRoutes.POST("/files", func(c *gin.Context) {
|
||||||
exercice := c.MustGet("exercice").(*fic.Exercice)
|
exercice := c.MustGet("exercice").(*fic.Exercice)
|
||||||
|
|
@ -179,7 +186,7 @@ func declareSyncExercicesRoutes(router *gin.RouterGroup) {
|
||||||
exceptions := sync.LoadException(sync.GlobalImporter, theme)
|
exceptions := sync.LoadException(sync.GlobalImporter, theme)
|
||||||
|
|
||||||
_, errs := sync.SyncExerciceHints(sync.GlobalImporter, exercice, sync.ExerciceFlagsMap(sync.GlobalImporter, exercice), exceptions)
|
_, errs := sync.SyncExerciceHints(sync.GlobalImporter, exercice, sync.ExerciceFlagsMap(sync.GlobalImporter, exercice), exceptions)
|
||||||
c.JSON(http.StatusOK, errs)
|
c.JSON(http.StatusOK, flatifySyncErrors(errs))
|
||||||
})
|
})
|
||||||
apiSyncExercicesRoutes.POST("/flags", func(c *gin.Context) {
|
apiSyncExercicesRoutes.POST("/flags", func(c *gin.Context) {
|
||||||
exercice := c.MustGet("exercice").(*fic.Exercice)
|
exercice := c.MustGet("exercice").(*fic.Exercice)
|
||||||
|
|
@ -188,7 +195,7 @@ func declareSyncExercicesRoutes(router *gin.RouterGroup) {
|
||||||
exceptions := sync.LoadException(sync.GlobalImporter, theme)
|
exceptions := sync.LoadException(sync.GlobalImporter, theme)
|
||||||
_, errs := sync.SyncExerciceFlags(sync.GlobalImporter, exercice, exceptions)
|
_, errs := sync.SyncExerciceFlags(sync.GlobalImporter, exercice, exceptions)
|
||||||
_, herrs := sync.SyncExerciceHints(sync.GlobalImporter, exercice, sync.ExerciceFlagsMap(sync.GlobalImporter, exercice), exceptions)
|
_, herrs := sync.SyncExerciceHints(sync.GlobalImporter, exercice, sync.ExerciceFlagsMap(sync.GlobalImporter, exercice), exceptions)
|
||||||
c.JSON(http.StatusOK, append(errs, herrs...))
|
c.JSON(http.StatusOK, flatifySyncErrors(append(errs, herrs...)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue