summaryrefslogtreecommitdiffstats
path: root/store/sqlstore
diff options
context:
space:
mode:
Diffstat (limited to 'store/sqlstore')
-rw-r--r--store/sqlstore/file_info_store.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/store/sqlstore/file_info_store.go b/store/sqlstore/file_info_store.go
index 7559640c8..824e41583 100644
--- a/store/sqlstore/file_info_store.go
+++ b/store/sqlstore/file_info_store.go
@@ -177,6 +177,30 @@ func (fs SqlFileInfoStore) GetForPost(postId string, readFromMaster bool, allowF
})
}
+func (fs SqlFileInfoStore) GetForUser(userId string) store.StoreChannel {
+ return store.Do(func(result *store.StoreResult) {
+ var infos []*model.FileInfo
+
+ dbmap := fs.GetReplica()
+
+ if _, err := dbmap.Select(&infos,
+ `SELECT
+ *
+ FROM
+ FileInfo
+ WHERE
+ CreatorId = :CreatorId
+ AND DeleteAt = 0
+ ORDER BY
+ CreateAt`, map[string]interface{}{"CreatorId": userId}); err != nil {
+ result.Err = model.NewAppError("SqlFileInfoStore.GetForPost",
+ "store.sql_file_info.get_for_user_id.app_error", nil, "creator_id="+userId+", "+err.Error(), http.StatusInternalServerError)
+ } else {
+ result.Data = infos
+ }
+ })
+}
+
func (fs SqlFileInfoStore) AttachToPost(fileId, postId string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
if _, err := fs.GetMaster().Exec(
@@ -246,3 +270,22 @@ func (s SqlFileInfoStore) PermanentDeleteBatch(endTime int64, limit int64) store
}
})
}
+
+func (s SqlFileInfoStore) PermanentDeleteByUser(userId string) store.StoreChannel {
+ return store.Do(func(result *store.StoreResult) {
+ query := "DELETE from FileInfo WHERE CreatorId = :CreatorId"
+
+ sqlResult, err := s.GetMaster().Exec(query, map[string]interface{}{"CreatorId": userId})
+ if err != nil {
+ result.Err = model.NewAppError("SqlFileInfoStore.PermanentDeleteByUser", "store.sql_file_info.PermanentDeleteByUser.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
+ } else {
+ rowsAffected, err1 := sqlResult.RowsAffected()
+ if err1 != nil {
+ result.Err = model.NewAppError("SqlFileInfoStore.PermanentDeleteByUser", "store.sql_file_info.PermanentDeleteByUser.app_error", nil, ""+err.Error(), http.StatusInternalServerError)
+ result.Data = int64(0)
+ } else {
+ result.Data = rowsAffected
+ }
+ }
+ })
+}