Added method to show all namespaces a user has access to
This commit is contained in:
35
routes/api/v1/namespaces_list.go
Normal file
35
routes/api/v1/namespaces_list.go
Normal file
@ -0,0 +1,35 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"git.kolaente.de/konrad/list/models"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetAllNamespacesByCurrentUser(c echo.Context) error {
|
||||
// swagger:operation GET /namespaces namespaces getNamespaces
|
||||
// ---
|
||||
// summary: Get all namespaces the currently logged in user has at least read access
|
||||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
// - application/json
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/Namespace"
|
||||
// "500":
|
||||
// "$ref": "#/responses/Message"
|
||||
|
||||
|
||||
user, err := models.GetCurrentUser(c)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get the current user."})
|
||||
}
|
||||
|
||||
namespaces, err := models.GetAllNamespacesByUserID(user.ID)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get namespaces."})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, namespaces)
|
||||
}
|
@ -93,7 +93,7 @@ func RegisterRoutes(e *echo.Echo) {
|
||||
a.DELETE("/item/:id", apiv1.DeleteListItemByIDtemByID)
|
||||
a.POST("/item/:id", apiv1.UpdateListItem)
|
||||
|
||||
a.GET("/namespaces")
|
||||
a.GET("/namespaces", apiv1.GetAllNamespacesByCurrentUser)
|
||||
a.PUT("/namespaces", apiv1.AddNamespace)
|
||||
a.GET("/namespaces/:id")
|
||||
a.POST("/namespaces/:id", apiv1.UpdateNamespace)
|
||||
|
Reference in New Issue
Block a user