You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/04/25 04:19:19 UTC

(incubator-answer) branch dev updated (4269a11c -> ba904330)

This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a change to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


    from 4269a11c fix: move slugcheck to correct line
     new b2cc3cc2 [wip] start issue 909
     new 2b053f1a enhancement: 909; update initial data
     new 4bed411d enhancement: 909; fix broken tests
     new ba904330 enhancement: 909; use camelCase, modify init data

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 internal/migrations/init.go                  | 138 +++++++++++++++++++++++++++
 internal/repo/repo_test/tag_rel_repo_test.go |  14 +--
 2 files changed, 145 insertions(+), 7 deletions(-)


(incubator-answer) 03/04: enhancement: 909; fix broken tests

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit 4bed411dba02d6888e807dba183997e610458b8b
Author: zahash <za...@gmail.com>
AuthorDate: Tue Apr 23 20:36:53 2024 +0530

    enhancement: 909; fix broken tests
---
 internal/repo/repo_test/tag_rel_repo_test.go | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/internal/repo/repo_test/tag_rel_repo_test.go b/internal/repo/repo_test/tag_rel_repo_test.go
index edcd45e9..f3696590 100644
--- a/internal/repo/repo_test/tag_rel_repo_test.go
+++ b/internal/repo/repo_test/tag_rel_repo_test.go
@@ -36,13 +36,13 @@ var (
 	tagRelOnce     sync.Once
 	testTagRelList = []*entity.TagRel{
 		{
-			ObjectID: "10010000000000001",
-			TagID:    "10030000000000001",
+			ObjectID: "10010000000000101",
+			TagID:    "10030000000000101",
 			Status:   entity.TagRelStatusAvailable,
 		},
 		{
-			ObjectID: "10010000000000002",
-			TagID:    "10030000000000002",
+			ObjectID: "10010000000000202",
+			TagID:    "10030000000000202",
 			Status:   entity.TagRelStatusAvailable,
 		},
 	}
@@ -68,7 +68,7 @@ func Test_tagListRepo_BatchGetObjectTagRelList(t *testing.T) {
 func Test_tagListRepo_CountTagRelByTagID(t *testing.T) {
 	tagRelOnce.Do(addTagRelList)
 	tagRelRepo := tag.NewTagRelRepo(testDataSource, unique.NewUniqueIDRepo(testDataSource))
-	count, err := tagRelRepo.CountTagRelByTagID(context.TODO(), "10030000000000001")
+	count, err := tagRelRepo.CountTagRelByTagID(context.TODO(), "10030000000000101")
 	assert.NoError(t, err)
 	assert.Equal(t, int64(1), count)
 }
@@ -96,7 +96,7 @@ func Test_tagListRepo_GetObjectTagRelWithoutStatus(t *testing.T) {
 	err = tagRelRepo.RemoveTagRelListByIDs(context.TODO(), ids)
 	assert.NoError(t, err)
 
-	count, err := tagRelRepo.CountTagRelByTagID(context.TODO(), "10030000000000001")
+	count, err := tagRelRepo.CountTagRelByTagID(context.TODO(), "10030000000000101")
 	assert.NoError(t, err)
 	assert.Equal(t, int64(0), count)
 
@@ -107,7 +107,7 @@ func Test_tagListRepo_GetObjectTagRelWithoutStatus(t *testing.T) {
 	err = tagRelRepo.EnableTagRelByIDs(context.TODO(), ids)
 	assert.NoError(t, err)
 
-	count, err = tagRelRepo.CountTagRelByTagID(context.TODO(), "10030000000000001")
+	count, err = tagRelRepo.CountTagRelByTagID(context.TODO(), "10030000000000101")
 	assert.NoError(t, err)
 	assert.Equal(t, int64(1), count)
 }


(incubator-answer) 01/04: [wip] start issue 909

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit b2cc3cc26ec61085e75c535743e4941dbeb77927
Author: zahash <za...@gmail.com>
AuthorDate: Tue Apr 23 12:34:14 2024 +0530

    [wip] start issue 909
---
 internal/migrations/init.go | 77 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 71 insertions(+), 6 deletions(-)

diff --git a/internal/migrations/init.go b/internal/migrations/init.go
index 8448bfc4..2dbd425b 100644
--- a/internal/migrations/init.go
+++ b/internal/migrations/init.go
@@ -23,7 +23,9 @@ import (
 	"context"
 	"encoding/json"
 	"fmt"
+
 	"github.com/apache/incubator-answer/internal/schema"
+	"github.com/apache/incubator-answer/internal/service/unique"
 	"github.com/segmentfault/pacman/log"
 
 	"github.com/apache/incubator-answer/internal/entity"
@@ -32,14 +34,15 @@ import (
 )
 
 type Mentor struct {
-	ctx      context.Context
-	engine   *xorm.Engine
-	userData *InitNeedUserInputData
-	err      error
-	Done     bool
+	ctx          context.Context
+	engine       *xorm.Engine
+	uniqueIDRepo unique.UniqueIDRepo
+	userData     *InitNeedUserInputData
+	err          error
+	Done         bool
 }
 
-func NewMentor(ctx context.Context, engine *xorm.Engine, data *InitNeedUserInputData) *Mentor {
+func NewMentor(ctx context.Context, engine *xorm.Engine, uniqueIDRepo unique.UniqueIDRepo, data *InitNeedUserInputData) *Mentor {
 	return &Mentor{ctx: ctx, engine: engine, userData: data}
 }
 
@@ -73,6 +76,7 @@ func (m *Mentor) InitDB() error {
 	m.do("init site info user config", m.initSiteInfoUsersConfig)
 	m.do("init site info privilege rank", m.initSiteInfoPrivilegeRank)
 	m.do("init site info write", m.initSiteInfoWrite)
+	m.do("init default content", m.initDefaultContent)
 	return m.err
 }
 
@@ -255,3 +259,64 @@ func (m *Mentor) initSiteInfoWrite() {
 		Status:  1,
 	})
 }
+
+func (m *Mentor) initDefaultContent() {
+	tag := entity.Tag{
+		SlugName:     "support",
+		DisplayName:  "support",
+		OriginalText: "For general support questions.",
+		UserID:       "1",
+	}
+
+	tag.ID, m.err = m.uniqueIDRepo.GenUniqueIDStr(m.ctx, tag.TableName())
+	if m.err != nil {
+		return
+	}
+
+	_, m.err = m.engine.Context(m.ctx).Insert(tag)
+	if m.err != nil {
+		return
+	}
+
+	var q1 = &entity.Question{
+		UserID:       "1",
+		Title:        "What is a tag?",
+		OriginalText: "When asking a question, we need to choose tags. What are tags and why should I use them?",
+	}
+
+	q1.ID, m.err = m.uniqueIDRepo.GenUniqueIDStr(m.ctx, q1.TableName())
+	if m.err != nil {
+		return
+	}
+
+	_, m.err = m.engine.Context(m.ctx).Insert(q1)
+	if m.err != nil {
+		return
+	}
+
+	var q1_tag_rel = &entity.TagRel{
+		ObjectID: q1.ID,
+		TagID:    tag.ID,
+	}
+
+	_, m.err = m.engine.Context(m.ctx).Insert(q1_tag_rel)
+	if m.err != nil {
+		return
+	}
+
+	var a1 = &entity.Answer{
+		QuestionID:   q1.ID,
+		UserID:       "1",
+		OriginalText: "Tags help to organize content and make searching easier. It helps your question get more attention from people interested in that tag. Tags also send notifications. If you are interested in some topic, follow that tag to get updates.",
+	}
+
+	a1.ID, m.err = m.uniqueIDRepo.GenUniqueIDStr(m.ctx, a1.TableName())
+	if m.err != nil {
+		return
+	}
+
+	_, m.err = m.engine.Context(m.ctx).Insert(a1)
+	if m.err != nil {
+		return
+	}
+}


(incubator-answer) 04/04: enhancement: 909; use camelCase, modify init data

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit ba904330126d42dc26bd25a96bdadc62ed75f0ba
Author: zahash <za...@gmail.com>
AuthorDate: Wed Apr 24 16:14:32 2024 +0530

    enhancement: 909; use camelCase, modify init data
---
 internal/migrations/init.go | 69 ++++++++++++++++++++-------------------------
 1 file changed, 31 insertions(+), 38 deletions(-)

diff --git a/internal/migrations/init.go b/internal/migrations/init.go
index 1ede0dad..0c50857a 100644
--- a/internal/migrations/init.go
+++ b/internal/migrations/init.go
@@ -265,38 +265,38 @@ func (m *Mentor) initDefaultContent() {
 	uniqueIDRepo := unique.NewUniqueIDRepo(&data.Data{DB: m.engine})
 	now := time.Now()
 
-	tag_id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Tag{}.TableName())
+	tagId, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Tag{}.TableName())
 	if err != nil {
 		m.err = err
 		return
 	}
 
-	q1_id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Question{}.TableName())
+	q1Id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Question{}.TableName())
 	if err != nil {
 		m.err = err
 		return
 	}
 
