From b643ef136f3fd63fdca490b28bd3e9be577ae734 Mon Sep 17 00:00:00 2001 From: ZhenlyChen Date: Thu, 27 Jun 2019 12:30:59 +0800 Subject: [PATCH] Fix a bug Collection --- app/models/user.go | 31 ------------------------------- app/services/task.go | 4 ---- app/services/user.go | 1 - 3 files changed, 36 deletions(-) diff --git a/app/models/user.go b/app/models/user.go index 8cbdf5c..84a42bb 100644 --- a/app/models/user.go +++ b/app/models/user.go @@ -1,7 +1,6 @@ package models import ( - "errors" "github.com/TimeForCoin/Server/app/utils" "reflect" "time" @@ -83,7 +82,6 @@ type UserDataSchema struct { Type UserType // 用户类型 AttendanceDate int64 `bson:"attendance_date"` // 签到时间戳 - CollectTasks []primitive.ObjectID `bson:"collect_tasks"` // 收藏的任务 SearchHistory []string `bson:"search_history"` // 搜索历史(仅保留最近的 20 条) // 冗余数据 PublishCount int64 `bson:"publish_count"` // 发布任务数 @@ -123,7 +121,6 @@ func makeNewUserSchema() UserSchema { RegisterTime: time.Now().Unix(), Data: UserDataSchema{ Type: UserTypeNormal, - CollectTasks: []primitive.ObjectID{}, SearchHistory: []string{}, Money: 100, Value: 1000, @@ -354,34 +351,6 @@ func (m *UserModel) CheckCertificationEmail(email string) bool { return false } -// AddCollectTask 添加任务收藏 -func (m *UserModel) AddCollectTask(id, taskID primitive.ObjectID) error { - ctx, over := GetCtx() - defer over() - res, err := m.Collection.UpdateOne(ctx, bson.M{"_id": id}, - bson.M{"$addToSet": bson.M{"data.collect_tasks": taskID}}) - if err != nil { - return err - } else if res.ModifiedCount == 0 { - return errors.New("exist") - } - return nil -} - -// RemoveCollectTask 移除任务收藏 -func (m *UserModel) RemoveCollectTask(id, taskID primitive.ObjectID) error { - ctx, over := GetCtx() - defer over() - res, err := m.Collection.UpdateOne(ctx, bson.M{"_id": id}, - bson.M{"$pull": bson.M{"data.collect_tasks": taskID}}) - if err != nil { - return err - } else if res.ModifiedCount == 0 { - return ErrNotExist - } - return nil -} - // AddSearchHistory 添加搜索历史 func (m *UserModel) AddSearchHistory(id primitive.ObjectID, key string) error { ctx, over := GetCtx() diff --git a/app/services/task.go b/app/services/task.go index 92b6c07..d5ffbef 100644 --- a/app/services/task.go +++ b/app/services/task.go @@ -451,14 +451,10 @@ func (s *taskService) ChangeCollection(taskID, userID primitive.ObjectID, collec err = s.setModel.AddToSet(userID, taskID, models.SetOfCollectTask) utils.AssertErr(err, "exist_collect", 403) err = s.model.InsertCount(taskID, models.CollectCount, 1) - utils.AssertErr(err, "", 500) - err = s.userModel.AddCollectTask(userID, taskID) } else { err = s.setModel.RemoveFromSet(userID, taskID, models.SetOfCollectTask) utils.AssertErr(err, "faked_collect", 403) err = s.model.InsertCount(taskID, models.CollectCount, -1) - utils.AssertErr(err, "", 500) - err = s.userModel.RemoveCollectTask(userID, taskID) } utils.AssertErr(err, "", 500) err = s.cache.WillUpdate(userID, models.KindOfLikeTask) diff --git a/app/services/user.go b/app/services/user.go index 0cbec36..fc6697d 100644 --- a/app/services/user.go +++ b/app/services/user.go @@ -660,7 +660,6 @@ func (s *userService) makeUserRes(user models.UserSchema, all bool) UserDetail { Info: user.Info, Data: &UserDataRes{ UserDataSchema: &user.Data, - CollectCount: int64(len(user.Data.CollectTasks)), }, Certification: &UserCertification{ Type: user.Certification.Identity,