Skip to content

Commit

Permalink
Pass canceledBy in array
Browse files Browse the repository at this point in the history
  • Loading branch information
alallema committed Dec 6, 2022
1 parent 225330c commit 029e503
Show file tree
Hide file tree
Showing 4 changed files with 519 additions and 612 deletions.
69 changes: 51 additions & 18 deletions client.go
Expand Up @@ -277,28 +277,15 @@ func (c *Client) GetTasks(param *TasksQuery) (resp *TaskResult, err error) {
functionName: "GetTasks",
}
if param != nil {
if param.Limit != 0 {
req.withQueryParams["limit"] = strconv.FormatInt(param.Limit, 10)
}
if param.From != 0 {
req.withQueryParams["from"] = strconv.FormatInt(param.From, 10)
}
if len(param.Statuses) != 0 {
req.withQueryParams["statuses"] = strings.Join(param.Statuses, ",")
}
if len(param.Types) != 0 {
req.withQueryParams["types"] = strings.Join(param.Types, ",")
}
if len(param.IndexUIDs) != 0 {
req.withQueryParams["indexUids"] = strings.Join(param.IndexUIDs, ",")
}
encodeTasksQuery(param, &req)
}
if err := c.executeRequest(req); err != nil {
return nil, err
}
return resp, nil
}


// WaitForTask waits for a task to be processed
//
// The function will check by regular interval provided in parameter interval
Expand Down Expand Up @@ -390,9 +377,7 @@ func convertKeyToParsedKey(key Key) (resp KeyParsed) {
// Convert time.Time to *string to feat the exact ISO-8601
// format of Meilisearch
if !key.ExpiresAt.IsZero() {
const Format = "2006-01-02T15:04:05"
timeParsedToString := key.ExpiresAt.Format(Format)
resp.ExpiresAt = &timeParsedToString
resp.ExpiresAt = formatDate(key.ExpiresAt, true)
}
return resp
}
Expand All @@ -401,3 +386,51 @@ func IsValidUUID(uuid string) bool {
r := regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")
return r.MatchString(uuid)
}

func encodeTasksQuery(param *TasksQuery, req *internalRequest) {
if param.Limit != 0 {
req.withQueryParams["limit"] = strconv.FormatInt(param.Limit, 10)
}
if param.From != 0 {
req.withQueryParams["from"] = strconv.FormatInt(param.From, 10)
}
if len(param.Statuses) != 0 {
req.withQueryParams["statuses"] = strings.Join(param.Statuses, ",")
}
if len(param.Types) != 0 {
req.withQueryParams["types"] = strings.Join(param.Types, ",")
}
if len(param.IndexUIDs) != 0 {
req.withQueryParams["indexUids"] = strings.Join(param.IndexUIDs, ",")
}
if len(param.UIDs) != 0 {
req.withQueryParams["uids"] = strings.Trim(strings.Join(strings.Fields(fmt.Sprint(param.UIDs)), ","), "[]")
}
if len(param.CanceledBy) != 0 {
req.withQueryParams["canceledBy"] = strings.Trim(strings.Join(strings.Fields(fmt.Sprint(param.CanceledBy)), ","), "[]")
}
if !param.BeforeEnqueuedAt.IsZero() {
req.withQueryParams["beforeEnqueuedAt"] = *formatDate(param.BeforeEnqueuedAt, false)
}
if !param.AfterEnqueuedAt.IsZero() {
req.withQueryParams["afterEnqueuedAt"] = *formatDate(param.AfterEnqueuedAt, false)
}
if !param.BeforeStartedAt.IsZero() {
req.withQueryParams["beforeStartedAt"] = *formatDate(param.BeforeStartedAt, false)
}
if !param.AfterStartedAt.IsZero() {
req.withQueryParams["afterStartedAt"] = *formatDate(param.AfterStartedAt, false)
}
if !param.BeforeFinishedAt.IsZero() {
req.withQueryParams["beforeFinishedAt"] = *formatDate(param.BeforeFinishedAt, false)
}
if !param.AfterFinishedAt.IsZero() {
req.withQueryParams["afterFinishedAt"] = *formatDate(param.AfterFinishedAt, false)
}
}

