ABC-90 Add POST /emoji/search and GET /emoji/autocomplete API endpoints (#8125)

* Add POST /emoji/search and GET /emoji/autocomplete API endpoints

* Add constant to be clearer
Этот коммит содержится в:
Joram Wilander
2018-01-23 11:04:44 -05:00
коммит произвёл Christopher Speller
родитель 599991ea73
Коммит 4f4a765e7d
11 изменённых файлов: 381 добавлений и 3 удалений

Просмотреть файл

@@ -46,6 +46,7 @@ func (es SqlEmojiStore) CreateIndexesIfNotExists() {
es.CreateIndexIfNotExists("idx_emoji_update_at", "Emoji", "UpdateAt")
es.CreateIndexIfNotExists("idx_emoji_create_at", "Emoji", "CreateAt")
es.CreateIndexIfNotExists("idx_emoji_delete_at", "Emoji", "DeleteAt")
es.CreateIndexIfNotExists("idx_emoji_name", "Emoji", "Name")
}
func (es SqlEmojiStore) Save(emoji *model.Emoji) store.StoreChannel {
@@ -162,3 +163,31 @@ func (es SqlEmojiStore) Delete(id string, time int64) store.StoreChannel {
emojiCache.Remove(id)
})
}
func (es SqlEmojiStore) Search(name string, prefixOnly bool, limit int) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
var emojis []*model.Emoji
term := ""
if !prefixOnly {
term = "%"
}
term += name + "%"
if _, err := es.GetReplica().Select(&emojis,
`SELECT
*
FROM
Emoji
WHERE
Name LIKE :Name
AND DeleteAt = 0
ORDER BY Name
LIMIT :Limit`, map[string]interface{}{"Name": term, "Limit": limit}); err != nil {
result.Err = model.NewAppError("SqlEmojiStore.Search", "store.sql_emoji.get_by_name.app_error", nil, "name="+name+", "+err.Error(), http.StatusInternalServerError)
} else {
result.Data = emojis
}
})
}