Skip to content

Commit e755091

Browse files
committed
test fix and formatting
1 parent 610f8e8 commit e755091

File tree

7 files changed

+240
-247
lines changed

7 files changed

+240
-247
lines changed

sources/pages/contributors/bookmarks.go

Lines changed: 55 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import (
1414
"techpro.club/sources/users"
1515
)
1616

17-
type FinalBookmarksOutputStruct struct{
18-
Projects []common.FeedStruct `json:"projects"`
19-
UserNameImage common.UsernameImageStruct `json:"usernameImage"`
20-
MyReactions []primitive.ObjectID `json:"myReactions"`
21-
NotificaitonsCount int64 `json:"notificationsCount"`
22-
NotificationsList []common.MainNotificationStruct `json:"nofiticationsList"`
23-
PageDetails common.PageDetails `json:"pageDetails"`
17+
type FinalBookmarksOutputStruct struct {
18+
Projects []common.FeedStruct `json:"projects"`
19+
UserNameImage common.UsernameImageStruct `json:"usernameImage"`
20+
MyReactions []primitive.ObjectID `json:"myReactions"`
21+
NotificaitonsCount int64 `json:"notificationsCount"`
22+
NotificationsList []common.MainNotificationStruct `json:"nofiticationsList"`
23+
PageDetails common.PageDetails `json:"pageDetails"`
2424
}
2525

2626
// Fetched bookmarked projects
@@ -32,14 +32,14 @@ func FetchBookmarks(w http.ResponseWriter, r *http.Request) {
3232

3333
// Session check
3434
sessionOk, userID := users.ValidateDbSession(w, r)
35-
if(!sessionOk){
36-
35+
if !sessionOk {
36+
3737
// Delete cookies
3838
users.DeleteSessionCookie(w, r)
3939
users.DeleteUserCookie(w, r)
4040

4141
http.Redirect(w, r, "/", http.StatusSeeOther)
42-
}
42+
}
4343

4444
var userNameImage common.UsernameImageStruct
4545

@@ -49,16 +49,16 @@ func FetchBookmarks(w http.ResponseWriter, r *http.Request) {
4949
// Fetch notificaitons
5050
_, _, notificationsCount, notificationsList := pages.NotificationsCountAndTopFive(userID)
5151

52-
if(!status){
52+
if !status {
5353
log.Println(msg)
5454
} else {
55-
userNameImage = common.UsernameImageStruct{userName,image}
55+
userNameImage = common.UsernameImageStruct{Username: userName, Image: image}
5656
}
5757

5858
var functions = template.FuncMap{
59-
"objectIdToString" : pages.ObjectIDToString,
60-
"containsObjectId" : pages.ContainsObjectID,
61-
"timeElapsed" : pages.TimeElapsed,
59+
"objectIdToString": pages.ObjectIDToString,
60+
"containsObjectId": pages.ContainsObjectID,
61+
"timeElapsed": pages.TimeElapsed,
6262
}
6363

6464
// constants for check
@@ -70,39 +70,38 @@ func FetchBookmarks(w http.ResponseWriter, r *http.Request) {
7070
_, _, _, reactions := pages.FetchMyBookmarksAndReactions(userID)
7171

7272
baseUrl := common.GetBaseurl() + common.CONST_APP_PORT
73-
pageDetails := common.PageDetails{BaseUrl: baseUrl, Title : "Bookmarks"}
73+
pageDetails := common.PageDetails{BaseUrl: baseUrl, Title: "Bookmarks"}
7474

7575
output := FinalBookmarksOutputStruct{results, userNameImage, reactions, notificationsCount, notificationsList, pageDetails}
7676

7777
tmpl, err := template.New("").Funcs(functions).ParseFiles("templates/app/common/base.gohtml", "templates/app/common/contributormenu.gohtml", "templates/app/contributors/bookmarks.gohtml")
7878
if err != nil {
7979
fmt.Println(err.Error())
80-
}else {
81-
tmpl.ExecuteTemplate(w, "base", output)
80+
} else {
81+
tmpl.ExecuteTemplate(w, "base", output)
8282
}
8383
}
8484

8585
// Fetch all bookmarked projects
86-
func filterBookmarkedProjects(pageid int64, userID primitive.ObjectID)(status bool, msg string, results []primitive.ObjectID){
87-
86+
func filterBookmarkedProjects(pageid int64, userID primitive.ObjectID) (status bool, msg string, results []primitive.ObjectID) {
8887

8988
status = false
9089
msg = ""
9190
var out common.FetchUserProjectBookmarkStruct
9291

93-
status, msg, client := common.Mongoconnect()
92+
status, msg, client := common.Mongoconnect()
9493
defer client.Disconnect(context.TODO())
9594

9695
dbName := common.GetMoDb()
9796
fetchBookmarkedProjects := client.Database(dbName).Collection(common.CONST_MO_BOOKMARKS)
9897

9998
// Fetch all bookmarked projects against a user
100-
bookmarkedProjectsResults, err:= fetchBookmarkedProjects.Find(context.TODO(), bson.M{"userid": userID})
99+
bookmarkedProjectsResults, err := fetchBookmarkedProjects.Find(context.TODO(), bson.M{"userid": userID})
101100

102-
if err != nil{
101+
if err != nil {
103102
msg = err.Error()
104103
} else {
105-
for bookmarkedProjectsResults.Next(context.TODO()){
104+
for bookmarkedProjectsResults.Next(context.TODO()) {
106105
errDecode := bookmarkedProjectsResults.Decode(&out)
107106

108107
if errDecode != nil {
@@ -116,18 +115,16 @@ func filterBookmarkedProjects(pageid int64, userID primitive.ObjectID)(status bo
116115
return status, msg, results
117116
}
118117

119-
120118
// Filter all active projects from the database according to users bookmarks
121-
func fetchBookmarkedProjectsList(pageid int64, userID primitive.ObjectID)(status bool, msg string, results []common.FeedStruct){
122-
119+
func fetchBookmarkedProjectsList(pageid int64, userID primitive.ObjectID) (status bool, msg string, results []common.FeedStruct) {
123120

124121
status = false
125122
msg = ""
126123

127124
var finalConditions []bson.M
128125
resultsPerPage := int64(20)
129126

130-
status, msg, client := common.Mongoconnect()
127+
status, msg, client := common.Mongoconnect()
131128
defer client.Disconnect(context.TODO())
132129

133130
dbName := common.GetMoDb()
@@ -137,54 +134,53 @@ func fetchBookmarkedProjectsList(pageid int64, userID primitive.ObjectID)(status
137134

138135
status, errMsg, projectIds := filterBookmarkedProjects(pageid, userID)
139136

140-
if !status{
137+
if !status {
141138
msg = errMsg
142139
} else {
143-
if len(projectIds) <= 0{
140+
if len(projectIds) <= 0 {
144141
msg = "No projects found"
145-
results = []common.FeedStruct{}
142+
results = []common.FeedStruct{}
146143
} else {
147-
finalConditions = append(finalConditions, bson.M{"_id" : bson.M{"$in": projectIds}})
148-
149-
aggCondition := bson.M{"$match": bson.M{"$and" : finalConditions}}
150-
151-
144+
finalConditions = append(finalConditions, bson.M{"_id": bson.M{"$in": projectIds}})
145+
146+
aggCondition := bson.M{"$match": bson.M{"$and": finalConditions}}
147+
152148
// Filter joins
153149
aggLookup := bson.M{"$lookup": bson.M{
154-
"from": common.CONST_MO_USERS, // the collection name
155-
"localField": "userid", // the field on the child struct
156-
"foreignField": "_id", // the field on the parent struct
157-
"as": "userdetails", // the field to populate into
150+
"from": common.CONST_MO_USERS, // the collection name
151+
"localField": "userid", // the field on the child struct
152+
"foreignField": "_id", // the field on the parent struct
153+
"as": "userdetails", // the field to populate into
158154
}}
159-
155+
160156
// Set projections
161-
aggProjections := bson.M{"$project": bson.M{
162-
"_id": 1, "projectname" : 1,
163-
"projectdescription" : 1,
164-
"repolink": 1,
165-
"languages": 1,
166-
"otherlanguages": 1,
167-
"allied": 1,
168-
"company" : 1,
169-
"companyname": 1,
170-
"createddate": 1,
171-
"public" : 1,
172-
"reactionscount": 1,
173-
"userdetails" : bson.M{ "_id" : 1, "name": 1, "imagelink" :1},
157+
aggProjections := bson.M{"$project": bson.M{
158+
"_id": 1, "projectname": 1,
159+
"projectdescription": 1,
160+
"repolink": 1,
161+
"languages": 1,
162+
"otherlanguages": 1,
163+
"allied": 1,
164+
"company": 1,
165+
"companyname": 1,
166+
"createddate": 1,
167+
"public": 1,
168+
"reactionscount": 1,
169+
"userdetails": bson.M{"_id": 1, "name": 1, "imagelink": 1},
174170
}}
175-
171+
176172
aggSkip := bson.M{"$skip": (pageid * resultsPerPage)}
177173
aggLimit := bson.M{"$limit": resultsPerPage}
178-
174+
179175
projectsList, err := fetchProjects.Aggregate(context.TODO(), []bson.M{aggCondition, aggLookup, aggProjections, aggSkip, aggLimit})
180-
176+
181177
if err != nil {
182178
msg = err.Error()
183179
} else {
184-
for projectsList.Next(context.TODO()){
180+
for projectsList.Next(context.TODO()) {
185181
var elem common.FeedStruct
186182
errDecode := projectsList.Decode(&elem)
187-
183+
188184
if errDecode != nil {
189185
msg = errDecode.Error()
190186
} else {
@@ -199,4 +195,3 @@ func fetchBookmarkedProjectsList(pageid int64, userID primitive.ObjectID)(status
199195

200196
return status, msg, results
201197
}
202-

0 commit comments

Comments
 (0)