Added method to show one namespace
This commit is contained in:
parent
124e4f4a5b
commit
06cae09f77
6 changed files with 199 additions and 13 deletions
|
@ -36,11 +36,8 @@ func GetAllNamespacesByUserID(userID int64) (namespaces []*Namespace, err error)
|
|||
|
||||
// Get all namespaces of teams that user is part of
|
||||
/*err = x.Table("namespaces").
|
||||
Join("INNER", ).
|
||||
Find(namespaces)*/
|
||||
|
||||
|
||||
|
||||
Join("INNER", ).
|
||||
Find(namespaces)*/
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -352,6 +352,143 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/namespaces": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"namespaces"
|
||||
],
|
||||
"summary": "Get all namespaces the currently logged in user has at least read access",
|
||||
"operationId": "getNamespaces",
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/Namespace"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/Message"
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"namespaces"
|
||||
],
|
||||
"summary": "Creates a new namespace owned by the currently logged in user",
|
||||
"operationId": "addNamespace",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Namespace"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/Namespace"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"403": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/Message"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/namespaces/{namespaceID}": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"namespaces"
|
||||
],
|
||||
"summary": "gets one namespace with all todo items",
|
||||
"operationId": "getNamespace",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "ID of the namespace to show",
|
||||
"name": "namespaceID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/Namespace"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/Message"
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"namespaces"
|
||||
],
|
||||
"summary": "Updates a namespace",
|
||||
"operationId": "upadteNamespace",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "ID of the namespace to update",
|
||||
"name": "namespaceID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Namespace"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"$ref": "#/responses/Namespace"
|
||||
},
|
||||
"400": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"403": {
|
||||
"$ref": "#/responses/Message"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/Message"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/register": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
// AddOrUpdateList Adds or updates a new list
|
||||
// GetListByID Adds or updates a new list
|
||||
func GetListByID(c echo.Context) error {
|
||||
// swagger:operation GET /lists/{listID} lists getList
|
||||
// ---
|
||||
|
|
52
routes/api/v1/namespace_show.go
Normal file
52
routes/api/v1/namespace_show.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"git.kolaente.de/konrad/list/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func ShowNamespace(c echo.Context) error {
|
||||
// swagger:operation GET /namespaces/{namespaceID} namespaces getNamespace
|
||||
// ---
|
||||
// summary: gets one namespace with all todo items
|
||||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: namespaceID
|
||||
// in: path
|
||||
// description: ID of the namespace to show
|
||||
// type: string
|
||||
// required: true
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/Namespace"
|
||||
// "400":
|
||||
// "$ref": "#/responses/Message"
|
||||
// "500":
|
||||
// "$ref": "#/responses/Message"
|
||||
|
||||
// Check if we have our ID
|
||||
id := c.Param("id")
|
||||
// Make int
|
||||
namespaceID, err := strconv.ParseInt(id, 10, 64)
|
||||
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusBadRequest, models.Message{"Invalid ID."})
|
||||
}
|
||||
|
||||
// Get the namespace
|
||||
namespace, err := models.GetNamespaceByID(namespaceID)
|
||||
if err != nil {
|
||||
if models.IsErrNamespaceDoesNotExist(err) {
|
||||
return c.JSON(http.StatusBadRequest, models.Message{"The namespace does not exist."})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, namespace)
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"git.kolaente.de/konrad/list/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -20,7 +20,6 @@ func GetAllNamespacesByCurrentUser(c echo.Context) error {
|
|||
// "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."})
|
||||
|
@ -32,4 +31,4 @@ func GetAllNamespacesByCurrentUser(c echo.Context) error {
|
|||
}
|
||||
|
||||
return c.JSON(http.StatusOK, namespaces)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,8 +95,9 @@ func RegisterRoutes(e *echo.Echo) {
|
|||
|
||||
a.GET("/namespaces", apiv1.GetAllNamespacesByCurrentUser)
|
||||
a.PUT("/namespaces", apiv1.AddNamespace)
|
||||
a.GET("/namespaces/:id")
|
||||
a.GET("/namespaces/:id", apiv1.ShowNamespace)
|
||||
//a.GET("/namespaces/:id/lists") // Gets all lists for that namespace
|
||||
a.POST("/namespaces/:id", apiv1.UpdateNamespace)
|
||||
a.PUT("/namespaces/:id")
|
||||
a.DELETE("/namespaces/:id")
|
||||
//a.PUT("/namespaces/:id") // Creates a new list in that namespace
|
||||
// a.DELETE("/namespaces/:id") // Deletes a namespace with all lists
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue