-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepository.go
91 lines (80 loc) · 2.72 KB
/
Repository.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
package main
import (
"time"
"go.mongodb.org/mongo-driver/bson"
)
func SetUserBaseInfoIfNotExists(userBaseInfo SingleUserModel) (SingleUserModel, bool) {
selectUserFilter := bson.M{"_id": userBaseInfo.ID}
userInfo := GetSingleUser(selectUserFilter)
if userInfo.ID == "" {
userInfo.ID = userBaseInfo.ID
userInfo.FirstName = userBaseInfo.FirstName
userInfo.LastName = userBaseInfo.LastName
userInfo.Role = USER_ROLE
userInfo.UserName = userBaseInfo.UserName
userInfo.Bio = userBaseInfo.Bio
userInfo.Status = USER_STATUS_FREE
userInfo.PhoneNumber = USER_PHONENUMBER_STATE_NOT_SET
userInfo.Created_at = time.Now()
CreateSingleUser(userInfo)
return userInfo, true
}
return userInfo, false
}
func GetSingleUserInfo(userBaseInfo SingleUserModel) SingleUserModel {
selectUserFilter := bson.M{"_id": userBaseInfo.ID}
userInfo := GetSingleUser(selectUserFilter)
return userInfo
}
func GetSingleUserRole(userBaseInfo SingleUserModel) string {
selectUserFilter := bson.M{"_id": userBaseInfo.ID}
userInfo := GetSingleUser(selectUserFilter)
return userInfo.Role
}
func GetSingleUserUserName(userBaseInfo SingleUserModel) string {
selectUserFilter := bson.M{"_id": userBaseInfo.ID}
userInfo := GetSingleUser(selectUserFilter)
return userInfo.UserName
}
func GetSingleUserPhoneNumber(userBaseInfo SingleUserModel) string {
selectUserFilter := bson.M{"_id": userBaseInfo.ID}
userInfo := GetSingleUser(selectUserFilter)
return userInfo.PhoneNumber
}
func GetAllUsersInfo() []SingleUserModel {
selectUserFilter := bson.M{"role": USER_ROLE}
usersList := GetFilteredUsers(selectUserFilter)
return usersList
}
func GetAllAdminsInfo() []SingleUserModel {
selectUserFilter := bson.M{"role": ADMIN_ROLE}
adminsList := GetFilteredUsers(selectUserFilter)
return adminsList
}
func UpdateSingleUserInfo(userBaseInfo SingleUserModel) bool {
selectUserFilter := bson.M{"_id": userBaseInfo.ID}
hasErr := SetUpdateSingleUser(selectUserFilter, userBaseInfo)
return hasErr
}
func CreateNewProjectBase(projectBaseInfo SingleProjectModel) (SingleProjectModel, bool) {
projectBaseInfo.Status = PROJECT_STATUS_PENDING
projectBaseInfo.ID = idGenarator()
projectBaseInfo.ChannelPostId = -1
projectBaseInfo.Created_at = time.Now()
hasErr := CreateSingleProject(projectBaseInfo)
return projectBaseInfo, hasErr
}
func GetSingleProjectInfo(projectBaseInfo SingleProjectModel) SingleProjectModel {
selectProjectFilter := bson.M{
"_id": projectBaseInfo.ID,
}
selectProject := GetSingleProject(selectProjectFilter)
return selectProject
}
func UpdateSingleProjectInfo(projectBaseInfo SingleProjectModel) bool {
selectProjectFilter := bson.M{
"_id": projectBaseInfo.ID,
}
hasErr := SetUpdateSingleProject(selectProjectFilter, projectBaseInfo)
return hasErr
}