From b1520d0b9458d1dab09d9e3e05dd7522fc28ba57 Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Wed, 6 Jul 2016 10:11:21 -0800 Subject: PLT-3512 adding join/leave channel to the CLI (#3498) * PLT-3512 adding join/leave channel to the CLI * PLT-3512 adding list channels to the CLI * PLT-3512 adding restore channel * Adding make run-cli command * Updating txt * Fixing txt purposed by PMs --- store/sql_channel_store.go | 28 +++++++++++++++++++++++++++- store/sql_channel_store_test.go | 9 +++++++++ store/store.go | 2 ++ 3 files changed, 38 insertions(+), 1 deletion(-) (limited to 'store') diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index 3636fb62f..e5e0aa8ba 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -289,12 +289,16 @@ func (s SqlChannelStore) get(id string, master bool) StoreChannel { } func (s SqlChannelStore) Delete(channelId string, time int64) StoreChannel { + return s.SetDeleteAt(channelId, time, time) +} + +func (s SqlChannelStore) SetDeleteAt(channelId string, deleteAt int64, updateAt int64) StoreChannel { storeChannel := make(StoreChannel) go func() { result := StoreResult{} - _, err := s.GetMaster().Exec("Update Channels SET DeleteAt = :Time, UpdateAt = :Time WHERE Id = :ChannelId", map[string]interface{}{"Time": time, "ChannelId": channelId}) + _, err := s.GetMaster().Exec("Update Channels SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :ChannelId", map[string]interface{}{"DeleteAt": deleteAt, "UpdateAt": updateAt, "ChannelId": channelId}) if err != nil { result.Err = model.NewLocAppError("SqlChannelStore.Delete", "store.sql_channel.delete.channel.app_error", nil, "id="+channelId+", err="+err.Error()) } @@ -948,6 +952,28 @@ func (s SqlChannelStore) GetForExport(teamId string) StoreChannel { return storeChannel } +func (s SqlChannelStore) GetAll(teamId string) StoreChannel { + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + var data []*model.Channel + _, err := s.GetReplica().Select(&data, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Type != 'D' ORDER BY Name", map[string]interface{}{"TeamId": teamId}) + + if err != nil { + result.Err = model.NewLocAppError("SqlChannelStore.GetAll", "store.sql_channel.get_all.app_error", nil, "teamId="+teamId+", err="+err.Error()) + } else { + result.Data = data + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType string) StoreChannel { storeChannel := make(StoreChannel) diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go index 2b284d06e..0c293972c 100644 --- a/store/sql_channel_store_test.go +++ b/store/sql_channel_store_test.go @@ -200,6 +200,15 @@ func TestChannelStoreGet(t *testing.T) { t.Fatal("invalid returned channel") } } + + if r3 := <-store.Channel().GetAll(o1.TeamId); r3.Err != nil { + t.Fatal(r3.Err) + } else { + channels := r3.Data.([]*model.Channel) + if len(channels) == 0 { + t.Fatal("too little") + } + } } func TestChannelStoreDelete(t *testing.T) { diff --git a/store/store.go b/store/store.go index 29a7e8d82..f576cc2ab 100644 --- a/store/store.go +++ b/store/store.go @@ -77,12 +77,14 @@ type ChannelStore interface { Get(id string) StoreChannel GetFromMaster(id string) StoreChannel Delete(channelId string, time int64) StoreChannel + SetDeleteAt(channelId string, deleteAt int64, updateAt int64) StoreChannel PermanentDeleteByTeam(teamId string) StoreChannel GetByName(team_id string, domain string) StoreChannel GetChannels(teamId string, userId string) StoreChannel GetMoreChannels(teamId string, userId string) StoreChannel GetChannelCounts(teamId string, userId string) StoreChannel GetForExport(teamId string) StoreChannel + GetAll(teamId string) StoreChannel SaveMember(member *model.ChannelMember) StoreChannel UpdateMember(member *model.ChannelMember) StoreChannel -- cgit v1.2.3-1-g7c22