Skip to content

Commit

Permalink
Fix a bug
Browse files Browse the repository at this point in the history
Collection
  • Loading branch information
ZhenlyChen committed Jun 27, 2019
1 parent 32c8175 commit b643ef1
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 36 deletions.
31 changes: 0 additions & 31 deletions app/models/user.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package models

import (
"errors"
"github.com/TimeForCoin/Server/app/utils"
"reflect"
"time"
Expand Down Expand Up @@ -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"` // 发布任务数
Expand Down Expand Up @@ -123,7 +121,6 @@ func makeNewUserSchema() UserSchema {
RegisterTime: time.Now().Unix(),
Data: UserDataSchema{
Type: UserTypeNormal,
CollectTasks: []primitive.ObjectID{},
SearchHistory: []string{},
Money: 100,
Value: 1000,
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 0 additions & 4 deletions app/services/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion app/services/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b643ef1

Please sign in to comment.