[GH-6798] added a new api endpoint to get the bulk reactions for posts (#10049)

* 6798 added a new api to get the bulk reactions for posts

* 6798 added the permsission check before getting the reactions

* GH-6798 added a new app function for the new endpoint

* 6798 added a store method to get reactions for multiple posts

* 6798 connected the app function with the new store function

* 6798 fixed the review comments
Этот коммит содержится в:
Pradeep Murugesan
2019-01-03 14:35:08 +01:00
коммит произвёл Joram Wilander
родитель 7b7b89d5ae
Коммит 99160ff0bc
17 изменённых файлов: 342 добавлений и 0 удалений

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

@@ -60,6 +60,35 @@ func (a *App) GetReactionsForPost(postId string) ([]*model.Reaction, *model.AppE
return result.Data.([]*model.Reaction), nil
}
func (a *App) GetBulkReactionsForPosts(postIds []string) (map[string][]*model.Reaction, *model.AppError) {
reactions := make(map[string][]*model.Reaction)
result := <-a.Srv.Store.Reaction().BulkGetForPosts(postIds)
if result.Err != nil {
return nil, result.Err
}
allReactions := result.Data.([]*model.Reaction)
for _, reaction := range allReactions {
reactionsForPost := reactions[reaction.PostId]
reactionsForPost = append(reactionsForPost, reaction)
reactions[reaction.PostId] = reactionsForPost
}
reactions = populateEmptyReactions(postIds, reactions)
return reactions, nil
}
func populateEmptyReactions(postIds []string, reactions map[string][]*model.Reaction) map[string][]*model.Reaction {
for _, postId := range postIds {
if _, present := reactions[postId]; !present {
reactions[postId] = []*model.Reaction{}
}
}
return reactions
}
func (a *App) DeleteReactionForPost(reaction *model.Reaction) *model.AppError {
post, err := a.GetSinglePost(reaction.PostId)
if err != nil {