Add paging to the GET /emojis endpoint (#6802)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
02335ddad4
Коммит
f54aee1ef5
@@ -36,7 +36,7 @@ func getEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
listEmoji, err := app.GetEmojiList()
|
||||
listEmoji, err := app.GetEmojiList(0, 100000)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -81,7 +81,7 @@ func getEmojiList(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
listEmoji, err := app.GetEmojiList()
|
||||
listEmoji, err := app.GetEmojiList(c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -173,7 +173,7 @@ func TestGetEmojiList(t *testing.T) {
|
||||
emojis[idx] = emoji
|
||||
}
|
||||
|
||||
listEmoji, resp := Client.GetEmojiList()
|
||||
listEmoji, resp := Client.GetEmojiList(0, 100)
|
||||
CheckNoError(t, resp)
|
||||
for _, emoji := range emojis {
|
||||
found := false
|
||||
@@ -190,7 +190,7 @@ func TestGetEmojiList(t *testing.T) {
|
||||
|
||||
_, resp = Client.DeleteEmoji(emojis[0].Id)
|
||||
CheckNoError(t, resp)
|
||||
listEmoji, resp = Client.GetEmojiList()
|
||||
listEmoji, resp = Client.GetEmojiList(0, 100)
|
||||
CheckNoError(t, resp)
|
||||
found := false
|
||||
for _, savedEmoji := range listEmoji {
|
||||
@@ -202,6 +202,13 @@ func TestGetEmojiList(t *testing.T) {
|
||||
t.Fatalf("should not get a deleted emoji %v", emojis[0].Id)
|
||||
}
|
||||
}
|
||||
|
||||
listEmoji, resp = Client.GetEmojiList(0, 1)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if len(listEmoji) != 1 {
|
||||
t.Fatal("should only return 1")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteEmoji(t *testing.T) {
|
||||
|
||||
@@ -66,8 +66,8 @@ func CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartImageData *m
|
||||
}
|
||||
}
|
||||
|
||||
func GetEmojiList() ([]*model.Emoji, *model.AppError) {
|
||||
if result := <-Srv.Store.Emoji().GetAll(); result.Err != nil {
|
||||
func GetEmojiList(page, perPage int) ([]*model.Emoji, *model.AppError) {
|
||||
if result := <-Srv.Store.Emoji().GetList(page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.Emoji), nil
|
||||
|
||||
@@ -2699,9 +2699,10 @@ func (c *Client4) CreateEmoji(emoji *Emoji, image []byte, filename string) (*Emo
|
||||
return c.DoEmojiUploadFile(c.GetEmojisRoute(), body.Bytes(), writer.FormDataContentType())
|
||||
}
|
||||
|
||||
// GetEmojiList returns a list of custom emoji in the system.
|
||||
func (c *Client4) GetEmojiList() ([]*Emoji, *Response) {
|
||||
if r, err := c.DoApiGet(c.GetEmojisRoute(), ""); err != nil {
|
||||
// GetEmojiList returns a page of custom emoji on the system.
|
||||
func (c *Client4) GetEmojiList(page, perPage int) ([]*Emoji, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
|
||||
if r, err := c.DoApiGet(c.GetEmojisRoute()+query, ""); err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
|
||||
@@ -150,7 +150,7 @@ func (es SqlEmojiStore) GetByName(name string) StoreChannel {
|
||||
return storeChannel
|
||||
}
|
||||
|
||||
func (es SqlEmojiStore) GetAll() StoreChannel {
|
||||
func (es SqlEmojiStore) GetList(offset, limit int) StoreChannel {
|
||||
storeChannel := make(StoreChannel, 1)
|
||||
|
||||
go func() {
|
||||
@@ -164,8 +164,9 @@ func (es SqlEmojiStore) GetAll() StoreChannel {
|
||||
FROM
|
||||
Emoji
|
||||
WHERE
|
||||
DeleteAt = 0`); err != nil {
|
||||
result.Err = model.NewLocAppError("SqlEmojiStore.Get", "store.sql_emoji.get_all.app_error", nil, err.Error())
|
||||
DeleteAt = 0
|
||||
LIMIT :Limit OFFSET :Offset`, 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
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ func TestEmojiGetByName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmojiGetAll(t *testing.T) {
|
||||
func TestEmojiGetList(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
emojis := []model.Emoji{
|
||||
@@ -153,7 +153,7 @@ func TestEmojiGetAll(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
if result := <-store.Emoji().GetAll(); result.Err != nil {
|
||||
if result := <-store.Emoji().GetList(0, 100); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
for _, emoji := range emojis {
|
||||
|
||||
@@ -349,7 +349,7 @@ type EmojiStore interface {
|
||||
Save(emoji *model.Emoji) StoreChannel
|
||||
Get(id string, allowFromCache bool) StoreChannel
|
||||
GetByName(name string) StoreChannel
|
||||
GetAll() StoreChannel
|
||||
GetList(offset, limit int) StoreChannel
|
||||
Delete(id string, time int64) StoreChannel
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user