Add sort query parameter to GET /emojis (#8121)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
9d6a9ff4be
Коммит
a844577535
@@ -123,18 +123,19 @@ func (es SqlEmojiStore) GetByName(name string) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (es SqlEmojiStore) GetList(offset, limit int) store.StoreChannel {
|
||||
func (es SqlEmojiStore) GetList(offset, limit int, sort string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var emoji []*model.Emoji
|
||||
|
||||
if _, err := es.GetReplica().Select(&emoji,
|
||||
`SELECT
|
||||
*
|
||||
FROM
|
||||
Emoji
|
||||
WHERE
|
||||
DeleteAt = 0
|
||||
LIMIT :Limit OFFSET :Offset`, map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
|
||||
query := "SELECT * FROM Emoji WHERE DeleteAt = 0"
|
||||
|
||||
if sort == model.EMOJI_SORT_BY_NAME {
|
||||
query += " ORDER BY Name"
|
||||
}
|
||||
|
||||
query += " LIMIT :Limit OFFSET :Offset"
|
||||
|
||||
if _, err := es.GetReplica().Select(&emoji, query, map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil {
|
||||
result.Err = model.NewAppError("SqlEmojiStore.GetList", "store.sql_emoji.get_all.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
result.Data = emoji
|
||||
|
||||
@@ -391,7 +391,7 @@ type EmojiStore interface {
|
||||
Save(emoji *model.Emoji) StoreChannel
|
||||
Get(id string, allowFromCache bool) StoreChannel
|
||||
GetByName(name string) StoreChannel
|
||||
GetList(offset, limit int) StoreChannel
|
||||
GetList(offset, limit int, sort string) StoreChannel
|
||||
Delete(id string, time int64) StoreChannel
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEmojiStore(t *testing.T, ss store.Store) {
|
||||
@@ -133,15 +135,15 @@ func testEmojiGetList(t *testing.T, ss store.Store) {
|
||||
emojis := []model.Emoji{
|
||||
{
|
||||
CreatorId: model.NewId(),
|
||||
Name: model.NewId(),
|
||||
Name: "00000000000000000000000000a" + model.NewId(),
|
||||
},
|
||||
{
|
||||
CreatorId: model.NewId(),
|
||||
Name: model.NewId(),
|
||||
Name: "00000000000000000000000000b" + model.NewId(),
|
||||
},
|
||||
{
|
||||
CreatorId: model.NewId(),
|
||||
Name: model.NewId(),
|
||||
Name: "00000000000000000000000000c" + model.NewId(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -154,7 +156,7 @@ func testEmojiGetList(t *testing.T, ss store.Store) {
|
||||
}
|
||||
}()
|
||||
|
||||
if result := <-ss.Emoji().GetList(0, 100); result.Err != nil {
|
||||
if result := <-ss.Emoji().GetList(0, 100, ""); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
for _, emoji := range emojis {
|
||||
@@ -172,4 +174,20 @@ func testEmojiGetList(t *testing.T, ss store.Store) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result := <-ss.Emoji().GetList(0, 3, model.EMOJI_SORT_BY_NAME)
|
||||
assert.Nil(t, result.Err)
|
||||
remojis := result.Data.([]*model.Emoji)
|
||||
assert.Equal(t, 3, len(remojis))
|
||||
assert.Equal(t, emojis[0].Name, remojis[0].Name)
|
||||
assert.Equal(t, emojis[1].Name, remojis[1].Name)
|
||||
assert.Equal(t, emojis[2].Name, remojis[2].Name)
|
||||
|
||||
result = <-ss.Emoji().GetList(1, 2, model.EMOJI_SORT_BY_NAME)
|
||||
assert.Nil(t, result.Err)
|
||||
remojis = result.Data.([]*model.Emoji)
|
||||
assert.Equal(t, 2, len(remojis))
|
||||
assert.Equal(t, emojis[1].Name, remojis[0].Name)
|
||||
assert.Equal(t, emojis[2].Name, remojis[1].Name)
|
||||
|
||||
}
|
||||
|
||||
@@ -61,13 +61,13 @@ func (_m *EmojiStore) GetByName(name string) store.StoreChannel {
|
||||
return r0
|
||||
}
|
||||
|
||||
// GetList provides a mock function with given fields: offset, limit
|
||||
func (_m *EmojiStore) GetList(offset int, limit int) store.StoreChannel {
|
||||
ret := _m.Called(offset, limit)
|
||||
// GetList provides a mock function with given fields: offset, limit, sort
|
||||
func (_m *EmojiStore) GetList(offset int, limit int, sort string) store.StoreChannel {
|
||||
ret := _m.Called(offset, limit, sort)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(int, int) store.StoreChannel); ok {
|
||||
r0 = rf(offset, limit)
|
||||
if rf, ok := ret.Get(0).(func(int, int, string) store.StoreChannel); ok {
|
||||
r0 = rf(offset, limit, sort)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
|
||||
Ссылка в новой задаче
Block a user