Files
stufflog3/api/scope.go
T

32 lines
800 B
Go

package api
import (
"git.aiterp.net/stufflog3/stufflog3-api/internal/auth"
"git.aiterp.net/stufflog3/stufflog3-api/internal/database"
"git.aiterp.net/stufflog3/stufflog3-api/internal/slerrors"
"github.com/gin-gonic/gin"
)
func Scopes(g *gin.RouterGroup, db database.Database) {
g.GET("/", handler("scopes", func(c *gin.Context) (interface{}, error) {
return db.Scopes().ListByUser(c.Request.Context(), auth.UserID(c))
}))
g.GET("/:id", handler("scope", func(c *gin.Context) (interface{}, error) {
id, err := reqInt(c, "id")
if err != nil {
return nil, err
}
scope, err := db.Scopes().Find(c.Request.Context(), id, true)
if err != nil {
return nil, err
}
if !scope.HasMember(auth.UserID(c)) {
return nil, slerrors.NotFound("Scope")
}
return scope, nil
}))
}