Skip to content

Commit 9d80462

Browse files
bors[bot]meili-botalallema
authored
Merge #382
382: Changes related to the next Meilisearch release (v0.30.0) r=alallema a=meili-bot Related to this issue: meilisearch/integration-guides#221 This PR: - gathers the changes related to the next Meilisearch release (v0.30.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases). - might eventually contain test failures until the Meilisearch v0.30.0 is out. ⚠️ This PR should NOT be merged until the next release of Meilisearch (v0.30.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/main/resources/pre-release-week.md) purpose._ Done: - #390 - #392 - #395 - #396 - #397 Co-authored-by: meili-bot <74670311+meili-bot@users.noreply.github.com> Co-authored-by: Amélie <alallema@users.noreply.github.com> Co-authored-by: alallema <amelie@meilisearch.com>
2 parents fc4a073 + 0345f62 commit 9d80462

File tree

10 files changed

+2319
-719
lines changed

10 files changed

+2319
-719
lines changed

.code-samples.meilisearch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ get_all_tasks_filtering_1: |-
791791
client.Index("movies").GetTasks(nil);
792792
// OR
793793
client.GetTasks(&TasksQuery{
794-
IndexUID: []string{"movies"},
794+
IndexUIDs: []string{"movies"},
795795
});
796796
get_all_tasks_filtering_2: |-
797797
client.GetTasks(&meilisearch.TasksQuery{

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ searchRes, err := index.Search("wonder",
230230

231231
## 🤖 Compatibility with Meilisearch
232232

233-
This package only guarantees the compatibility with the [version v0.29.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.29.0).
233+
This package only guarantees the compatibility with the [version v0.30.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.30.0).
234234

235235
## 💡 Learn more
236236

client.go

Lines changed: 131 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ type ClientInterface interface {
5454
IsHealthy() bool
5555
GetTask(taskUID int64) (resp *Task, err error)
5656
GetTasks(param *TasksQuery) (resp *TaskResult, err error)
57+
CancelTasks(param *CancelTasksQuery) (resp *TaskInfo, err error)
58+
DeleteTasks(param *DeleteTasksQuery) (resp *TaskInfo, err error)
59+
SwapIndexes(param []SwapIndexesParams) (resp *TaskInfo, err error)
5760
WaitForTask(taskUID int64, options ...WaitParams) (*Task, error)
5861
GenerateTenantToken(APIKeyUID string, searchRules map[string]interface{}, options *TenantTokenOptions) (resp string, err error)
5962
}
@@ -277,21 +280,87 @@ func (c *Client) GetTasks(param *TasksQuery) (resp *TaskResult, err error) {
277280
functionName: "GetTasks",
278281
}
279282
if param != nil {
280-
if param.Limit != 0 {
281-
req.withQueryParams["limit"] = strconv.FormatInt(param.Limit, 10)
282-
}
283-
if param.From != 0 {
284-
req.withQueryParams["from"] = strconv.FormatInt(param.From, 10)
285-
}
286-
if len(param.Status) != 0 {
287-
req.withQueryParams["status"] = strings.Join(param.Status, ",")
288-
}
289-
if len(param.Type) != 0 {
290-
req.withQueryParams["type"] = strings.Join(param.Type, ",")
283+
encodeTasksQuery(param, &req)
284+
}
285+
if err := c.executeRequest(req); err != nil {
286+
return nil, err
287+
}
288+
return resp, nil
289+
}
290+
291+
func (c *Client) CancelTasks(param *CancelTasksQuery) (resp *TaskInfo, err error) {
292+
resp = &TaskInfo{}
293+
req := internalRequest{
294+
endpoint: "/tasks/cancel",
295+
method: http.MethodPost,
296+
withRequest: nil,
297+
withResponse: &resp,
298+
withQueryParams: map[string]string{},
299+
acceptedStatusCodes: []int{http.StatusOK},
300+
functionName: "CancelTasks",
301+
}
302+
if param != nil {
303+
paramToSend := &TasksQuery{
304+
UIDS: param.UIDS,
305+
IndexUIDS: param.IndexUIDS,
306+
Statuses: param.Statuses,
307+
Types: param.Types,
308+
BeforeEnqueuedAt: param.BeforeEnqueuedAt,
309+
AfterEnqueuedAt: param.AfterEnqueuedAt,
310+
BeforeStartedAt: param.BeforeStartedAt,
311+
AfterStartedAt: param.AfterStartedAt,
291312
}
292-
if len(param.IndexUID) != 0 {
293-
req.withQueryParams["indexUid"] = strings.Join(param.IndexUID, ",")
313+
encodeTasksQuery(paramToSend, &req)
314+
}
315+
if err := c.executeRequest(req); err != nil {
316+
return nil, err
317+
}
318+
return resp, nil
319+
}
320+
321+
func (c *Client) DeleteTasks(param *DeleteTasksQuery) (resp *TaskInfo, err error) {
322+
resp = &TaskInfo{}
323+
req := internalRequest{
324+
endpoint: "/tasks",
325+
method: http.MethodDelete,
326+
withRequest: nil,
327+
withResponse: &resp,
328+
withQueryParams: map[string]string{},
329+
acceptedStatusCodes: []int{http.StatusOK},
330+
functionName: "DeleteTasks",
331+
}
332+
if param != nil {
333+
paramToSend := &TasksQuery{
334+
UIDS: param.UIDS,
335+
IndexUIDS: param.IndexUIDS,
336+
Statuses: param.Statuses,
337+
Types: param.Types,
338+
CanceledBy: param.CanceledBy,
339+
BeforeEnqueuedAt: param.BeforeEnqueuedAt,
340+
AfterEnqueuedAt: param.AfterEnqueuedAt,
341+
BeforeStartedAt: param.BeforeStartedAt,
342+
AfterStartedAt: param.AfterStartedAt,
343+
BeforeFinishedAt: param.BeforeFinishedAt,
344+
AfterFinishedAt: param.AfterFinishedAt,
294345
}
346+
encodeTasksQuery(paramToSend, &req)
347+
}
348+
if err := c.executeRequest(req); err != nil {
349+
return nil, err
350+
}
351+
return resp, nil
352+
}
353+
354+
func (c *Client) SwapIndexes(param []SwapIndexesParams) (resp *TaskInfo, err error) {
355+
resp = &TaskInfo{}
356+
req := internalRequest{
357+
endpoint: "/swap-indexes",
358+
method: http.MethodPost,
359+
contentType: contentTypeJSON,
360+
withRequest: param,
361+
withResponse: &resp,
362+
acceptedStatusCodes: []int{http.StatusAccepted},
363+
functionName: "SwapIndexes",
295364
}
296365
if err := c.executeRequest(req); err != nil {
297366
return nil, err
@@ -390,9 +459,7 @@ func convertKeyToParsedKey(key Key) (resp KeyParsed) {
390459
// Convert time.Time to *string to feat the exact ISO-8601
391460
// format of Meilisearch
392461
if !key.ExpiresAt.IsZero() {
393-
const Format = "2006-01-02T15:04:05"
394-
timeParsedToString := key.ExpiresAt.Format(Format)
395-
resp.ExpiresAt = &timeParsedToString
462+
resp.ExpiresAt = formatDate(key.ExpiresAt, true)
396463
}
397464
return resp
398465
}
@@ -401,3 +468,51 @@ func IsValidUUID(uuid string) bool {
401468
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}$")
402469
return r.MatchString(uuid)
403470
}
471+
472+
func encodeTasksQuery(param *TasksQuery, req *internalRequest) {
473+
if param.Limit != 0 {
474+
req.withQueryParams["limit"] = strconv.FormatInt(param.Limit, 10)
475+
}
476+
if param.From != 0 {
477+
req.withQueryParams["from"] = strconv.FormatInt(param.From, 10)
478+
}
479+
if len(param.Statuses) != 0 {
480+
req.withQueryParams["statuses"] = strings.Join(param.Statuses, ",")
481+
}
482+
if len(param.Types) != 0 {
483+
req.withQueryParams["types"] = strings.Join(param.Types, ",")
484+
}
485+
if len(param.IndexUIDS) != 0 {
486+
req.withQueryParams["indexUids"] = strings.Join(param.IndexUIDS, ",")
487+
}
488+
if len(param.UIDS) != 0 {
489+
req.withQueryParams["uids"] = strings.Trim(strings.Join(strings.Fields(fmt.Sprint(param.UIDS)), ","), "[]")
490+
}
491+
if len(param.CanceledBy) != 0 {
492+
req.withQueryParams["canceledBy"] = strings.Trim(strings.Join(strings.Fields(fmt.Sprint(param.CanceledBy)), ","), "[]")
493+
}
494+
if !param.BeforeEnqueuedAt.IsZero() {
495+
req.withQueryParams["beforeEnqueuedAt"] = *formatDate(param.BeforeEnqueuedAt, false)
496+
}
497+
if !param.AfterEnqueuedAt.IsZero() {
498+
req.withQueryParams["afterEnqueuedAt"] = *formatDate(param.AfterEnqueuedAt, false)
499+
}
500+
if !param.BeforeStartedAt.IsZero() {
501+
req.withQueryParams["beforeStartedAt"] = *formatDate(param.BeforeStartedAt, false)
502+
}
503+
if !param.AfterStartedAt.IsZero() {
504+
req.withQueryParams["afterStartedAt"] = *formatDate(param.AfterStartedAt, false)
505+
}
506+
if !param.BeforeFinishedAt.IsZero() {
507+
req.withQueryParams["beforeFinishedAt"] = *formatDate(param.BeforeFinishedAt, false)
508+
}
509+
if !param.AfterFinishedAt.IsZero() {
510+
req.withQueryParams["afterFinishedAt"] = *formatDate(param.AfterFinishedAt, false)
511+
}
512+
}
513+
514+
func formatDate(date time.Time, key bool) *string {
515+
const format = "2006-01-02T15:04:05Z"
516+
timeParsedToString := date.Format(format)
517+
return &timeParsedToString
518+
}

0 commit comments

Comments
 (0)