|
|
@ -5,15 +5,27 @@ import ( |
|
|
|
"git.aiterp.net/lucifer/new-server/app/services/publisher" |
|
|
|
"git.aiterp.net/lucifer/new-server/models" |
|
|
|
"github.com/gin-gonic/gin" |
|
|
|
"regexp" |
|
|
|
) |
|
|
|
|
|
|
|
func Scenes(r gin.IRoutes) { |
|
|
|
nonNumericRegex := regexp.MustCompile("[a-zA-Z ]") |
|
|
|
|
|
|
|
findScene := func(c *gin.Context) (*models.Scene, error) { |
|
|
|
param := c.Param("id") |
|
|
|
if nonNumericRegex.MatchString(param) { |
|
|
|
return config.SceneRepository().FindName(ctxOf(c), param) |
|
|
|
} else { |
|
|
|
return config.SceneRepository().Find(ctxOf(c), intParam(c, "id")) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
r.GET("", handler(func(c *gin.Context) (interface{}, error) { |
|
|
|
return config.SceneRepository().FetchAll(ctxOf(c)) |
|
|
|
})) |
|
|
|
|
|
|
|
r.GET("/:id", handler(func(c *gin.Context) (interface{}, error) { |
|
|
|
return config.SceneRepository().Find(ctxOf(c), intParam(c, "id")) |
|
|
|
return findScene(c) |
|
|
|
})) |
|
|
|
|
|
|
|
r.POST("", handler(func(c *gin.Context) (interface{}, error) { |
|
|
@ -45,7 +57,7 @@ func Scenes(r gin.IRoutes) { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
scene, err := config.SceneRepository().Find(ctxOf(c), intParam(c, "id")) |
|
|
|
scene, err := findScene(c) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|