This commit is contained in:
konrad 2018-07-12 23:36:55 +02:00 committed by kolaente
parent c5888093fe
commit 7f7b243cbe
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
6 changed files with 30 additions and 105 deletions

View File

@ -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
}

View File

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

View File

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

View File

@ -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(&currentUser)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Could not get lists."})
}*/
return c.JSON(http.StatusOK, nil)
}

View File

@ -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
}

View File

@ -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)*/
}