diff --git a/internal/entity/answer_entity.go b/internal/entity/answer_entity.go index 33e04d32..549e7f6b 100644 --- a/internal/entity/answer_entity.go +++ b/internal/entity/answer_entity.go @@ -20,7 +20,7 @@ var CmsAnswerSearchStatus = map[string]int{ type Answer struct { ID string `xorm:"not null pk autoincr BIGINT(20) id"` CreatedAt time.Time `xorm:"created not null default CURRENT_TIMESTAMP TIMESTAMP created_at"` - UpdatedAt time.Time `xorm:"not null default CURRENT_TIMESTAMP TIMESTAMP updated_at"` + UpdatedAt time.Time `xorm:"updated_at TIMESTAMP"` QuestionID string `xorm:"not null default 0 BIGINT(20) question_id"` UserID string `xorm:"not null default 0 BIGINT(20) INDEX user_id"` OriginalText string `xorm:"not null MEDIUMTEXT original_text"` diff --git a/internal/service/answer_common/answer.go b/internal/service/answer_common/answer.go index 196d6628..56cfbb99 100644 --- a/internal/service/answer_common/answer.go +++ b/internal/service/answer_common/answer.go @@ -68,6 +68,9 @@ func (as *AnswerCommon) ShowFormat(ctx context.Context, data *entity.Answer) *sc info.VoteCount = data.VoteCount info.CreateTime = data.CreatedAt.Unix() info.UpdateTime = data.UpdatedAt.Unix() + if data.UpdatedAt.Unix() < 1 { + info.UpdateTime = 0 + } info.UserID = data.UserID return &info } @@ -80,6 +83,9 @@ func (as *AnswerCommon) AdminShowFormat(ctx context.Context, data *entity.Answer info.VoteCount = data.VoteCount info.CreateTime = data.CreatedAt.Unix() info.UpdateTime = data.UpdatedAt.Unix() + if data.UpdatedAt.Unix() < 1 { + info.UpdateTime = 0 + } info.UserID = data.UserID info.Description = htmltext.FetchExcerpt(data.ParsedText, "...", 240) return &info diff --git a/internal/service/answer_service.go b/internal/service/answer_service.go index f2975ce4..693c996b 100644 --- a/internal/service/answer_service.go +++ b/internal/service/answer_service.go @@ -134,7 +134,6 @@ func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq) ( if !exist { return "", errors.BadRequest(reason.QuestionNotFound) } - now := time.Now() insertData := new(entity.Answer) insertData.UserID = req.UserID insertData.OriginalText = req.Content @@ -143,7 +142,7 @@ func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq) ( insertData.QuestionID = req.QuestionID insertData.RevisionID = "0" insertData.Status = entity.AnswerStatusAvailable - insertData.UpdatedAt = now + //insertData.UpdatedAt = now if err = as.answerRepo.AddAnswer(ctx, insertData); err != nil { return "", err }