diff options
author | Andrei Stanciu <andrei.stanciu@geminisols.ro> | 2017-02-28 10:41:38 +0200 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2017-02-28 08:41:38 +0000 |
commit | 45edfbe719b87bc6207f88350ff501eff142b28c (patch) | |
tree | 30dac4de7c3b43ce9b2ec2160e8c993cc9c4e764 /store | |
parent | 83c113595ace467ad34f05e35fb2282fa8631a17 (diff) | |
download | chat-45edfbe719b87bc6207f88350ff501eff142b28c.tar.gz chat-45edfbe719b87bc6207f88350ff501eff142b28c.tar.bz2 chat-45edfbe719b87bc6207f88350ff501eff142b28c.zip |
Get all teams api4 (#5542)
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_team_store.go | 58 | ||||
-rw-r--r-- | store/store.go | 2 |
2 files changed, 60 insertions, 0 deletions
diff --git a/store/sql_team_store.go b/store/sql_team_store.go index 9ef420943..bd99ed95c 100644 --- a/store/sql_team_store.go +++ b/store/sql_team_store.go @@ -283,6 +283,32 @@ func (s SqlTeamStore) GetAll() StoreChannel { return storeChannel } +func (s SqlTeamStore) GetAllPage(offset int, limit int) StoreChannel { + storeChannel := make(StoreChannel, 1) + + go func() { + result := StoreResult{} + + var data []*model.Team + if _, err := s.GetReplica().Select(&data, "SELECT * FROM Teams LIMIT :Limit OFFSET :Offset", map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil { + result.Err = model.NewLocAppError("SqlTeamStore.GetAllTeams", "store.sql_team.get_all.app_error", nil, err.Error()) + } + + for _, team := range data { + if len(team.InviteId) == 0 { + team.InviteId = team.Id + } + } + + result.Data = data + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (s SqlTeamStore) GetTeamsByUserId(userId string) StoreChannel { storeChannel := make(StoreChannel, 1) @@ -341,6 +367,38 @@ func (s SqlTeamStore) GetAllTeamListing() StoreChannel { return storeChannel } +func (s SqlTeamStore) GetAllTeamPageListing(offset int, limit int) StoreChannel { + storeChannel := make(StoreChannel, 1) + + go func() { + result := StoreResult{} + + query := "SELECT * FROM Teams WHERE AllowOpenInvite = 1 LIMIT :Limit OFFSET :Offset" + + if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES { + query = "SELECT * FROM Teams WHERE AllowOpenInvite = true LIMIT :Limit OFFSET :Offset" + } + + var data []*model.Team + if _, err := s.GetReplica().Select(&data, query, map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil { + result.Err = model.NewLocAppError("SqlTeamStore.GetAllTeamListing", "store.sql_team.get_all_team_listing.app_error", nil, err.Error()) + } + + for _, team := range data { + if len(team.InviteId) == 0 { + team.InviteId = team.Id + } + } + + result.Data = data + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (s SqlTeamStore) PermanentDelete(teamId string) StoreChannel { storeChannel := make(StoreChannel, 1) diff --git a/store/store.go b/store/store.go index 4226f03a5..57741742c 100644 --- a/store/store.go +++ b/store/store.go @@ -62,7 +62,9 @@ type TeamStore interface { GetByName(name string) StoreChannel SearchByName(name string) StoreChannel GetAll() StoreChannel + GetAllPage(offset int, limit int) StoreChannel GetAllTeamListing() StoreChannel + GetAllTeamPageListing(offset int, limit int) StoreChannel GetTeamsByUserId(userId string) StoreChannel GetByInviteId(inviteId string) StoreChannel PermanentDelete(teamId string) StoreChannel |