-
Notifications
You must be signed in to change notification settings - Fork 3
/
gf_bookmarks_db_mongo.go
132 lines (104 loc) · 3.67 KB
/
gf_bookmarks_db_mongo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
GloFlow application and media management/publishing platform
Copyright (C) 2021 Ivan Trajkovic
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package gf_bookmarks
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
"github.com/gloflow/gloflow/go/gf_core"
"github.com/gloflow/gloflow/go/gf_apps/gf_images_lib/gf_images_core"
)
//---------------------------------------------------
func dbMongoCreateBookmark(p_bookmark *GFbookmark,
p_ctx context.Context,
pRuntimeSys *gf_core.RuntimeSys) *gf_core.GFerror {
coll_name_str := "gf_bookmarks"
gfErr := gf_core.MongoInsert(p_bookmark,
coll_name_str,
map[string]interface{}{
"url_str": p_bookmark.Url_str,
"caller_err_msg_str": "failed to insert GF_bookmark into the DB",
},
p_ctx,
pRuntimeSys)
if gfErr != nil {
return gfErr
}
return nil
}
//---------------------------------------------------
func dbMongoUpdateBookmarkScreenshot(p_bookmark_id_str gf_core.GF_ID,
p_screenshot_image_id_str gf_images_core.GFimageID,
p_screenshot_image_thumbnail_url_str string,
p_ctx context.Context,
pRuntimeSys *gf_core.RuntimeSys) *gf_core.GFerror {
coll := pRuntimeSys.Mongo_db.Collection("gf_bookmarks")
_, err := coll.UpdateMany(p_ctx, bson.M{
"id_str": p_bookmark_id_str,
},
bson.M{
"$set": bson.M{
"screenshot_image_id_str": p_screenshot_image_id_str,
"Screenshot_image_thumbnail_url_str": p_screenshot_image_thumbnail_url_str,
},
},)
if err != nil {
gfErr := gf_core.MongoHandleError("failed to update DB ",
"mongodb_update_error",
map[string]interface{}{
"bookmark_id_str": p_bookmark_id_str,
"screenshot_image_id_str": p_screenshot_image_id_str,
"screenshot_image_thumbnail_url_str": p_screenshot_image_thumbnail_url_str,
},
err, "gf_tagger_lib", pRuntimeSys)
return gfErr
}
return nil
}
//---------------------------------------------------
func dbMongoGetAllBookmarks(p_user_id_str gf_core.GF_ID,
p_ctx context.Context,
pRuntimeSys *gf_core.RuntimeSys) ([]*GFbookmark, *gf_core.GFerror) {
find_opts := options.Find()
find_opts.SetSort(map[string]interface{}{"creation_unix_time_f": -1}) // descending - true - sort the latest items first
db_cursor, gfErr := gf_core.MongoFind(bson.M{
"user_id_str": p_user_id_str,
"deleted_bool": false,
},
find_opts,
map[string]interface{}{
"user_id_str": p_user_id_str,
"caller_err_msg_str": "failed to get bookmarks for a user from DB",
},
pRuntimeSys.Mongo_db.Collection("gf_bookmarks"),
p_ctx,
pRuntimeSys)
if gfErr != nil {
return nil, gfErr
}
var bookmarks_lst []*GFbookmark
err := db_cursor.All(p_ctx, &bookmarks_lst)
if err != nil {
gfErr := gf_core.MongoHandleError("failed to get DB results of query to get all Bookmarks",
"mongodb_cursor_all",
map[string]interface{}{
"user_id_str": p_user_id_str,
},
err, "gf_tagger_lib", pRuntimeSys)
return nil, gfErr
}
return bookmarks_lst, nil
}