-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
calculate the reward #16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Things to improve:
- Change pull request title
- Use proper commit messages.
- Rebase on current master branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move these lines up to the invitation code check block.
user,err:=queries.GetUserByID(nil,v.User.ID) | ||
if err==nil{ | ||
if user.InvCanReward == true{ | ||
user.Reward+=1 | ||
user.InvCanReward=false | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always format your code before submitting.
pkg/models/user.go
Outdated
@@ -29,6 +29,8 @@ type User struct { | |||
IsAdmin bool `gorm:"default:false"` | |||
IsCommunityAdmin bool `gorm:"default:false"` | |||
InvitationCode string | |||
Reward int `gorm:"default:0"` | |||
InvCanReward bool `gorm:"default:false"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid bad abbreviation. Also its purpose is not obvious by looking at the name.
|
||
|
||
//若该用户通过邀请码注册 | ||
if u.InvitationCode != ""{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u.InvitationCode
is the invitation code generated in the current function for the registered user, not someone else's invitation code that the new user used to register. Use the invitation_code
parameter of this function.
@WAAutoMaton take a look at this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 计算 reward 的代码不应该放在 GenerateResponse 方法内(功能和方法名字不符)。我的建议是写在
comments/Post
方法内。 - 对 User 示例修改后需要调用
Save
保存,否则修改不会写入数据库。 - 获得 reward 的应该是邀请该用户的用户,而不是发表评论的用户自身
- 整个修改过程应该用事务包起来,并且应该和发表评论作为同一个事务,建议是写在
comments/post.go:106
中 :
// 插入评论作为一个事务,若插入失败则回滚
err = db.Transaction(func(tx *gorm.DB) error {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分代码更适合放在 register_active 的逻辑中
此外这部分也应该使用事务包起来
Closing due to no activity. |
calculate the reward