Merge remote-tracking branch 'origin/tuoyun' into tuoyun

This commit is contained in:
skiffer-git
2022-04-15 20:37:26 +08:00
17 changed files with 2633 additions and 159 deletions
+9 -5
View File
@@ -46,11 +46,15 @@ func init() {
// example: mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize
uri = config.Config.Mongo.DBUri
} else {
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d",
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
config.Config.Mongo.DBMaxPoolSize)
if config.Config.Mongo.DBPassword != "" && config.Config.Mongo.DBUserName != "" {
uri = fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d", config.Config.Mongo.DBUserName, config.Config.Mongo.DBPassword, config.Config.Mongo.DBAddress[0],
config.Config.Mongo.DBDatabase, config.Config.Mongo.DBMaxPoolSize)
} else {
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d",
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
config.Config.Mongo.DBMaxPoolSize)
}
}
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
if err != nil {
fmt.Println(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri)
@@ -61,7 +65,7 @@ func init() {
panic(err1.Error())
}
}
fmt.Println("0", utils.GetSelfFuncName(), "mongo driver client init success")
fmt.Println("0", utils.GetSelfFuncName(), "mongo driver client init success: ", uri)
DB.mongoClient = mongoClient
+78
View File
@@ -563,10 +563,88 @@ func (d *DataBases) GetTagSendLogs(userID string, showNumber, pageNumber int32)
return tagSendLogs, nil
}
type WorkMoment struct {
WorkMomentID string `bson:"work_moment_id"`
UserID string `bson:"user_id"`
Content string `bson:"content"`
LikeUsers []*LikeUser `bson:"like_users"`
Comments []*Comment `bson:"comments"`
WhoCanSeeUserIDList []string `bson:"who_can_see_user_id_list"`
WhoCantSeeUserIDList []string `bson:"who_cant_see_user_id_list"`
IsPrivate bool
IsPublic bool
CreateTime int32
}
type LikeUser struct {
UserID string
UserName string
}
type Comment struct {
UserID string
UserName string
ReplyUserID string
ReplyUserName string
ContentID string
Content string
CreateTime int32
}
func (d *DataBases) CreateOneWorkMoment(workMoment *WorkMoment) error {
return nil
}
func (d *DataBases) DeleteOneWorkMoment(workMomentID string) error {
return nil
}
func (d *DataBases) GetWorkMomentByID(workMomentID string) (*WorkMoment, error) {
return nil, nil
}
func (d *DataBases) LikeOneWorkMoment(likeUserID, workMomentID string) error {
return nil
}
func (d *DataBases) SetUserWorkMomentsLevel(userID string, level int32) error {
return nil
}
func (d *DataBases) ClearUserWorkMomentsCommentsMsg(userID string) error {
return nil
}
type CommentMsg struct {
WorkMomentID string `bson:"workMoment"`
CommentContent string `bson:"content"`
Comment
}
func (d *DataBases) GetUserWorkMomentsCommentsMsg(userID string, showNumber, pageNumber int32) ([]CommentMsg, error) {
return nil, nil
}
func (d *DataBases) CommentOneWorkMoment(comment Comment, workMomentID string) error {
return nil
}
func (d *DataBases) GetUserWorkMoments(userID string, showNumber, pageNumber int32) ([]WorkMoment, error) {
return nil, nil
}
func (d *DataBases) GetUserFriendWorkMoments(friendIDList []string, showNumber, pageNumber int32) ([]WorkMoment, error) {
return nil, nil
}
func generateTagID(tagName, userID string) string {
return utils.Md5(tagName + userID + strconv.Itoa(rand.Int()) + time.Now().String())
}
func generateWorkMomentID(userID string) string {
return utils.Md5(userID + strconv.Itoa(rand.Int()) + time.Now().String())
}
func getCurrentTimestampByMill() int64 {
return time.Now().UnixNano() / 1e6
}
@@ -49,6 +49,19 @@ func GetFriendListByUserID(OwnerUserID string) ([]db.Friend, error) {
return friends, nil
}
func GetFriendIDListByUserID(OwnerUserID string) ([]string, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var friendIDList []string
err = dbConn.Table("friends").Select("friend_user_id").Where("owner_user_id=?", OwnerUserID).Find(&friendIDList).Error
if err != nil {
return nil, err
}
return friendIDList, nil
}
func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {