mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-09 19:45:58 +08:00
errcode
This commit is contained in:
@@ -12,23 +12,19 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const cTag = "tag"
|
||||
const cSendLog = "send_log"
|
||||
const cWorkMoment = "work_moment"
|
||||
|
||||
type OfficeMgoDB struct {
|
||||
type OfficeMongoDriver struct {
|
||||
mgoDB *mongo.Database
|
||||
TagCollection *mongo.Collection
|
||||
TagSendLogCollection *mongo.Collection
|
||||
WorkMomentCollection *mongo.Collection
|
||||
}
|
||||
|
||||
func NewOfficeMgoDB(mgoDB *mongo.Database) *OfficeMgoDB {
|
||||
return &OfficeMgoDB{mgoDB: mgoDB, TagCollection: mgoDB.Collection(cTag), TagSendLogCollection: mgoDB.Collection(cSendLog), WorkMomentCollection: mgoDB.Collection(cSendLog)}
|
||||
func NewOfficeMongoDriver(mgoDB *mongo.Database) *OfficeMongoDriver {
|
||||
return &OfficeMongoDriver{mgoDB: mgoDB, TagCollection: mgoDB.Collection(table.CTag), TagSendLogCollection: mgoDB.Collection(table.CSendLog), WorkMomentCollection: mgoDB.Collection(table.CSendLog)}
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) GetUserTags(ctx context.Context, userID string) ([]table.Tag, error) {
|
||||
var tags []table.Tag
|
||||
func (db *OfficeMongoDriver) GetUserTags(ctx context.Context, userID string) ([]table.TagModel, error) {
|
||||
var tags []table.TagModel
|
||||
cursor, err := db.TagCollection.Find(ctx, bson.M{"user_id": userID})
|
||||
if err != nil {
|
||||
return tags, err
|
||||
@@ -39,9 +35,9 @@ func (db *OfficeMgoDB) GetUserTags(ctx context.Context, userID string) ([]table.
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) CreateTag(ctx context.Context, userID, tagName string, userList []string) error {
|
||||
func (db *OfficeMongoDriver) CreateTag(ctx context.Context, userID, tagName string, userList []string) error {
|
||||
tagID := generateTagID(tagName, userID)
|
||||
tag := table.Tag{
|
||||
tag := table.TagModel{
|
||||
UserID: userID,
|
||||
TagID: tagID,
|
||||
TagName: tagName,
|
||||
@@ -51,19 +47,19 @@ func (db *OfficeMgoDB) CreateTag(ctx context.Context, userID, tagName string, us
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) GetTagByID(ctx context.Context, userID, tagID string) (table.Tag, error) {
|
||||
var tag table.Tag
|
||||
func (db *OfficeMongoDriver) GetTagByID(ctx context.Context, userID, tagID string) (table.TagModel, error) {
|
||||
var tag table.TagModel
|
||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||
return tag, err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) DeleteTag(ctx context.Context, userID, tagID string) error {
|
||||
func (db *OfficeMongoDriver) DeleteTag(ctx context.Context, userID, tagID string) error {
|
||||
_, err := db.TagCollection.DeleteOne(ctx, bson.M{"user_id": userID, "tag_id": tagID})
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) SetTag(ctx context.Context, userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error {
|
||||
var tag table.Tag
|
||||
func (db *OfficeMongoDriver) SetTag(ctx context.Context, userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error {
|
||||
var tag table.TagModel
|
||||
if err := db.TagCollection.FindOne(ctx, bson.M{"tag_id": tagID, "user_id": userID}).Decode(&tag); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -95,19 +91,19 @@ func (db *OfficeMgoDB) SetTag(ctx context.Context, userID, tagID, newName string
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) GetUserIDListByTagID(ctx context.Context, userID, tagID string) ([]string, error) {
|
||||
var tag table.Tag
|
||||
func (db *OfficeMongoDriver) GetUserIDListByTagID(ctx context.Context, userID, tagID string) ([]string, error) {
|
||||
var tag table.TagModel
|
||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||
return tag.UserList, err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) SaveTagSendLog(ctx context.Context, tagSendLog *table.TagSendLog) error {
|
||||
func (db *OfficeMongoDriver) SaveTagSendLog(ctx context.Context, tagSendLog *table.TagSendLogModel) error {
|
||||
_, err := db.TagSendLogCollection.InsertOne(ctx, tagSendLog)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]table.TagSendLog, error) {
|
||||
var tagSendLogs []table.TagSendLog
|
||||
func (db *OfficeMongoDriver) GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]table.TagSendLogModel, error) {
|
||||
var tagSendLogs []table.TagSendLogModel
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"send_time": -1})
|
||||
cursor, err := db.TagSendLogCollection.Find(ctx, bson.M{"send_id": userID}, findOpts)
|
||||
if err != nil {
|
||||
@@ -117,7 +113,7 @@ func (db *OfficeMgoDB) GetTagSendLogs(ctx context.Context, userID string, showNu
|
||||
return tagSendLogs, err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) CreateOneWorkMoment(ctx context.Context, workMoment *table.WorkMoment) error {
|
||||
func (db *OfficeMongoDriver) CreateOneWorkMoment(ctx context.Context, workMoment *table.WorkMoment) error {
|
||||
workMomentID := generateWorkMomentID(workMoment.UserID)
|
||||
workMoment.WorkMomentID = workMomentID
|
||||
workMoment.CreateTime = int32(time.Now().Unix())
|
||||
@@ -125,12 +121,12 @@ func (db *OfficeMgoDB) CreateOneWorkMoment(ctx context.Context, workMoment *tabl
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) DeleteOneWorkMoment(ctx context.Context, workMomentID string) error {
|
||||
func (db *OfficeMongoDriver) DeleteOneWorkMoment(ctx context.Context, workMomentID string) error {
|
||||
_, err := db.WorkMomentCollection.DeleteOne(ctx, bson.M{"work_moment_id": workMomentID})
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) DeleteComment(ctx context.Context, workMomentID, contentID, opUserID string) error {
|
||||
func (db *OfficeMongoDriver) DeleteComment(ctx context.Context, workMomentID, contentID, opUserID string) error {
|
||||
_, err := db.WorkMomentCollection.UpdateOne(ctx, bson.D{{"work_moment_id", workMomentID},
|
||||
{"$or", bson.A{
|
||||
bson.D{{"user_id", opUserID}},
|
||||
@@ -140,13 +136,13 @@ func (db *OfficeMgoDB) DeleteComment(ctx context.Context, workMomentID, contentI
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) GetWorkMomentByID(ctx context.Context, workMomentID string) (*table.WorkMoment, error) {
|
||||
func (db *OfficeMongoDriver) GetWorkMomentByID(ctx context.Context, workMomentID string) (*table.WorkMoment, error) {
|
||||
workMoment := &table.WorkMoment{}
|
||||
err := db.WorkMomentCollection.FindOne(ctx, bson.M{"work_moment_id": workMomentID}).Decode(workMoment)
|
||||
return workMoment, err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*table.WorkMoment, bool, error) {
|
||||
func (db *OfficeMongoDriver) LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*table.WorkMoment, bool, error) {
|
||||
workMoment, err := db.GetWorkMomentByID(ctx, workMomentID)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
@@ -159,24 +155,24 @@ func (db *OfficeMgoDB) LikeOneWorkMoment(ctx context.Context, likeUserID, userNa
|
||||
}
|
||||
}
|
||||
if !isAlreadyLike {
|
||||
workMoment.LikeUserList = append(workMoment.LikeUserList, &table.CommonUser{UserID: likeUserID, UserName: userName})
|
||||
workMoment.LikeUserList = append(workMoment.LikeUserList, &table.CommonUserModel{UserID: likeUserID, UserName: userName})
|
||||
}
|
||||
_, err = db.WorkMomentCollection.UpdateOne(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$set": bson.M{"like_user_list": workMoment.LikeUserList}})
|
||||
return workMoment, !isAlreadyLike, err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) SetUserWorkMomentsLevel(ctx context.Context, userID string, level int32) error {
|
||||
func (db *OfficeMongoDriver) SetUserWorkMomentsLevel(ctx context.Context, userID string, level int32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) CommentOneWorkMoment(ctx context.Context, comment *table.Comment, workMomentID string) (table.WorkMoment, error) {
|
||||
func (db *OfficeMongoDriver) CommentOneWorkMoment(ctx context.Context, comment *table.Comment, workMomentID string) (table.WorkMoment, error) {
|
||||
comment.ContentID = generateWorkMomentCommentID(workMomentID)
|
||||
var workMoment table.WorkMoment
|
||||
err := db.WorkMomentCollection.FindOneAndUpdate(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$push": bson.M{"comments": comment}}).Decode(&workMoment)
|
||||
return workMoment, err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]table.WorkMoment, error) {
|
||||
func (db *OfficeMongoDriver) GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]table.WorkMoment, error) {
|
||||
var workMomentList []table.WorkMoment
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||
result, err := db.WorkMomentCollection.Find(ctx, bson.M{"user_id": userID}, findOpts)
|
||||
@@ -187,7 +183,7 @@ func (db *OfficeMgoDB) GetUserSelfWorkMoments(ctx context.Context, userID string
|
||||
return workMomentList, err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]table.WorkMoment, error) {
|
||||
func (db *OfficeMongoDriver) GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]table.WorkMoment, error) {
|
||||
var workMomentList []table.WorkMoment
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||
result, err := db.WorkMomentCollection.Find(ctx, bson.D{ // 等价条件: select * from
|
||||
@@ -205,8 +201,8 @@ func (db *OfficeMgoDB) GetUserWorkMoments(ctx context.Context, opUserID, userID
|
||||
return workMomentList, err
|
||||
}
|
||||
|
||||
func (db *OfficeMgoDB) GetUserFriendWorkMoments(ctx context.Context, showNumber, pageNumber int32, userID string, friendIDList []string) ([]WorkMoment, error) {
|
||||
var workMomentList []WorkMoment
|
||||
func (db *OfficeMongoDriver) GetUserFriendWorkMoments(ctx context.Context, showNumber, pageNumber int32, userID string, friendIDList []string) ([]table.WorkMoment, error) {
|
||||
var workMomentList []table.WorkMoment
|
||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||
var filter bson.D
|
||||
permissionFilter := bson.D{
|
||||
|
||||
Reference in New Issue
Block a user