mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-08 18:04:14 +01:00
Add an updated_at field to the API call for issue's comment edition
The update date is used as the comment update date, and is applied to the issue as an update date.
This commit is contained in:
parent
76c8faecdc
commit
cf787ad7fd
5 changed files with 29 additions and 4 deletions
|
@ -1106,9 +1106,12 @@ func UpdateComment(c *Comment, doer *user_model.User) error {
|
|||
return err
|
||||
}
|
||||
defer committer.Close()
|
||||
sess := db.GetEngine(ctx)
|
||||
|
||||
if _, err := sess.ID(c.ID).AllCols().Update(c); err != nil {
|
||||
sess := db.GetEngine(ctx).ID(c.ID).AllCols()
|
||||
if c.Issue.NoAutoTime {
|
||||
c.UpdatedUnix = c.Issue.UpdatedUnix
|
||||
sess = sess.NoAutoTime()
|
||||
}
|
||||
if _, err := sess.Update(c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.LoadIssue(ctx); err != nil {
|
||||
|
|
|
@ -36,6 +36,8 @@ type CreateIssueCommentOption struct {
|
|||
type EditIssueCommentOption struct {
|
||||
// required: true
|
||||
Body string `json:"body" binding:"Required"`
|
||||
// swagger:strfmt date-time
|
||||
Updated *time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TimelineComment represents a timeline comment (comment of any type) on a commit or issue
|
||||
|
|
|
@ -560,6 +560,17 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
|
|||
return
|
||||
}
|
||||
|
||||
err = comment.LoadIssue(ctx)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
|
||||
return
|
||||
}
|
||||
err = issue_service.SetIssueUpdateDate(ctx, comment.Issue, form.Updated, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusForbidden, "SetIssueUpdateDate", err)
|
||||
return
|
||||
}
|
||||
|
||||
oldContent := comment.Content
|
||||
comment.Content = form.Body
|
||||
if err := issue_service.UpdateComment(ctx, comment, ctx.Doer, oldContent); err != nil {
|
||||
|
|
|
@ -89,7 +89,11 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, doer *user_mode
|
|||
}
|
||||
|
||||
if needsContentHistory {
|
||||
err := issues_model.SaveIssueContentHistory(ctx, doer.ID, c.IssueID, c.ID, timeutil.TimeStampNow(), c.Content, false)
|
||||
historyDate := timeutil.TimeStampNow()
|
||||
if c.Issue.NoAutoTime {
|
||||
historyDate = c.Issue.UpdatedUnix
|
||||
}
|
||||
err := issues_model.SaveIssueContentHistory(ctx, doer.ID, c.IssueID, c.ID, historyDate, c.Content, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
5
templates/swagger/v1_json.tmpl
generated
5
templates/swagger/v1_json.tmpl
generated
|
@ -18075,6 +18075,11 @@
|
|||
"body": {
|
||||
"type": "string",
|
||||
"x-go-name": "Body"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string",
|
||||
"format": "date-time",
|
||||
"x-go-name": "Updated"
|
||||
}
|
||||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
|
|
Loading…
Reference in a new issue