summaryrefslogtreecommitdiffstats
path: root/store/sql_webhook_store.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-03-13 10:40:43 -0400
committerGitHub <noreply@github.com>2017-03-13 10:40:43 -0400
commit19c67d7fe35f92ae8a288dcdb9877d3bede41a61 (patch)
tree1119f74c30564ce53d5e7dc566009594e348f494 /store/sql_webhook_store.go
parent3ebfb369530e28ca3246c5cd2833e666edce9c90 (diff)
downloadchat-19c67d7fe35f92ae8a288dcdb9877d3bede41a61.tar.gz
chat-19c67d7fe35f92ae8a288dcdb9877d3bede41a61.tar.bz2
chat-19c67d7fe35f92ae8a288dcdb9877d3bede41a61.zip
Implement GET and POST /hooks/outgoing endpoints for APIv4 (#5645)
Diffstat (limited to 'store/sql_webhook_store.go')
-rw-r--r--store/sql_webhook_store.go43
1 files changed, 39 insertions, 4 deletions
diff --git a/store/sql_webhook_store.go b/store/sql_webhook_store.go
index e0e6562bf..67290c983 100644
--- a/store/sql_webhook_store.go
+++ b/store/sql_webhook_store.go
@@ -329,7 +329,7 @@ func (s SqlWebhookStore) GetOutgoing(id string) StoreChannel {
return storeChannel
}
-func (s SqlWebhookStore) GetOutgoingByChannel(channelId string) StoreChannel {
+func (s SqlWebhookStore) GetOutgoingList(offset, limit int) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
@@ -337,7 +337,35 @@ func (s SqlWebhookStore) GetOutgoingByChannel(channelId string) StoreChannel {
var webhooks []*model.OutgoingWebhook
- if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM OutgoingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0", map[string]interface{}{"ChannelId": channelId}); err != nil {
+ if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM OutgoingWebhooks WHERE DeleteAt = 0 LIMIT :Limit OFFSET :Offset", map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
+ result.Err = model.NewLocAppError("SqlWebhookStore.GetOutgoingList", "store.sql_webhooks.get_outgoing_by_channel.app_error", nil, "err="+err.Error())
+ }
+
+ result.Data = webhooks
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
+func (s SqlWebhookStore) GetOutgoingByChannel(channelId string, offset, limit int) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ var webhooks []*model.OutgoingWebhook
+
+ query := ""
+ if limit < 0 || offset < 0 {
+ query = "SELECT * FROM OutgoingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0"
+ } else {
+ query = "SELECT * FROM OutgoingWebhooks WHERE ChannelId = :ChannelId AND DeleteAt = 0 LIMIT :Limit OFFSET :Offset"
+ }
+
+ if _, err := s.GetReplica().Select(&webhooks, query, map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}); err != nil {
result.Err = model.NewLocAppError("SqlWebhookStore.GetOutgoingByChannel", "store.sql_webhooks.get_outgoing_by_channel.app_error", nil, "channelId="+channelId+", err="+err.Error())
}
@@ -350,7 +378,7 @@ func (s SqlWebhookStore) GetOutgoingByChannel(channelId string) StoreChannel {
return storeChannel
}
-func (s SqlWebhookStore) GetOutgoingByTeam(teamId string) StoreChannel {
+func (s SqlWebhookStore) GetOutgoingByTeam(teamId string, offset, limit int) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
@@ -358,7 +386,14 @@ func (s SqlWebhookStore) GetOutgoingByTeam(teamId string) StoreChannel {
var webhooks []*model.OutgoingWebhook
- if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM OutgoingWebhooks WHERE TeamId = :TeamId AND DeleteAt = 0", map[string]interface{}{"TeamId": teamId}); err != nil {
+ query := ""
+ if limit < 0 || offset < 0 {
+ query = "SELECT * FROM OutgoingWebhooks WHERE TeamId = :TeamId AND DeleteAt = 0"
+ } else {
+ query = "SELECT * FROM OutgoingWebhooks WHERE TeamId = :TeamId AND DeleteAt = 0 LIMIT :Limit OFFSET :Offset"
+ }
+
+ if _, err := s.GetReplica().Select(&webhooks, query, map[string]interface{}{"TeamId": teamId, "Offset": offset, "Limit": limit}); err != nil {
result.Err = model.NewLocAppError("SqlWebhookStore.GetOutgoingByTeam", "store.sql_webhooks.get_outgoing_by_team.app_error", nil, "teamId="+teamId+", err="+err.Error())
}