mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-04-29 19:10:51 -05:00
fix: ensure API consistency for /tasks and empty array responses (#1988)
- Renames the `/tasks/all` endpoint to `/tasks` for consistency with other collection endpoints like `/projects` and `/labels` - Returns `[]` instead of `null` for empty pagination results across all list endpoints - Updates the frontend service to use the new endpoint path - Updates API token tests to use the new endpoint path Fixes #1984
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
vconfig "code.vikunja.io/api/pkg/config"
|
||||
@@ -128,6 +129,13 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
||||
return HandleHTTPError(err)
|
||||
}
|
||||
|
||||
// Ensure we return an empty array instead of null when there are no results.
|
||||
// We need to use reflection here because a nil slice wrapped in an interface{}
|
||||
// is not equal to nil (the interface contains a nil value but is not nil itself).
|
||||
if result == nil || (reflect.ValueOf(result).Kind() == reflect.Slice && reflect.ValueOf(result).IsNil()) {
|
||||
result = []interface{}{}
|
||||
}
|
||||
|
||||
err = ctx.JSON(http.StatusOK, result)
|
||||
if err != nil {
|
||||
return HandleHTTPError(err)
|
||||
|
||||
Reference in New Issue
Block a user