diff --git a/routes/api/v1/list_by_namespace.go b/routes/api/v1/list_by_namespace.go index c8a1985bc97..bcb467ea7ed 100644 --- a/routes/api/v1/list_by_namespace.go +++ b/routes/api/v1/list_by_namespace.go @@ -4,6 +4,7 @@ import ( "git.kolaente.de/konrad/list/models" "github.com/labstack/echo" "net/http" + "strconv" ) // GetListsByNamespaceID is the web handler to delete a namespace @@ -51,3 +52,31 @@ func GetListsByNamespaceID(c echo.Context) error { } return c.JSON(http.StatusOK, lists) } + + +func getNamespace(c echo.Context) (namespace models.Namespace, err error) { + // Check if we have our ID + id := c.Param("id") + // Make int + namespaceID, err := strconv.ParseInt(id, 10, 64) + if err != nil { + return + } + + // Get the namespace + namespace, err = models.GetNamespaceByID(namespaceID) + if err != nil { + return + } + + // Check if the user has acces to that namespace + user, err := models.GetCurrentUser(c) + if err != nil { + return + } + if !namespace.CanRead(&user) { + return + } + + return +} diff --git a/routes/api/v1/list_delete.go b/routes/api/v1/list_delete.go index ade093cdfe0..432eb0868cf 100644 --- a/routes/api/v1/list_delete.go +++ b/routes/api/v1/list_delete.go @@ -35,36 +35,5 @@ func DeleteListByID(c echo.Context) error { // "500": // "$ref": "#/responses/Message" - /* - // Check if we have our ID - id := c.Param("id") - // Make int - itemID, err := strconv.ParseInt(id, 10, 64) - if err != nil { - return c.JSON(http.StatusBadRequest, models.Message{"Invalid ID."}) - } - - // Check if the user has the right to delete that list - user, err := models.GetCurrentUser(c) - if err != nil { - return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."}) - } - - // err = models.DeleteListByID(itemID, &user) - if err != nil { - if models.IsErrNeedToBeListAdmin(err) { - return c.JSON(http.StatusForbidden, models.Message{"You need to be the list owner to delete a list."}) - } - - if models.IsErrListDoesNotExist(err) { - return c.JSON(http.StatusNotFound, models.Message{"This list does not exist."}) - } - - return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."}) - } - - return c.JSON(http.StatusOK, models.Message{"The list was deleted with success."}) - */ - return echo.NewHTTPError(http.StatusNotImplemented) } diff --git a/routes/api/v1/list_show.go b/routes/api/v1/list_show.go index a07759b9c7d..8b982c23a78 100644 --- a/routes/api/v1/list_show.go +++ b/routes/api/v1/list_show.go @@ -1,10 +1,8 @@ package v1 import ( - "git.kolaente.de/konrad/list/models" "github.com/labstack/echo" "net/http" - "strconv" ) // GetListByID Adds or updates a new list @@ -30,24 +28,5 @@ func GetListByID(c echo.Context) error { // "500": // "$ref": "#/responses/Message" - // Check if we have our ID - id := c.Param("id") - // Make int - listID, err := strconv.ParseInt(id, 10, 64) - - if err != nil { - return c.JSON(http.StatusBadRequest, models.Message{"Invalid ID."}) - } - - // Get the list - list, err := models.GetListByID(listID) - if err != nil { - if models.IsErrListDoesNotExist(err) { - return c.JSON(http.StatusBadRequest, models.Message{"The list does not exist."}) - } - - return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."}) - } - - return c.JSON(http.StatusOK, list) + return echo.NewHTTPError(http.StatusNotImplemented) } diff --git a/routes/api/v1/lists_list.go b/routes/api/v1/lists_list.go index dfdb139c9ad..cfa624445f7 100644 --- a/routes/api/v1/lists_list.go +++ b/routes/api/v1/lists_list.go @@ -20,15 +20,5 @@ func GetListsByUser(c echo.Context) error { // "500": // "$ref": "#/responses/Message" - /*currentUser, err := models.GetCurrentUser(c) - if err != nil { - return c.JSON(http.StatusInternalServerError, models.Message{"Could not determine the current user."}) - } - - allLists, err := models.GetListsByUser(¤tUser) - if err != nil { - return c.JSON(http.StatusInternalServerError, models.Message{"Could not get lists."}) - }*/ - return c.JSON(http.StatusOK, nil) } diff --git a/routes/api/v1/namespace_show.go b/routes/api/v1/namespace_show.go index e96bd77bd24..eb442a8c4a6 100644 --- a/routes/api/v1/namespace_show.go +++ b/routes/api/v1/namespace_show.go @@ -1,10 +1,8 @@ package v1 import ( - "git.kolaente.de/konrad/list/models" "github.com/labstack/echo" "net/http" - "strconv" ) // ShowNamespace ... @@ -32,30 +30,3 @@ func ShowNamespace(c echo.Context) error { return echo.NewHTTPError(http.StatusNotImplemented) } - -func getNamespace(c echo.Context) (namespace models.Namespace, err error) { - // Check if we have our ID - id := c.Param("id") - // Make int - namespaceID, err := strconv.ParseInt(id, 10, 64) - if err != nil { - return - } - - // Get the namespace - namespace, err = models.GetNamespaceByID(namespaceID) - if err != nil { - return - } - - // Check if the user has acces to that namespace - user, err := models.GetCurrentUser(c) - if err != nil { - return - } - if !namespace.CanRead(&user) { - return - } - - return -} diff --git a/routes/api/v1/namespaces_list.go b/routes/api/v1/namespaces_list.go index c13c7bc305e..952287d8f19 100644 --- a/routes/api/v1/namespaces_list.go +++ b/routes/api/v1/namespaces_list.go @@ -21,17 +21,4 @@ func GetAllNamespacesByCurrentUser(c echo.Context) error { // "$ref": "#/responses/Message" return echo.NewHTTPError(http.StatusNotImplemented) - /* - - 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)*/ }