mirror of https://gitee.com/answerdev/answer.git
fix update
This commit is contained in:
parent
7e9bcc3f0e
commit
60dfc74301
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue