groupware: change /accounts endpoint to return an array with the accountId instead of a map

This commit is contained in:
Pascal Bleser
2025-10-24 17:11:54 +02:00
parent f2e515638c
commit 3cddb65e24

View File

@@ -2,6 +2,8 @@ package groupware
import (
"net/http"
"slices"
"strings"
"github.com/opencloud-eu/opencloud/pkg/jmap"
)
@@ -52,10 +54,26 @@ type SwaggerGetAccountsResponse struct {
// 500: ErrorResponse500
func (g *Groupware) GetAccounts(w http.ResponseWriter, r *http.Request) {
g.respond(w, r, func(req Request) Response {
return response(req.session.Accounts, req.session.State, "")
list := make([]AccountWithId, len(req.session.Accounts))
i := 0
for accountId, account := range req.session.Accounts {
list[i] = AccountWithId{
AccountId: accountId,
Account: account,
}
i++
}
// sort on accountId to have a stable order that remains the same with every query
slices.SortFunc(list, func(a, b AccountWithId) int { return strings.Compare(a.AccountId, b.AccountId) })
return response(list, req.session.State, "")
})
}
type AccountWithId struct {
AccountId string `json:"accountId,omitempty"`
jmap.Account
}
type AccountBootstrapResponse struct {
// The API version.
Version string `json:"version"`