* Migrate admin functions into app package

* More user function refactoring

* Move post functions into app package
Этот коммит содержится в:
Joram Wilander
2017-01-25 09:32:42 -05:00
коммит произвёл Harrison Healey
родитель 8ed665cb76
Коммит d245b29f82
24 изменённых файлов: 1466 добавлений и 1081 удалений

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

@@ -222,6 +222,27 @@ func (s SqlPostStore) Get(id string) StoreChannel {
return storeChannel
}
func (s SqlPostStore) GetSingle(id string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
var post model.Post
err := s.GetReplica().SelectOne(&post, "SELECT * FROM Posts WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": id})
if err != nil {
result.Err = model.NewLocAppError("SqlPostStore.GetSingle", "store.sql_post.get.app_error", nil, "id="+id+err.Error())
}
result.Data = &post
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
type etagPosts struct {
Id string
UpdateAt int64

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

@@ -63,6 +63,29 @@ func TestPostStoreGet(t *testing.T) {
}
}
func TestPostStoreGetSingle(t *testing.T) {
Setup()
o1 := &model.Post{}
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
if r1 := <-store.Post().GetSingle(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Post).CreateAt != o1.CreateAt {
t.Fatal("invalid returned post")
}
}
if err := (<-store.Post().GetSingle("123")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
}
func TestGetEtagCache(t *testing.T) {
Setup()
o1 := &model.Post{}

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

@@ -348,3 +348,25 @@ func (s SqlPreferenceStore) DeleteCategory(userId string, category string) Store
return storeChannel
}
func (s SqlPreferenceStore) DeleteCategoryAndName(category string, name string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
if _, err := s.GetMaster().Exec(
`DELETE FROM
Preferences
WHERE
Name = :Name
AND Category = :Category`, map[string]interface{}{"Name": name, "Category": category}); err != nil {
result.Err = model.NewLocAppError("SqlPreferenceStore.DeleteCategoryAndName", "store.sql_preference.delete.app_error", nil, err.Error())
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}

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

@@ -427,3 +427,48 @@ func TestPreferenceDeleteCategory(t *testing.T) {
t.Fatal("should've returned no preferences")
}
}
func TestPreferenceDeleteCategoryAndName(t *testing.T) {
Setup()
category := model.NewId()
name := model.NewId()
userId := model.NewId()
userId2 := model.NewId()
preference1 := model.Preference{
UserId: userId,
Category: category,
Name: name,
Value: "value1a",
}
preference2 := model.Preference{
UserId: userId2,
Category: category,
Name: name,
Value: "value1a",
}
Must(store.Preference().Save(&model.Preferences{preference1, preference2}))
if prefs := Must(store.Preference().GetAll(userId)).(model.Preferences); len([]model.Preference(prefs)) != 1 {
t.Fatal("should've returned 1 preference")
}
if prefs := Must(store.Preference().GetAll(userId2)).(model.Preferences); len([]model.Preference(prefs)) != 1 {
t.Fatal("should've returned 1 preference")
}
if result := <-store.Preference().DeleteCategoryAndName(category, name); result.Err != nil {
t.Fatal(result.Err)
}
if prefs := Must(store.Preference().GetAll(userId)).(model.Preferences); len([]model.Preference(prefs)) != 0 {
t.Fatal("should've returned no preferences")
}
if prefs := Must(store.Preference().GetAll(userId2)).(model.Preferences); len([]model.Preference(prefs)) != 0 {
t.Fatal("should've returned no preferences")
}
}

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

@@ -127,6 +127,7 @@ type PostStore interface {
Save(post *model.Post) StoreChannel
Update(newPost *model.Post, oldPost *model.Post) StoreChannel
Get(id string) StoreChannel
GetSingle(id string) StoreChannel
Delete(postId string, time int64) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
GetPosts(channelId string, offset int, limit int, allowFromCache bool) StoreChannel
@@ -276,6 +277,7 @@ type PreferenceStore interface {
GetAll(userId string) StoreChannel
Delete(userId, category, name string) StoreChannel
DeleteCategory(userId string, category string) StoreChannel
DeleteCategoryAndName(category string, name string) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
IsFeatureEnabled(feature, userId string) StoreChannel
}