Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix update

aichy60dfc743014a
diff --git a/internal/repo/answer_repo.go b/internal/repo/answer_repo.go
index 9045a8fb..b0ef5154 100644
--- a/internal/repo/answer_repo.go
+++ b/internal/repo/answer_repo.go
@@ -2,6 +2,7 @@ package repo
import (
"context"
+ "time"
"github.com/segmentfault/answer/internal/base/constant"
"github.com/segmentfault/answer/internal/base/data"
@@ -77,7 +78,9 @@ func (ar *answerRepo) UpdateAnswer(ctx context.Context, answer *entity.Answer, C
}
func (ar *answerRepo) UpdateAnswerStatus(ctx context.Context, answer *entity.Answer) (err error) {
- _, err = ar.data.DB.Where("id =?", answer.ID).Cols("status").Update(answer)
+ now := time.Now()
+ answer.UpdatedAt = now
+ _, err = ar.data.DB.Where("id =?", answer.ID).Cols("status", "updated_at").Update(answer)
if err != nil {
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
@@ -216,7 +219,7 @@ func (ar *answerRepo) CmsSearchList(ctx context.Context, search *entity.CmsAnswe
offset := search.Page * search.PageSize
session := ar.data.DB.Where("")
session = session.And("status =?", search.Status)
- session = session.OrderBy("created_at desc")
+ session = session.OrderBy("updated_at desc")
session = session.Limit(search.PageSize, offset)
count, err = session.FindAndCount(&rows)
if err != nil {
diff --git a/internal/repo/question_repo.go b/internal/repo/question_repo.go
index 3f503f58..986a34e5 100644
--- a/internal/repo/question_repo.go
+++ b/internal/repo/question_repo.go
@@ -2,6 +2,7 @@ package repo
import (
"context"
+ "time"
"github.com/segmentfault/answer/internal/base/constant"
"github.com/segmentfault/answer/internal/base/data"
@@ -92,7 +93,9 @@ func (qr *questionRepo) UpdateCollectionCount(ctx context.Context, questionId st
}
func (qr *questionRepo) UpdateQuestionStatus(ctx context.Context, question *entity.Question) (err error) {
- _, err = qr.data.DB.Where("id =?", question.ID).Cols("status").Update(question)
+ now := time.Now()
+ question.UpdatedAt = now
+ _, err = qr.data.DB.Where("id =?", question.ID).Cols("status", "updated_at").Update(question)
if err != nil {
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
@@ -238,7 +241,7 @@ func (qr *questionRepo) CmsSearchList(ctx context.Context, search *schema.CmsQue
offset := search.Page * search.PageSize
session := qr.data.DB.Table("question")
session = session.And("status =?", search.Status)
- session = session.OrderBy("created_at desc")
+ session = session.OrderBy("updated_at desc")
session = session.Limit(search.PageSize, offset)
count, err = session.FindAndCount(&rows)
if err != nil {