func formatDate(date time.Time, key bool) *string {
const format = "2006-01-02T15:04:05Z"
timeParsedToString := date.Format(format)
return &timeParsedToString
}
10 changes: 5 additions & 5 deletions client_test.go
Expand Up @@ -762,8 +762,8 @@ func TestClient_GetTasks(t *testing.T) {
{ID: "123", Name: "Pride and Prejudice"},
},
query: &TasksQuery{
Limit: 1,
UIDs: []string{"1"},
Limit: 1,
UIDs: []int64{1},
},
},
},
Expand All @@ -776,7 +776,7 @@ func TestClient_GetTasks(t *testing.T) {
{ID: "123", Name: "Pride and Prejudice"},
},
query: &TasksQuery{
Limit: 1,
Limit: 1,
BeforeEnqueuedAt: time.Now(),
},
},
Expand All @@ -790,8 +790,8 @@ func TestClient_GetTasks(t *testing.T) {
{ID: "123", Name: "Pride and Prejudice"},
},
query: &TasksQuery{
Limit: 1,
CanceledBy: 1,
Limit: 1,
CanceledBy: []int64{1},
},
},
},
Expand Down
53 changes: 27 additions & 26 deletions types.go
Expand Up @@ -35,8 +35,8 @@ type IndexesResults struct {
}

type IndexesQuery struct {
Limit int64 `json:"limit,omitempty"`
Offset int64 `json:"offset,omitempty"`
Limit int64
Offset int64
}

// Settings is the type that represents the settings in Meilisearch
Expand Down Expand Up @@ -130,35 +130,39 @@ type Task struct {
StartedAt time.Time `json:"startedAt,omitempty"`
FinishedAt time.Time `json:"finishedAt,omitempty"`
Details Details `json:"details,omitempty"`
CanceledBy int64 `json:"canceledBy,omitempty"`
}

// TaskInfo indicates information regarding a task returned by an asynchronous method
//
// Documentation: https://docs.meilisearch.com/reference/api/tasks.html#tasks
type TaskInfo struct {
Status TaskStatus `json:"status"`
TaskUID int64 `json:"taskUid,omitempty"`
IndexUID string `json:"indexUid"`
Type string `json:"type"`
EnqueuedAt time.Time `json:"enqueuedAt"`
Status TaskStatus `json:"status"`
TaskUID int64 `json:"taskUid,omitempty"`
IndexUID string `json:"indexUid"`
Type string `json:"type"`
Error meilisearchApiError `json:"error,omitempty"`
Duration string `json:"duration,omitempty"`
EnqueuedAt time.Time `json:"enqueuedAt"`
StartedAt time.Time `json:"startedAt,omitempty"`
FinishedAt time.Time `json:"finishedAt,omitempty"`
Details Details `json:"details,omitempty"`
}

// TasksQuery is the request body for list documents method
type TasksQuery struct {
UIDs []string `json:"uids,omitempty"`
Limit int64 `json:"limit,omitempty"`
From int64 `json:"from,omitempty"`
IndexUIDs []string `json:"indexUids,omitempty"`
Statuses []string `json:"statuses,omitempty"`
Types []string `json:"types,omitempty"`
CanceledBy int64 `json:"canceledBy,omitempty"`
BeforeEnqueuedAt time.Time `json:"beforeEnqueuedAt,omitempty"`
AfterEnqueuedAt time.Time `json:"afterEnqueuedAt,omitempty"`
BeforeStartedAt time.Time `json:"beforeStartedAt,omitempty"`
AfterStartedAt time.Time `json:"afterStartedAt,omitempty"`
BeforeFinishedAt time.Time `json:"beforeFinishedAt,omitempty"`
AfterFinishedAt time.Time `json:"afterFinishedAt,omitempty"`
UIDs []int64
Limit int64
From int64
IndexUIDs []string
Statuses []string
Types []string
CanceledBy []int64
BeforeEnqueuedAt time.Time
AfterEnqueuedAt time.Time
BeforeStartedAt time.Time
AfterStartedAt time.Time
BeforeFinishedAt time.Time
AfterFinishedAt time.Time
}

type Details struct {
Expand All @@ -168,9 +172,6 @@ type Details struct {
PrimaryKey string `json:"primaryKey,omitempty"`
RankingRules []string `json:"rankingRules,omitempty"`
DistinctAttribute *string `json:"distinctAttribute,omitempty"`
SearchableAttributes []string `json:"searchableAttributes,omitempty"`
DisplayedAttributes []string `json:"displayedAttributes,omitempty"`
StopWords []string `json:"stopWords,omitempty"`
Synonyms map[string][]string `json:"synonyms,omitempty"`
FilterableAttributes []string `json:"filterableAttributes,omitempty"`
SortableAttributes []string `json:"sortableAttributes,omitempty"`
Expand Down Expand Up @@ -226,8 +227,8 @@ type KeysResults struct {
}

type KeysQuery struct {
Limit int64 `json:"limit,omitempty"`
Offset int64 `json:"offset,omitempty"`
Limit int64
Offset int64
}

// Information to create a tenant token
Expand Down

0 comments on commit 029e503

Please sign in to comment.