MM-45494: Add endpoint for message history (#20945)

* add api url

* write sql in store

* update app and client golang driver

* update layers and tests

* change sql query sort

* update layers

* fix style

* fix style post_store.go

* fix comments

* add test for app/post_test.go

* update layers

* fix test

* fix style

* fix style again :)

* add permission check

* add additional checks and tests

* change from nil to empty

* update app-layers

* fix style

* add index for OriginalId for Posts table

* fix postgres query

* update migration file names

* update app-layers

* address PR reviews

* write tests for post store

* fix style

* Update file name

* Update file name 2

* Update file name 3

* Update file name 4

* change the error orders

* update migration file name

---------

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Sinan Sonmez (Chaush)
2023-02-07 15:30:37 +01:00
коммит произвёл GitHub
родитель eabf454764
Коммит 50fec7c892
19 изменённых файлов: 433 добавлений и 0 удалений

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

@@ -2344,6 +2344,34 @@ func (s *SqlPostStore) GetPostsByIds(postIds []string) ([]*model.Post, error) {
return posts, nil
}
func (s *SqlPostStore) GetEditHistoryForPost(postId string) ([]*model.Post, error) {
builder := s.getQueryBuilder().
Select("*").
From("Posts").
Where(sq.Eq{"Posts.OriginalId": postId}).
OrderBy("Posts.EditAt DESC")
queryString, args, err := builder.ToSql()
if err != nil {
if err == sql.ErrNoRows {
return nil, store.NewErrNotFound("Post", postId)
}
return nil, errors.Wrap(err, "failed to find post history")
}
posts := []*model.Post{}
err = s.GetReplicaX().Select(&posts, queryString, args...)
if err != nil {
return nil, errors.Wrapf(err, "error getting posts edit history with postId=%s", postId)
}
if len(posts) == 0 {
return nil, store.NewErrNotFound("failed to find post history", postId)
}
return posts, nil
}
func (s *SqlPostStore) GetPostsBatchForIndexing(startTime int64, startPostID string, limit int) ([]*model.PostForIndexing, error) {
posts := []*model.PostForIndexing{}
table := "Posts"