2018-07-02 09:09:32 +02:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.kolaente.de/konrad/list/models"
|
|
|
|
"github.com/labstack/echo"
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2018-07-10 14:02:23 +02:00
|
|
|
// ShowNamespace ...
|
2018-07-02 09:09:32 +02:00
|
|
|
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"
|
|
|
|
|
2018-07-12 13:43:42 +02:00
|
|
|
return echo.NewHTTPError(http.StatusNotImplemented)
|
2018-07-04 08:56:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func getNamespace(c echo.Context) (namespace models.Namespace, err error) {
|
2018-07-02 09:09:32 +02:00
|
|
|
// Check if we have our ID
|
|
|
|
id := c.Param("id")
|
|
|
|
// Make int
|
|
|
|
namespaceID, err := strconv.ParseInt(id, 10, 64)
|
|
|
|
if err != nil {
|
2018-07-04 08:56:52 +02:00
|
|
|
return
|
2018-07-02 09:09:32 +02:00
|
|
|
}
|
|
|
|
|
2018-07-03 09:09:44 +02:00
|
|
|
// Get the namespace
|
2018-07-04 08:56:52 +02:00
|
|
|
namespace, err = models.GetNamespaceByID(namespaceID)
|
2018-07-03 09:09:44 +02:00
|
|
|
if err != nil {
|
2018-07-04 08:56:52 +02:00
|
|
|
return
|
2018-07-03 09:09:44 +02:00
|
|
|
}
|
|
|
|
|
2018-07-03 08:26:28 +02:00
|
|
|
// Check if the user has acces to that namespace
|
|
|
|
user, err := models.GetCurrentUser(c)
|
|
|
|
if err != nil {
|
2018-07-04 08:56:52 +02:00
|
|
|
return
|
2018-07-03 08:26:28 +02:00
|
|
|
}
|
2018-07-12 13:43:42 +02:00
|
|
|
if !namespace.CanRead(&user) {
|
2018-07-04 08:56:52 +02:00
|
|
|
return
|
2018-07-03 08:26:28 +02:00
|
|
|
}
|
|
|
|
|
2018-07-04 08:56:52 +02:00
|
|
|
return
|
2018-07-04 19:21:04 +02:00
|
|
|
}
|