diff --git a/Featurecreep.md b/Featurecreep.md index 6845dd06b..f7eab36c3 100644 --- a/Featurecreep.md +++ b/Featurecreep.md @@ -158,8 +158,7 @@ Sorry for some of them being in German, I'll tranlate them at some point. * [x] Middleware to have configurable rate-limiting per user * [ ] Colors for lists and namespaces -> Up to the frontend to implement these * [ ] Reminders via mail -* [ ] Be able to "really" delete the account -> delete all lists and move ownership for others -* [ ] Deprecate /namespaces/{id}/lists in favour of namespace.ReadOne() <-- should also return the lists +* [ ] Be able to "really" delete the account -> delete all lists and move ownership for others * [ ] All `ReadAll` methods should return the number of items per page, the number of items on this page, the total pages and the items -> Check if there's a way to do that efficently. Maybe only implementing it in the web handler. * [ ] Move lists between namespaces -> Extra endpoint diff --git a/pkg/routes/api/v1/list_by_namespace.go b/pkg/routes/api/v1/list_by_namespace.go index 3981d8608..2b671ac6d 100644 --- a/pkg/routes/api/v1/list_by_namespace.go +++ b/pkg/routes/api/v1/list_by_namespace.go @@ -18,6 +18,7 @@ package v1 import ( "code.vikunja.io/api/pkg/models" + "code.vikunja.io/web/handler" "github.com/labstack/echo/v4" "net/http" "strconv" @@ -41,32 +42,23 @@ func GetListsByNamespaceID(c echo.Context) error { // Get our namespace namespace, err := getNamespace(c) if err != nil { - if models.IsErrNamespaceDoesNotExist(err) { - return c.JSON(http.StatusNotFound, models.Message{"Namespace not found."}) - } - if models.IsErrUserDoesNotHaveAccessToNamespace(err) { - return c.JSON(http.StatusForbidden, models.Message{"You don't have access to this namespace."}) - } - return c.JSON(http.StatusInternalServerError, models.Message{"An error occurred."}) + return handler.HandleHTTPError(err, c) } // Get the lists doer, err := models.GetCurrentUser(c) if err != nil { - return c.JSON(http.StatusInternalServerError, models.Message{"An error occurred."}) + return handler.HandleHTTPError(err, c) } lists, err := models.GetListsByNamespaceID(namespace.ID, doer) if err != nil { - if models.IsErrNamespaceDoesNotExist(err) { - return c.JSON(http.StatusNotFound, models.Message{"Namespace not found."}) - } - return c.JSON(http.StatusInternalServerError, models.Message{"An error occurred."}) + return handler.HandleHTTPError(err, c) } return c.JSON(http.StatusOK, lists) } -func getNamespace(c echo.Context) (namespace models.Namespace, err error) { +func getNamespace(c echo.Context) (namespace *models.Namespace, err error) { // Check if we have our ID id := c.Param("namespace") // Make int @@ -76,7 +68,7 @@ func getNamespace(c echo.Context) (namespace models.Namespace, err error) { } if namespaceID == -1 { - namespace = models.PseudoNamespace + namespace = &models.PseudoNamespace return } @@ -91,10 +83,7 @@ func getNamespace(c echo.Context) (namespace models.Namespace, err error) { return namespace, err } if !canRead { - return + return nil, echo.ErrForbidden } - - // Get the namespace - err = namespace.ReadOne() return }