mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/formancehq/reconciliation/internal/storage"
|
|
"github.com/formancehq/stack/libs/go-libs/pointer"
|
|
"github.com/formancehq/stack/libs/go-libs/query"
|
|
)
|
|
|
|
func getQueryBuilder(r *http.Request) (query.Builder, error) {
|
|
data, err := io.ReadAll(r.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(data) > 0 {
|
|
return query.ParseJSON(string(data))
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func getPaginatedQueryOptionsReconciliations(r *http.Request) (*storage.PaginatedQueryOptions[storage.ReconciliationsFilters], error) {
|
|
qb, err := getQueryBuilder(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pageSize, err := getPageSize(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
filters := storage.ReconciliationsFilters{}
|
|
return pointer.For(storage.NewPaginatedQueryOptions(filters).
|
|
WithQueryBuilder(qb).
|
|
WithPageSize(pageSize)), nil
|
|
}
|
|
|
|
func getPaginatedQueryOptionsPolicies(r *http.Request) (*storage.PaginatedQueryOptions[storage.PoliciesFilters], error) {
|
|
qb, err := getQueryBuilder(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pageSize, err := getPageSize(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
filters := storage.PoliciesFilters{}
|
|
return pointer.For(storage.NewPaginatedQueryOptions(filters).
|
|
WithQueryBuilder(qb).
|
|
WithPageSize(pageSize)), nil
|
|
}
|