mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-07-13 17:12:05 -04:00
* refactor APIs in JMAP and Groupware in order to implement pagination across multiple accountIds and multiple suppliers (currently implemented using a mock supplier for contacts) * requires go 1.26 due to use of self-reflecting generics type constraints * still missing: query criteria and sorting parameters * still missing: multi-accountId support for emails * errors are now all just 'error' in the APIs, instead of the specialized implementations, and are interpreted dynamically where necessary in order to transform them into HTTP responses * remove position, anchor, anchorOffset as individual query parameters as we now only support a 'next=...' token for subsequent pages (except in emails for now), and use jmap.QueryParams instead; those tokens have a header character for the format, followed by a JSON encoded QueryParams map, all wrapped into base62 to make it clearer that it is meant to be an opaque token, and not a parameter clients should tinker with or construct themselves * introduce QueryParamsSupplier as an interface to provide QueryParams for various scenarios (single supplier, multiple supplier, ...) per accountId * implement multi-supplier template methods slist and squery
65 lines
3.0 KiB
Go
65 lines
3.0 KiB
Go
package jmap
|
|
|
|
var NS_PRINCIPALS = ns(JmapPrincipals)
|
|
|
|
func (j *Client) GetPrincipals(accountId string, ids []string, ctx Context) (Result[PrincipalGetResponse], error) {
|
|
return get(j, "GetPrincipals", PrincipalType,
|
|
func(accountId string, ids []string) PrincipalGetCommand {
|
|
return PrincipalGetCommand{AccountId: accountId, Ids: ids}
|
|
},
|
|
PrincipalGetResponse{},
|
|
identity1,
|
|
accountId, ids,
|
|
ctx,
|
|
)
|
|
}
|
|
|
|
type PrincipalSearchResults SearchResultsTemplate[Principal]
|
|
|
|
var _ SearchResults[Principal] = &PrincipalSearchResults{}
|
|
|
|
func (r *PrincipalSearchResults) GetResults() []Principal { return r.Results }
|
|
func (r *PrincipalSearchResults) GetCanCalculateChanges() ChangeCalculation {
|
|
return r.CanCalculateChanges
|
|
}
|
|
func (r *PrincipalSearchResults) GetPosition() *uint { return r.Position }
|
|
func (r *PrincipalSearchResults) GetLimit() *uint { return r.Limit }
|
|
func (r *PrincipalSearchResults) GetTotal() *uint { return r.Total }
|
|
func (r *PrincipalSearchResults) RemoveResults() { r.Results = nil }
|
|
func (r *PrincipalSearchResults) SetLimit(limit *uint) { r.Limit = limit }
|
|
func (r *PrincipalSearchResults) SetPosition(position *uint) { r.Position = position }
|
|
|
|
func (j *Client) QueryPrincipals(accountIds map[string]QueryParams, limit *uint, //NOSONAR
|
|
filter PrincipalFilterElement, sortBy []PrincipalComparator, calculateTotal bool,
|
|
ctx Context) (Result[map[string]*PrincipalSearchResults], error) {
|
|
return queryN(j, "QueryPrincipals", PrincipalType,
|
|
[]PrincipalComparator{{Property: PrincipalPropertyName, IsAscending: true}},
|
|
func(accountId string, p QueryParams, limit *uint, filter PrincipalFilterElement, sortBy []PrincipalComparator) PrincipalQueryCommand {
|
|
return PrincipalQueryCommand{AccountId: accountId, Filter: filter, Sort: sortBy, Position: p.Position, Anchor: p.Anchor, AnchorOffset: p.AnchorOffset, Limit: limit, CalculateTotal: calculateTotal}
|
|
},
|
|
func(accountId string, cmd Command, path, rof string) PrincipalGetRefCommand {
|
|
return PrincipalGetRefCommand{AccountId: accountId, IdsRef: &ResultReference{Name: cmd, Path: path, ResultOf: rof}}
|
|
},
|
|
func(query PrincipalQueryResponse, queryParams QueryParams, limit *uint) *PrincipalSearchResults {
|
|
return &PrincipalSearchResults{
|
|
Results: []Principal{},
|
|
CanCalculateChanges: ChangeCalculation(query.CanCalculateChanges),
|
|
Position: valueIf(query.Position, queryParams.Anchor == ""),
|
|
Total: ptrIf(query.Total, calculateTotal),
|
|
Limit: valueIf(query.Limit, limit != nil),
|
|
}
|
|
},
|
|
func(query PrincipalQueryResponse, get PrincipalGetResponse, queryParams QueryParams, limit *uint) *PrincipalSearchResults {
|
|
return &PrincipalSearchResults{
|
|
Results: get.List,
|
|
CanCalculateChanges: ChangeCalculation(query.CanCalculateChanges),
|
|
Position: valueIf(query.Position, queryParams.Anchor == ""),
|
|
Total: ptrIf(query.Total, calculateTotal),
|
|
Limit: valueIf(query.Limit, limit != nil),
|
|
}
|
|
},
|
|
accountIds, limit, filter, sortBy,
|
|
ctx,
|
|
)
|
|
}
|