You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
784 B

  1. package api
  2. import (
  3. "git.aiterp.net/lucifer/new-server/app/config"
  4. "git.aiterp.net/lucifer/new-server/models"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func Scenes(r gin.IRoutes) {
  8. r.GET("", handler(func(c *gin.Context) (interface{}, error) {
  9. return config.SceneRepository().FetchAll(ctxOf(c))
  10. }))
  11. r.GET("/:id", handler(func(c *gin.Context) (interface{}, error) {
  12. return config.SceneRepository().Find(ctxOf(c), intParam(c, "id"))
  13. }))
  14. r.POST("", handler(func(c *gin.Context) (interface{}, error) {
  15. var body models.Scene
  16. err := parseBody(c, &body)
  17. if err != nil {
  18. return nil, err
  19. }
  20. err = body.Validate()
  21. if err != nil {
  22. return nil, err
  23. }
  24. err = config.SceneRepository().Save(ctxOf(c), &body)
  25. if err != nil {
  26. return nil, err
  27. }
  28. return body, nil
  29. }))
  30. }