about summary refs log tree commit diff
path: root/src/rest-api/handler/db.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/rest-api/handler/db.go')
-rw-r--r--src/rest-api/handler/db.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/rest-api/handler/db.go b/src/rest-api/handler/db.go
index fc32f5c..65ca8b2 100644
--- a/src/rest-api/handler/db.go
+++ b/src/rest-api/handler/db.go
@@ -11,6 +11,7 @@ import (
 type DB interface {
 	GetLatestFileByPath(ctx context.Context, path string, user_id string) (*lib.File, error)
 	GetUserIDByAPIKey(ctx context.Context, apiKey string) (string, error)
+	GetAndDeleteRestoredFiles(ctx context.Context, user_id string) (*[]lib.File, error)
 }
 
 type DBImpl struct {
@@ -39,6 +40,27 @@ func (db DBImpl) GetLatestFileByPath(ctx context.Context, path string, user_id s
 	return &file, nil
 }
 
+func (db DBImpl) GetAndDeleteRestoredFiles(ctx context.Context, user_id string) (*[]lib.File, error) {
+	var files []lib.File
+	err := db.db.SelectContext(ctx, &files, `
+		SELECT * FROM public.restored_file
+		WHERE user_id = $1
+	`, user_id)
+	if err != nil {
+		return nil, err
+	}
+
+	_, err = db.db.ExecContext(ctx, `
+		DELETE FROM public.restored_file
+		WHERE user_id = $1
+	`, user_id)
+	if err != nil {
+		return nil, err
+	}
+
+	return &files, nil
+}
+
 // TODO: Add test
 func (db DBImpl) GetUserIDByAPIKey(ctx context.Context, apiKey string) (string, error) {
 	if len(apiKey) != 44 {