-	a1_id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Answer{}.TableName())
+	a1Id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Answer{}.TableName())
 	if err != nil {
 		m.err = err
 		return
 	}
 
-	q2_id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Question{}.TableName())
+	q2Id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Question{}.TableName())
 	if err != nil {
 		m.err = err
 		return
 	}
 
-	a2_id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Answer{}.TableName())
+	a2Id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Answer{}.TableName())
 	if err != nil {
 		m.err = err
 		return
 	}
 
 	tag := entity.Tag{
-		ID:            tag_id,
+		ID:            tagId,
 		SlugName:      "support",
 		DisplayName:   "support",
 		OriginalText:  "For general support questions.",
@@ -307,53 +307,47 @@ func (m *Mentor) initDefaultContent() {
 	}
 
 	q1 := &entity.Question{
-		ID:               q1_id,
-		CreatedAt:        now,
-		UserID:           "1",
-		Title:            "What is a tag?",
-		OriginalText:     "When asking a question, we need to choose tags. What are tags and why should I use them?",
-		ParsedText:       "<p>When asking a question, we need to choose tags. What are tags and why should I use them?</p>",
-		Pin:              entity.QuestionPin,
-		Show:             entity.QuestionShow,
-		Status:           entity.QuestionStatusAvailable,
-		AnswerCount:      1,
-		AcceptedAnswerID: a1_id,
+		ID:           q1Id,
+		CreatedAt:    now,
+		UserID:       "1",
+		Title:        "What is a tag?",
+		OriginalText: "When asking a question, we need to choose tags. What are tags and why should I use them?",
+		ParsedText:   "<p>When asking a question, we need to choose tags. What are tags and why should I use them?</p>",
+		Show:         entity.QuestionShow,
+		Status:       entity.QuestionStatusAvailable,
+		AnswerCount:  1,
 	}
 
 	a1 := &entity.Answer{
-		ID:           a1_id,
+		ID:           a1Id,
 		CreatedAt:    now,
-		QuestionID:   q1_id,
+		QuestionID:   q1Id,
 		UserID:       "1",
 		OriginalText: "Tags help to organize content and make searching easier. It helps your question get more attention from people interested in that tag. Tags also send notifications. If you are interested in some topic, follow that tag to get updates.",
 		ParsedText:   "<p>Tags help to organize content and make searching easier. It helps your question get more attention from people interested in that tag. Tags also send notifications. If you are interested in some topic, follow that tag to get updates.</p>",
 		Status:       entity.AnswerStatusAvailable,
-		Accepted:     schema.AnswerAcceptedEnable,
 	}
 
 	q2 := &entity.Question{
-		ID:               q2_id,
-		CreatedAt:        now,
-		UserID:           "1",
-		Title:            "What is reputation and how do I earn them?",
-		OriginalText:     "I see that each user has reputation points, What is it and how do I earn them?",
-		ParsedText:       "<p>I see that each user has reputation points, What is it and how do I earn them?</p>",
-		Pin:              entity.QuestionPin,
-		Show:             entity.QuestionShow,
-		Status:           entity.QuestionStatusAvailable,
-		AnswerCount:      1,
-		AcceptedAnswerID: a2_id,
+		ID:           q2Id,
+		CreatedAt:    now,
+		UserID:       "1",
+		Title:        "What is reputation and how do I earn them?",
+		OriginalText: "I see that each user has reputation points, What is it and how do I earn them?",
+		ParsedText:   "<p>I see that each user has reputation points, What is it and how do I earn them?</p>",
+		Show:         entity.QuestionShow,
+		Status:       entity.QuestionStatusAvailable,
+		AnswerCount:  1,
 	}
 
 	a2 := &entity.Answer{
-		ID:           a2_id,
+		ID:           a2Id,
 		CreatedAt:    now,
-		QuestionID:   q2_id,
+		QuestionID:   q2Id,
 		UserID:       "1",
 		OriginalText: "Your reputation points show how much the community values your knowledge. You earn points when someone find your question or answer helpful. You also get points when the person who asked the question thinks you did a good job and accepts your answer.",
 		ParsedText:   "<p>Your reputation points show how much the community values your knowledge. You earn points when someone find your question or answer helpful. You also get points when the person who asked the question thinks you did a good job and accepts your answer.</p>",
 		Status:       entity.AnswerStatusAvailable,
-		Accepted:     schema.AnswerAcceptedEnable,
 	}
 
 	_, m.err = m.engine.Context(m.ctx).Insert(tag)
@@ -372,10 +366,9 @@ func (m *Mentor) initDefaultContent() {
 	}
 
 	_, m.err = m.engine.Context(m.ctx).Insert(entity.TagRel{
-		CreatedAt: now,
-		ObjectID:  q1.ID,
-		TagID:     tag.ID,
-		Status:    entity.TagRelStatusAvailable,
+		ObjectID: q1.ID,
+		TagID:    tag.ID,
+		Status:   entity.TagRelStatusAvailable,
 	})
 	if m.err != nil {
 		return


(incubator-answer) 02/04: enhancement: 909; update initial data

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit 2b053f1a950ad98b9dc8432ebd8fc3c3402472f9
Author: zahash <za...@gmail.com>
AuthorDate: Tue Apr 23 20:19:26 2024 +0530

    enhancement: 909; update initial data
---
 internal/migrations/init.go | 142 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 111 insertions(+), 31 deletions(-)

diff --git a/internal/migrations/init.go b/internal/migrations/init.go
index 2dbd425b..1ede0dad 100644
--- a/internal/migrations/init.go
+++ b/internal/migrations/init.go
@@ -23,9 +23,11 @@ import (
 	"context"
 	"encoding/json"
 	"fmt"
+	"time"
 
+	"github.com/apache/incubator-answer/internal/base/data"
+	"github.com/apache/incubator-answer/internal/repo/unique"
 	"github.com/apache/incubator-answer/internal/schema"
-	"github.com/apache/incubator-answer/internal/service/unique"
 	"github.com/segmentfault/pacman/log"
 
 	"github.com/apache/incubator-answer/internal/entity"
@@ -34,15 +36,14 @@ import (
 )
 
 type Mentor struct {
-	ctx          context.Context
-	engine       *xorm.Engine
-	uniqueIDRepo unique.UniqueIDRepo
-	userData     *InitNeedUserInputData
-	err          error
-	Done         bool
+	ctx      context.Context
+	engine   *xorm.Engine
+	userData *InitNeedUserInputData
+	err      error
+	Done     bool
 }
 
-func NewMentor(ctx context.Context, engine *xorm.Engine, uniqueIDRepo unique.UniqueIDRepo, data *InitNeedUserInputData) *Mentor {
+func NewMentor(ctx context.Context, engine *xorm.Engine, data *InitNeedUserInputData) *Mentor {
 	return &Mentor{ctx: ctx, engine: engine, userData: data}
 }
 
@@ -261,30 +262,101 @@ func (m *Mentor) initSiteInfoWrite() {
 }
 
 func (m *Mentor) initDefaultContent() {
-	tag := entity.Tag{
-		SlugName:     "support",
-		DisplayName:  "support",
-		OriginalText: "For general support questions.",
-		UserID:       "1",
+	uniqueIDRepo := unique.NewUniqueIDRepo(&data.Data{DB: m.engine})
+	now := time.Now()
+
+	tag_id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Tag{}.TableName())
+	if err != nil {
+		m.err = err
+		return
 	}
 
-	tag.ID, m.err = m.uniqueIDRepo.GenUniqueIDStr(m.ctx, tag.TableName())
-	if m.err != nil {
+	q1_id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Question{}.TableName())
+	if err != nil {
+		m.err = err
 		return
 	}
 
-	_, m.err = m.engine.Context(m.ctx).Insert(tag)
-	if m.err != nil {
+	a1_id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Answer{}.TableName())
+	if err != nil {
+		m.err = err
+		return
+	}
+
+	q2_id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Question{}.TableName())
+	if err != nil {
+		m.err = err
 		return
 	}
 
-	var q1 = &entity.Question{
+	a2_id, err := uniqueIDRepo.GenUniqueIDStr(m.ctx, entity.Answer{}.TableName())
+	if err != nil {
+		m.err = err
+		return
+	}
+
+	tag := entity.Tag{
+		ID:            tag_id,
+		SlugName:      "support",
+		DisplayName:   "support",
+		OriginalText:  "For general support questions.",
+		ParsedText:    "<p>For general support questions.</p>",
+		UserID:        "1",
+		QuestionCount: 1,
+		Status:        entity.TagStatusAvailable,
+	}
+
+	q1 := &entity.Question{
+		ID:               q1_id,
+		CreatedAt:        now,
+		UserID:           "1",
+		Title:            "What is a tag?",
+		OriginalText:     "When asking a question, we need to choose tags. What are tags and why should I use them?",
+		ParsedText:       "<p>When asking a question, we need to choose tags. What are tags and why should I use them?</p>",
+		Pin:              entity.QuestionPin,
+		Show:             entity.QuestionShow,
+		Status:           entity.QuestionStatusAvailable,
+		AnswerCount:      1,
+		AcceptedAnswerID: a1_id,
+	}
+
+	a1 := &entity.Answer{
+		ID:           a1_id,
+		CreatedAt:    now,
+		QuestionID:   q1_id,
 		UserID:       "1",
-		Title:        "What is a tag?",
-		OriginalText: "When asking a question, we need to choose tags. What are tags and why should I use them?",
+		OriginalText: "Tags help to organize content and make searching easier. It helps your question get more attention from people interested in that tag. Tags also send notifications. If you are interested in some topic, follow that tag to get updates.",
+		ParsedText:   "<p>Tags help to organize content and make searching easier. It helps your question get more attention from people interested in that tag. Tags also send notifications. If you are interested in some topic, follow that tag to get updates.</p>",
+		Status:       entity.AnswerStatusAvailable,
+		Accepted:     schema.AnswerAcceptedEnable,
 	}
 
-	q1.ID, m.err = m.uniqueIDRepo.GenUniqueIDStr(m.ctx, q1.TableName())
+	q2 := &entity.Question{
+		ID:               q2_id,
+		CreatedAt:        now,
+		UserID:           "1",
+		Title:            "What is reputation and how do I earn them?",
+		OriginalText:     "I see that each user has reputation points, What is it and how do I earn them?",
+		ParsedText:       "<p>I see that each user has reputation points, What is it and how do I earn them?</p>",
+		Pin:              entity.QuestionPin,
+		Show:             entity.QuestionShow,
+		Status:           entity.QuestionStatusAvailable,
+		AnswerCount:      1,
+		AcceptedAnswerID: a2_id,
+	}
+
+	a2 := &entity.Answer{
+		ID:           a2_id,
+		CreatedAt:    now,
+		QuestionID:   q2_id,
+		UserID:       "1",
+		OriginalText: "Your reputation points show how much the community values your knowledge. You earn points when someone find your question or answer helpful. You also get points when the person who asked the question thinks you did a good job and accepts your answer.",
+		ParsedText:   "<p>Your reputation points show how much the community values your knowledge. You earn points when someone find your question or answer helpful. You also get points when the person who asked the question thinks you did a good job and accepts your answer.</p>",
+		Status:       entity.AnswerStatusAvailable,
+		Accepted:     schema.AnswerAcceptedEnable,
+	}
+
+	_, m.err = m.engine.Context(m.ctx).Insert(tag)
 	if m.err != nil {
 		return
 	}
@@ -294,28 +366,36 @@ func (m *Mentor) initDefaultContent() {
 		return
 	}
 
-	var q1_tag_rel = &entity.TagRel{
-		ObjectID: q1.ID,
-		TagID:    tag.ID,
+	_, m.err = m.engine.Context(m.ctx).Insert(a1)
+	if m.err != nil {
+		return
 	}
 
-	_, m.err = m.engine.Context(m.ctx).Insert(q1_tag_rel)
+	_, m.err = m.engine.Context(m.ctx).Insert(entity.TagRel{
+		CreatedAt: now,
+		ObjectID:  q1.ID,
+		TagID:     tag.ID,
+		Status:    entity.TagRelStatusAvailable,
+	})
 	if m.err != nil {
 		return
 	}
 
-	var a1 = &entity.Answer{
-		QuestionID:   q1.ID,
-		UserID:       "1",
-		OriginalText: "Tags help to organize content and make searching easier. It helps your question get more attention from people interested in that tag. Tags also send notifications. If you are interested in some topic, follow that tag to get updates.",
+	_, m.err = m.engine.Context(m.ctx).Insert(q2)
+	if m.err != nil {
+		return
 	}
 
-	a1.ID, m.err = m.uniqueIDRepo.GenUniqueIDStr(m.ctx, a1.TableName())
+	_, m.err = m.engine.Context(m.ctx).Insert(a2)
 	if m.err != nil {
 		return
 	}
 
-	_, m.err = m.engine.Context(m.ctx).Insert(a1)
+	_, m.err = m.engine.Context(m.ctx).Insert(entity.TagRel{
+		ObjectID: q2.ID,
+		TagID:    tag.ID,
+		Status:   entity.TagRelStatusAvailable,
+	})
 	if m.err != nil {
 		return
 	}