Skip to content

Commit

Permalink
add sort channels filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagleft committed Nov 2, 2022
1 parent 68f5b61 commit e17d010
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
27 changes: 26 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ const (
ChannelTypeDeleted
)

const (
SortChannelsByCreated SortChannelsBy = iota + 1
SortChannelsByIsPrivate
SortChannelsByModified
SortChannelsByName
SortChannelsByDescription
)

type SortChannelsBy int

type ChannelType int

// NewClient - create client with default data:
Expand Down Expand Up @@ -497,6 +507,7 @@ type GetChannelsTask struct {
ChannelType ChannelType // by default: 0 - registered
FromDate string // date example: 2019-11-23T10:00:00.001
ToDate string
SortBy SortChannelsBy
}

// GetChannels get available channels
Expand All @@ -512,7 +523,21 @@ func (c *UtopiaClient) GetChannels(task GetChannelsTask) ([]SearchChannelData, e
params["to"] = task.ToDate
}

response, err := c.apiQuery("getChannels", params)
filters := map[string]interface{}{}
switch task.SortBy {
case SortChannelsByCreated:
filters["sortBy"] = "created"
case SortChannelsByIsPrivate:
filters["sortBy"] = "isprivate"
case SortChannelsByName:
filters["sortBy"] = "name"
case SortChannelsByModified:
filters["sortBy"] = "modified"
case SortChannelsByDescription:
filters["sortBy"] = "description"
}

response, err := c.apiQueryWithFilters("getChannels", params, filters)
if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (

// Query is a filter for API requests
type Query struct {
Method string `json:"method"`
Token string `json:"token"`
Params map[string]interface{} `json:"params"`
Method string `json:"method"`
Token string `json:"token"`
Params map[string]interface{} `json:"params"`
Filters map[string]interface{} `json:"filter"`
}

// UtopiaClient lets you connect to Utopia Client
Expand Down

0 comments on commit e17d010

Please sign in to comment.