Skip to content
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

Closed
wants to merge 4 commits into from
Closed

calculate the reward #16

wants to merge 4 commits into from

Conversation

kuangpenghao
Copy link

@kuangpenghao kuangpenghao commented Apr 8, 2024

calculate the reward

Copy link
Contributor

@Prince213 Prince213 left a 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.

Copy link
Contributor

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.

pkg/models/user.go Outdated Show resolved Hide resolved
pkg/models/comment.go Outdated Show resolved Hide resolved
Comment on lines 121 to 127
user,err:=queries.GetUserByID(nil,v.User.ID)
if err==nil{
if user.InvCanReward == true{
user.Reward+=1
user.InvCanReward=false
}
}
Copy link
Contributor

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.

@@ -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"`
Copy link
Contributor

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.

@AstatineAi AstatineAi self-requested a review April 9, 2024 11:56


//若该用户通过邀请码注册
if u.InvitationCode != ""{
Copy link
Contributor

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.

pkg/queries/user.go Outdated Show resolved Hide resolved
@Clarivy
Copy link
Contributor

Clarivy commented Apr 15, 2024

@WAAutoMaton take a look at this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 计算 reward 的代码不应该放在 GenerateResponse 方法内(功能和方法名字不符)。我的建议是写在 comments/Post 方法内。
  2. 对 User 示例修改后需要调用 Save 保存,否则修改不会写入数据库。
  3. 获得 reward 的应该是邀请该用户的用户,而不是发表评论的用户自身
  4. 整个修改过程应该用事务包起来,并且应该和发表评论作为同一个事务,建议是写在 comments/post.go:106 中 :
// 插入评论作为一个事务,若插入失败则回滚
err = db.Transaction(func(tx *gorm.DB) error {
	...
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分代码更适合放在 register_active 的逻辑中

此外这部分也应该使用事务包起来

@Prince213
Copy link
Contributor

Closing due to no activity.

@Prince213 Prince213 closed this Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants