@@ -18,14 +18,17 @@ import (
1818)
1919
2020type CreatePoolRequest struct {
21- Name string `json:"name" validate:"required"`
22- AccountIDs []string `json:"accountIDs" validate:"min=1,dive,accountID"`
21+ Name string `json:"name" validate:"required"`
22+ Query map [string ]any `json:"query" validate:"required_without=AccountIDs"`
23+ AccountIDs []string `json:"accountIDs" validate:"required_without=Query,dive,accountID"`
2324}
2425
2526type PoolResponse struct {
26- ID string `json:"id"`
27- Name string `json:"name"`
28- Accounts []string `json:"accounts"`
27+ ID string `json:"id"`
28+ Name string `json:"name"`
29+ Type models.PoolType `json:"type"`
30+ Query map [string ]any `json:"query"`
31+ Accounts []string `json:"accounts"`
2932}
3033
3134func poolsCreate (backend backend.Backend , validator * validation.Validator ) http.HandlerFunc {
@@ -55,18 +58,24 @@ func poolsCreate(backend backend.Backend, validator *validation.Validator) http.
5558 CreatedAt : time .Now ().UTC (),
5659 }
5760
58- accounts := make ([]models.AccountID , len (CreatePoolRequest .AccountIDs ))
59- for i , accountID := range CreatePoolRequest .AccountIDs {
60- aID , err := models .AccountIDFromString (accountID )
61- if err != nil {
62- otel .RecordError (span , err )
63- api .BadRequest (w , ErrValidation , err )
64- return
65- }
61+ if len (CreatePoolRequest .Query ) > 0 {
62+ pool .Type = models .POOL_TYPE_DYNAMIC
63+ pool .Query = CreatePoolRequest .Query
64+ } else {
65+ pool .Type = models .POOL_TYPE_STATIC
66+ accounts := make ([]models.AccountID , len (CreatePoolRequest .AccountIDs ))
67+ for i , accountID := range CreatePoolRequest .AccountIDs {
68+ aID , err := models .AccountIDFromString (accountID )
69+ if err != nil {
70+ otel .RecordError (span , err )
71+ api .BadRequest (w , ErrValidation , err )
72+ return
73+ }
6674
67- accounts [i ] = aID
75+ accounts [i ] = aID
76+ }
77+ pool .PoolAccounts = accounts
6878 }
69- pool .PoolAccounts = accounts
7079
7180 err = backend .PoolsCreate (ctx , pool )
7281 if err != nil {
@@ -78,6 +87,8 @@ func poolsCreate(backend backend.Backend, validator *validation.Validator) http.
7887 data := & PoolResponse {
7988 ID : pool .ID .String (),
8089 Name : pool .Name ,
90+ Type : pool .Type ,
91+ Query : pool .Query ,
8192 Accounts : CreatePoolRequest .AccountIDs ,
8293 }
8394
0 commit comments