diff --git a/internal/migrations/v5.go b/internal/migrations/v5.go index 58dd61c9..c4e3a4cc 100644 --- a/internal/migrations/v5.go +++ b/internal/migrations/v5.go @@ -25,6 +25,9 @@ func addThemeAndPrivateMode(x *xorm.Engine) error { } if !exist { _, err = x.InsertOne(siteInfo) + if err != nil { + return fmt.Errorf("insert site info failed: %w", err) + } } themeConfig := `{"theme":"default","theme_config":{"default":{"navbar_style":"colored","primary_color":"#0033ff"}}}` diff --git a/internal/repo/repo_test/email_repo_test.go b/internal/repo/repo_test/email_repo_test.go index 2da70944..4d3c6da5 100644 --- a/internal/repo/repo_test/email_repo_test.go +++ b/internal/repo/repo_test/email_repo_test.go @@ -3,6 +3,7 @@ package repo_test import ( "context" "testing" + "time" "github.com/answerdev/answer/internal/repo/export" "github.com/stretchr/testify/assert" @@ -11,7 +12,7 @@ import ( func Test_emailRepo_VerifyCode(t *testing.T) { emailRepo := export.NewEmailRepo(testDataSource) code, content := "1111", "test" - err := emailRepo.SetCode(context.TODO(), code, content) + err := emailRepo.SetCode(context.TODO(), code, content, time.Minute) assert.NoError(t, err) verifyContent, err := emailRepo.VerifyCode(context.TODO(), code) diff --git a/internal/service/comment/comment_service.go b/internal/service/comment/comment_service.go index c3133224..92d9a194 100644 --- a/internal/service/comment/comment_service.go +++ b/internal/service/comment/comment_service.go @@ -343,21 +343,6 @@ func (cs *CommentService) convertCommentEntity2Resp(ctx context.Context, req *sc return commentResp, nil } -func (cs *CommentService) checkCommentWhetherOwner(ctx context.Context, userID, commentID string) error { - // check comment if user self - comment, exist, err := cs.commentCommonRepo.GetComment(ctx, commentID) - if err != nil { - return err - } - if !exist { - return errors.BadRequest(reason.CommentNotFound) - } - if comment.UserID != userID { - return errors.BadRequest(reason.CommentEditWithoutPermission) - } - return nil -} - func (cs *CommentService) checkIsVote(ctx context.Context, userID, commentID string) (isVote bool) { status := cs.voteCommon.GetVoteStatus(ctx, commentID, userID) return len(status) > 0 diff --git a/internal/service/search_parser/search_parser.go b/internal/service/search_parser/search_parser.go index 2a938d32..ec56679f 100644 --- a/internal/service/search_parser/search_parser.go +++ b/internal/service/search_parser/search_parser.go @@ -27,19 +27,19 @@ func NewSearchParser(tagCommonService *tag_common.TagCommonService, userCommon * // but if match two type, it will return false func (sp *SearchParser) ParseStructure(dto *schema.SearchDTO) ( searchType string, -// search all + // search all userID string, votes int, -// search questions + // search questions notAccepted bool, isQuestion bool, views, answers int, -// search answers + // search answers accepted bool, questionID string, isAnswer bool, -// common fields + // common fields tags, words []string, ) { @@ -202,7 +202,7 @@ func (sp *SearchParser) parseUserID(query *string, currentUserID string) (userID re := regexp.MustCompile(exprUserID) res := re.FindStringSubmatch(q) - if strings.Index(q, exprMe) != -1 { + if strings.Contains(q, exprMe) { userID = currentUserID q = strings.ReplaceAll(q, exprMe, "") } else if len(res) == 2 { diff --git a/pkg/htmltext/htmltext.go b/pkg/htmltext/htmltext.go index 7f8e6e07..cb23cfb1 100644 --- a/pkg/htmltext/htmltext.go +++ b/pkg/htmltext/htmltext.go @@ -1,7 +1,7 @@ package htmltext import ( - "io/ioutil" + "io" "net/http" "net/url" "regexp" @@ -89,7 +89,7 @@ func GetPicByUrl(Url string) string { return "" } defer res.Body.Close() - pix, err := ioutil.ReadAll(res.Body) + pix, err := io.ReadAll(res.Body) if err != nil { return "" }