@@ -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