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.

31 lines
794 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/slerrors"
  6. "github.com/gin-gonic/gin"
  7. )
  8. func Scopes(g *gin.RouterGroup, db database.Database) {
  9. g.GET("/", handler("scopes", func(c *gin.Context) (interface{}, error) {
  10. return db.Scopes().ListByUser(c.Request.Context(), auth.UserID(c))
  11. }))
  12. g.GET("/:id", handler("scope", func(c *gin.Context) (interface{}, error) {
  13. id, err := reqInt(c, "id")
  14. if err != nil {
  15. return nil, err
  16. }
  17. scope, err := db.Scopes().Find(c.Request.Context(), id)
  18. if err != nil {
  19. return nil, err
  20. }
  21. if !scope.HasMember(auth.UserID(c)) {
  22. return nil, slerrors.NotFound("Scope")
  23. }
  24. return scope, nil
  25. }))
  26. }