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

feat: add comment support for problems #93

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

yeyn19
Copy link
Contributor

@yeyn19 yeyn19 commented Jul 3, 2021

I have read the CLA Document and I hereby sign the CLA

@github-actions
Copy link

github-actions bot commented Jul 3, 2021

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@codecov
Copy link

codecov bot commented Jul 3, 2021

Codecov Report

Patch coverage: 63.12% and project coverage change: -0.52 ⚠️

Comparison is base (5c5c951) 72.51% compared to head (79c5f7e) 72.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
- Coverage   72.51%   72.00%   -0.52%     
==========================================
  Files          56       58       +2     
  Lines        5851     6190     +339     
==========================================
+ Hits         4243     4457     +214     
- Misses       1355     1468     +113     
- Partials      253      265      +12     
Impacted Files Coverage Δ
database/models/comment.go 0.00% <0.00%> (ø)
app/controller/comment.go 54.65% <54.65%> (ø)
database/migrate.go 90.11% <100.00%> (+0.62%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

database/migrate.go Outdated Show resolved Hide resolved
app/routes.go Outdated Show resolved Hide resolved
app/routes.go Outdated Show resolved Hide resolved
app/response/comment.go Outdated Show resolved Hide resolved
app/response/comment.go Outdated Show resolved Hide resolved
app/request/comment.go Outdated Show resolved Hide resolved
app/request/comment.go Outdated Show resolved Hide resolved
app/request/comment.go Show resolved Hide resolved
app/request/comment.go Outdated Show resolved Hide resolved
app/controller/comment.go Show resolved Hide resolved
app/controller/comment.go Outdated Show resolved Hide resolved
app/controller/comment.go Outdated Show resolved Hide resolved
app/controller/comment.go Outdated Show resolved Hide resolved
@@ -128,24 +156,24 @@ func AddReaction(c echo.Context) error {
return err
}
user, ok := c.Get("user").(models.User)
targetID,_ := strconv.Atoi(c.Param("id"))
if !ok {
Copy link
Member

Choose a reason for hiding this comment

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

这个要紧挨着158行
以及,可以直接user := c.Get("user").(models.User)。这么写会在不ok的时候panic。

加上ok是想要不panic的时候用的。

if !ok {
panic("could not convert my user into type models.User")
}

targetID := req.TargetID
Copy link
Member

Choose a reason for hiding this comment

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

??????

Copy link
Member

Choose a reason for hiding this comment

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

这是在干啥

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个其实是传入的comment_id,就是 /api/comment/:id/reaction里的id,我在request里传了份一样的

Copy link
Member

Choose a reason for hiding this comment

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

@yeyn19 我的意思是,为啥不直接用req.TargetID,非得复制一个变量

Copy link
Contributor Author

Choose a reason for hiding this comment

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

嗷嗷这个其实是之前没有bind时候的逻辑…后来没改…

if !ok {
panic("could not convert my user into type models.User")
}

targetID := req.TargetID
Copy link
Member

Choose a reason for hiding this comment

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

这是在干啥

//operator is not zero
for _, v := range maps[typeId] {
if uint(v) == uint(user.ID) {
return c.JSON(http.StatusBadRequest, response.ErrorResp("can't action twice!", nil))
Copy link
Member

Choose a reason for hiding this comment

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

是否理解成,第二次reaction意思就是撤回?
现在有单独的撤回api吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

现在是AddReactionRequest中的IfAddReaction代表是增加还是删除,在前端有根据用户是否已经对某条评论点赞做了parse,理论上不会出现“重复点赞”或者“没点赞直接删除”的情况…

Copy link
Member

Choose a reason for hiding this comment

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

感觉IfAddReaction的名字不是很好🤔 有啥更简短的名字吗

Copy link
Contributor Author

Choose a reason for hiding this comment

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

先这个吧。感觉要不就得叫 AddOrDeleteAction string 之类的反而挺麻烦

Copy link
Member

Choose a reason for hiding this comment

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

@yeyn19
是否分成两个api,POST /comment/:id/reaction新建,DELETE /comment/:id/reaction 删除?

app/controller/comment.go Outdated Show resolved Hide resolved
app/controller/comment.go Outdated Show resolved Hide resolved
app/controller/comment.go Outdated Show resolved Hide resolved
newReaction := models.Reaction{
TargetType: "comment",
}
utils.PanicIfDBError(base.DB.Save(&newReaction), "could not save reaction")
Copy link
Member

Choose a reason for hiding this comment

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

能不能在发reaction的时候再创建reaction表里的数据?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

在save comment时好像不指定对应reaction就会报错violates foreign key constraint,不知道是不是comment.reaction有polymorphic的原因…

if comment.ID == 0 {
return nil
}
if err := tx.Where("father_id = ?", comment.ID).Delete(&Comment{}).Error; err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

为什么传入一个空comment指针?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个贼奇怪…好像不这么写就有bug,这个特判调试的时候进入comment.id==0的情况然后卡死了…猜测是不是查father_id时,如果查不到就会进入id=0的AfterDelete函数

leoleoasd
leoleoasd previously approved these changes Sep 12, 2021
@yeyn19
Copy link
Contributor Author

yeyn19 commented Sep 12, 2021

I have read the CLA Document and I hereby sign the CLA

leoleoasd added a commit to EduOJ/cla that referenced this pull request Sep 12, 2021
@leoleoasd leoleoasd changed the title fix bugs of urls, etc… Comment Sep 28, 2021
@leoleoasd leoleoasd changed the title Comment feat: add comment support for problems Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants