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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
listEmoji, err := app.GetEmojiList()
|
listEmoji, err := app.GetEmojiList(0, 100000)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ func getEmojiList(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
listEmoji, err := app.GetEmojiList()
|
listEmoji, err := app.GetEmojiList(c.Params.Page, c.Params.PerPage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ func TestGetEmojiList(t *testing.T) {
|
|||||||
emojis[idx] = emoji
|
emojis[idx] = emoji
|
||||||
}
|
}
|
||||||
|
|
||||||
listEmoji, resp := Client.GetEmojiList()
|
listEmoji, resp := Client.GetEmojiList(0, 100)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
for _, emoji := range emojis {
|
for _, emoji := range emojis {
|
||||||
found := false
|
found := false
|
||||||
@@ -190,7 +190,7 @@ func TestGetEmojiList(t *testing.T) {
|
|||||||
|
|
||||||
_, resp = Client.DeleteEmoji(emojis[0].Id)
|
_, resp = Client.DeleteEmoji(emojis[0].Id)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
listEmoji, resp = Client.GetEmojiList()
|
listEmoji, resp = Client.GetEmojiList(0, 100)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
found := false
|
found := false
|
||||||
for _, savedEmoji := range listEmoji {
|
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)
|
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) {
|
func TestDeleteEmoji(t *testing.T) {
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ func CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartImageData *m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetEmojiList() ([]*model.Emoji, *model.AppError) {
|
func GetEmojiList(page, perPage int) ([]*model.Emoji, *model.AppError) {
|
||||||
if result := <-Srv.Store.Emoji().GetAll(); result.Err != nil {
|
if result := <-Srv.Store.Emoji().GetList(page*perPage, perPage); result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
} else {
|
} else {
|
||||||
return result.Data.([]*model.Emoji), nil
|
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())
|
return c.DoEmojiUploadFile(c.GetEmojisRoute(), body.Bytes(), writer.FormDataContentType())
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEmojiList returns a list of custom emoji in the system.
|
// GetEmojiList returns a page of custom emoji on the system.
|
||||||
func (c *Client4) GetEmojiList() ([]*Emoji, *Response) {
|
func (c *Client4) GetEmojiList(page, perPage int) ([]*Emoji, *Response) {
|
||||||
if r, err := c.DoApiGet(c.GetEmojisRoute(), ""); err != nil {
|
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)
|
return nil, BuildErrorResponse(r, err)
|
||||||
} else {
|
} else {
|
||||||
defer closeBody(r)
|
defer closeBody(r)
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ func (es SqlEmojiStore) GetByName(name string) StoreChannel {
|
|||||||
return storeChannel
|
return storeChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
func (es SqlEmojiStore) GetAll() StoreChannel {
|
func (es SqlEmojiStore) GetList(offset, limit int) StoreChannel {
|
||||||
storeChannel := make(StoreChannel, 1)
|
storeChannel := make(StoreChannel, 1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -164,8 +164,9 @@ func (es SqlEmojiStore) GetAll() StoreChannel {
|
|||||||
FROM
|
FROM
|
||||||
Emoji
|
Emoji
|
||||||
WHERE
|
WHERE
|
||||||
DeleteAt = 0`); err != nil {
|
DeleteAt = 0
|
||||||
result.Err = model.NewLocAppError("SqlEmojiStore.Get", "store.sql_emoji.get_all.app_error", nil, err.Error())
|
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 {
|
} else {
|
||||||
result.Data = emoji
|
result.Data = emoji
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ func TestEmojiGetByName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmojiGetAll(t *testing.T) {
|
func TestEmojiGetList(t *testing.T) {
|
||||||
Setup()
|
Setup()
|
||||||
|
|
||||||
emojis := []model.Emoji{
|
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)
|
t.Fatal(result.Err)
|
||||||
} else {
|
} else {
|
||||||
for _, emoji := range emojis {
|
for _, emoji := range emojis {
|
||||||
|
|||||||
@@ -349,7 +349,7 @@ type EmojiStore interface {
|
|||||||
Save(emoji *model.Emoji) StoreChannel
|
Save(emoji *model.Emoji) StoreChannel
|
||||||
Get(id string, allowFromCache bool) StoreChannel
|
Get(id string, allowFromCache bool) StoreChannel
|
||||||
GetByName(name string) StoreChannel
|
GetByName(name string) StoreChannel
|
||||||
GetAll() StoreChannel
|
GetList(offset, limit int) StoreChannel
|
||||||
Delete(id string, time int64) StoreChannel
|
Delete(id string, time int64) StoreChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user