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
33 lines
901 B
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/models"
|
|
"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")
|
|
}
|
|
scope.StatusLabels = models.StatusLabels
|
|
|
|
return scope, nil
|
|
}))
|
|
}
|