Loggest thy stuff
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.

33 lines
901 B

  1. package api
  2. import (
  3. "git.aiterp.net/stufflog3/stufflog3-api/internal/auth"
  4. "git.aiterp.net/stufflog3/stufflog3-api/internal/database"
  5. "git.aiterp.net/stufflog3/stufflog3-api/internal/models"
  6. "git.aiterp.net/stufflog3/stufflog3-api/internal/slerrors"
  7. "github.com/gin-gonic/gin"
  8. )
  9. func Scopes(g *gin.RouterGroup, db database.Database) {
  10. g.GET("/", handler("scopes", func(c *gin.Context) (interface{}, error) {
  11. return db.Scopes().ListByUser(c.Request.Context(), auth.UserID(c))
  12. }))
  13. g.GET("/:id", handler("scope", func(c *gin.Context) (interface{}, error) {
  14. id, err := reqInt(c, "id")
  15. if err != nil {
  16. return nil, err
  17. }
  18. scope, err := db.Scopes().Find(c.Request.Context(), id, true)
  19. if err != nil {
  20. return nil, err
  21. }
  22. if !scope.HasMember(auth.UserID(c)) {
  23. return nil, slerrors.NotFound("Scope")
  24. }
  25. scope.StatusLabels = models.StatusLabels
  26. return scope, nil
  27. }))
  28. }