Added method to show one namespace

This commit is contained in:
kolaente 2018-07-02 09:09:32 +02:00
parent 124e4f4a5b
commit 06cae09f77
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
6 changed files with 199 additions and 13 deletions

View file

@ -36,11 +36,8 @@ func GetAllNamespacesByUserID(userID int64) (namespaces []*Namespace, err error)
// Get all namespaces of teams that user is part of // Get all namespaces of teams that user is part of
/*err = x.Table("namespaces"). /*err = x.Table("namespaces").
Join("INNER", ). Join("INNER", ).
Find(namespaces)*/ Find(namespaces)*/
return return
} }

View file

@ -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": { "/register": {
"post": { "post": {
"consumes": [ "consumes": [

View file

@ -7,7 +7,7 @@ import (
"strconv" "strconv"
) )
// AddOrUpdateList Adds or updates a new list // GetListByID Adds or updates a new list
func GetListByID(c echo.Context) error { func GetListByID(c echo.Context) error {
// swagger:operation GET /lists/{listID} lists getList // swagger:operation GET /lists/{listID} lists getList
// --- // ---

View 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)
}

View file

@ -1,8 +1,8 @@
package v1 package v1
import ( import (
"github.com/labstack/echo"
"git.kolaente.de/konrad/list/models" "git.kolaente.de/konrad/list/models"
"github.com/labstack/echo"
"net/http" "net/http"
) )
@ -20,7 +20,6 @@ func GetAllNamespacesByCurrentUser(c echo.Context) error {
// "500": // "500":
// "$ref": "#/responses/Message" // "$ref": "#/responses/Message"
user, err := models.GetCurrentUser(c) user, err := models.GetCurrentUser(c)
if err != nil { if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get the current user."}) 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) return c.JSON(http.StatusOK, namespaces)
} }

View file

@ -95,8 +95,9 @@ func RegisterRoutes(e *echo.Echo) {
a.GET("/namespaces", apiv1.GetAllNamespacesByCurrentUser) a.GET("/namespaces", apiv1.GetAllNamespacesByCurrentUser)
a.PUT("/namespaces", apiv1.AddNamespace) 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.POST("/namespaces/:id", apiv1.UpdateNamespace)
a.PUT("/namespaces/:id") //a.PUT("/namespaces/:id") // Creates a new list in that namespace
a.DELETE("/namespaces/:id") // a.DELETE("/namespaces/:id") // Deletes a namespace with all lists
} }