Skip to content

Commit

Permalink
Dev为题集和案例集的题目和案例添加 点赞数据 (#251)
Browse files Browse the repository at this point in the history
* 为案例集添加点赞数据

* make check
  • Loading branch information
juniaoshaonian authored Aug 8, 2024
1 parent 6efd51f commit 56f0ac4
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 22 deletions.
44 changes: 43 additions & 1 deletion internal/cases/internal/integration/case_set_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ func (s *CaseSetTestSuite) TestCaseSetDetailByBiz() {
Content: "Go案例1",
ExamineResult: domain.ResultAdvanced.ToUint8(),
Utime: now,
Interactive: web.Interactive{
ViewCnt: 615,
LikeCnt: 616,
CollectCnt: 617,
Liked: false,
Collected: true,
},
},
{
Id: 615,
Expand All @@ -275,6 +282,13 @@ func (s *CaseSetTestSuite) TestCaseSetDetailByBiz() {
Title: "Go案例2",
Content: "Go案例2",
Utime: now,
Interactive: web.Interactive{
ViewCnt: 616,
LikeCnt: 617,
CollectCnt: 618,
Liked: true,
Collected: false,
},
},
{
Id: 616,
Expand All @@ -283,6 +297,13 @@ func (s *CaseSetTestSuite) TestCaseSetDetailByBiz() {
Title: "Go案例3",
Content: "Go案例3",
Utime: now,
Interactive: web.Interactive{
ViewCnt: 617,
LikeCnt: 618,
CollectCnt: 619,
Liked: false,
Collected: true,
},
},
},
},
Expand Down Expand Up @@ -467,6 +488,13 @@ func (s *CaseSetTestSuite) TestCaseSet_Detail() {
Content: "Go案例1",
ExamineResult: domain.ResultAdvanced.ToUint8(),
Utime: now,
Interactive: web.Interactive{
ViewCnt: 615,
LikeCnt: 616,
CollectCnt: 617,
Liked: false,
Collected: true,
},
},
{
Id: 615,
Expand All @@ -475,6 +503,13 @@ func (s *CaseSetTestSuite) TestCaseSet_Detail() {
Title: "Go案例2",
Content: "Go案例2",
Utime: now,
Interactive: web.Interactive{
ViewCnt: 616,
LikeCnt: 617,
CollectCnt: 618,
Liked: true,
Collected: false,
},
},
{
Id: 616,
Expand All @@ -483,6 +518,13 @@ func (s *CaseSetTestSuite) TestCaseSet_Detail() {
Title: "Go案例3",
Content: "Go案例3",
Utime: now,
Interactive: web.Interactive{
ViewCnt: 617,
LikeCnt: 618,
CollectCnt: 619,
Liked: false,
Collected: true,
},
},
},
},
Expand Down Expand Up @@ -510,7 +552,7 @@ func (s *CaseSetTestSuite) TestCaseSet_Detail() {
}
}

func (s *CaseSetTestSuite) TestCaseSet_ListAllQuestionSets() {
func (s *CaseSetTestSuite) TestCaseSet_ListAllCaseSets() {
// 插入一百条
total := 100
data := make([]dao.CaseSet, 0, total)
Expand Down
23 changes: 17 additions & 6 deletions internal/cases/internal/web/case_set_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,23 @@ func (h *CaseSetHandler) getDetail(
uid int64,
cs domain.CaseSet) (ginx.Result, error) {
var (
eg errgroup.Group
intr interactive.Interactive
resultMap map[int64]domain.ExamineCaseResult
eg errgroup.Group
intr interactive.Interactive
caseIntrMap map[int64]interactive.Interactive
resultMap map[int64]domain.ExamineCaseResult
)

eg.Go(func() error {
var err error
intr, err = h.intrSvc.Get(ctx, "caseSet", cs.ID, uid)
return err
})
eg.Go(func() error {
var err error
cids := cs.Cids()
caseIntrMap, err = h.intrSvc.GetByIds(ctx, "case", cids)
return err
})

eg.Go(func() error {
var err error
Expand All @@ -124,24 +131,28 @@ func (h *CaseSetHandler) getDetail(
}

return ginx.Result{
Data: h.toCaseSetVO(cs, intr, resultMap),
Data: h.toCaseSetVO(cs, intr, caseIntrMap, resultMap),
}, nil
}

func (h *CaseSetHandler) toCaseSetVO(
set domain.CaseSet,
intr interactive.Interactive,
caseIntrMap map[int64]interactive.Interactive,
results map[int64]domain.ExamineCaseResult) CaseSet {
cs := newCaseSet(set)
cs.Cases = h.toCaseVO(set.Cases, results)
cs.Cases = h.toCaseVO(set.Cases, results, caseIntrMap)
cs.Interactive = newInteractive(intr)
return cs
}

func (h *CaseSetHandler) toCaseVO(cases []domain.Case, results map[int64]domain.ExamineCaseResult) []Case {
func (h *CaseSetHandler) toCaseVO(cases []domain.Case,
results map[int64]domain.ExamineCaseResult,
caseIntrMap map[int64]interactive.Interactive) []Case {
return slice.Map(cases, func(idx int, src domain.Case) Case {
ca := newCase(src)
res := results[ca.Id]
ca.Interactive = newInteractive(caseIntrMap[ca.Id])
ca.ExamineResult = res.Result.ToUint8()
return ca
})
Expand Down
56 changes: 49 additions & 7 deletions internal/question/internal/integration/set_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ func (s *SetHandlerTestSuite) TestQuestionSetDetailByBiz() {
Content: "Go问题1",
ExamineResult: domain.ResultAdvanced.ToUint8(),
Utime: now,
Interactive: web.Interactive{
ViewCnt: 615,
LikeCnt: 616,
CollectCnt: 617,
Liked: false,
Collected: true,
},
},
{
Id: 615,
Expand All @@ -283,6 +290,13 @@ func (s *SetHandlerTestSuite) TestQuestionSetDetailByBiz() {
Title: "Go问题2",
Content: "Go问题2",
Utime: now,
Interactive: web.Interactive{
ViewCnt: 616,
LikeCnt: 617,
CollectCnt: 618,
Liked: true,
Collected: false,
},
},
{
Id: 616,
Expand All @@ -291,6 +305,13 @@ func (s *SetHandlerTestSuite) TestQuestionSetDetailByBiz() {
Title: "Go问题3",
Content: "Go问题3",
Utime: now,
Interactive: web.Interactive{
ViewCnt: 617,
LikeCnt: 618,
CollectCnt: 619,
Liked: false,
Collected: true,
},
},
},
Utime: now,
Expand Down Expand Up @@ -470,11 +491,18 @@ func (s *SetHandlerTestSuite) TestQuestionSet_Detail() {
},
Questions: []web.Question{
{
Id: 614,
Biz: "project",
BizId: 1,
Title: "Go问题1",
Content: "Go问题1",
Id: 614,
Biz: "project",
BizId: 1,
Title: "Go问题1",
Content: "Go问题1",
Interactive: web.Interactive{
ViewCnt: 615,
LikeCnt: 616,
CollectCnt: 617,
Liked: false,
Collected: true,
},
ExamineResult: domain.ResultAdvanced.ToUint8(),
Utime: now,
},
Expand All @@ -484,15 +512,29 @@ func (s *SetHandlerTestSuite) TestQuestionSet_Detail() {
BizId: 1,
Title: "Go问题2",
Content: "Go问题2",
Utime: now,
Interactive: web.Interactive{
ViewCnt: 616,
LikeCnt: 617,
CollectCnt: 618,
Liked: true,
Collected: false,
},
Utime: now,
},
{
Id: 616,
Biz: "project",
BizId: 1,
Title: "Go问题3",
Content: "Go问题3",
Utime: now,
Interactive: web.Interactive{
ViewCnt: 617,
LikeCnt: 618,
CollectCnt: 619,
Liked: false,
Collected: true,
},
Utime: now,
},
},
Utime: now,
Expand Down
29 changes: 21 additions & 8 deletions internal/question/internal/web/question_set_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ func (h *QuestionSetHandler) getDetail(
uid int64,
qs domain.QuestionSet) (ginx.Result, error) {
var (
eg errgroup.Group
intr interactive.Interactive
resultMap map[int64]domain.ExamineResult
eg errgroup.Group
intr interactive.Interactive
queIntrMap map[int64]interactive.Interactive
resultMap map[int64]domain.ExamineResult
)

eg.Go(func() error {
Expand All @@ -129,6 +130,12 @@ func (h *QuestionSetHandler) getDetail(
return err
})

eg.Go(func() error {
var eerr error
queIntrMap, eerr = h.intrSvc.GetByIds(ctx, "question", qs.Qids())
return eerr
})

eg.Go(func() error {
var err error
resultMap, err = h.examineSvc.GetResults(ctx, uid, qs.Qids())
Expand All @@ -141,23 +148,29 @@ func (h *QuestionSetHandler) getDetail(
}

return ginx.Result{
Data: h.toQuestionSetVO(qs, intr, resultMap),
Data: h.toQuestionSetVO(qs, intr, resultMap, queIntrMap),
}, nil
}

func (h *QuestionSetHandler) toQuestionSetVO(
set domain.QuestionSet,
intr interactive.Interactive,
results map[int64]domain.ExamineResult) QuestionSet {
results map[int64]domain.ExamineResult,
queIntrMap map[int64]interactive.Interactive,
) QuestionSet {
qs := newQuestionSet(set)
qs.Questions = h.toQuestionVO(set.Questions, results)
qs.Questions = h.toQuestionVO(set.Questions, results, queIntrMap)
qs.Interactive = newInteractive(intr)
return qs
}

func (h *QuestionSetHandler) toQuestionVO(questions []domain.Question, results map[int64]domain.ExamineResult) []Question {
func (h *QuestionSetHandler) toQuestionVO(
questions []domain.Question,
results map[int64]domain.ExamineResult,
queIntrMap map[int64]interactive.Interactive) []Question {
return slice.Map(questions, func(idx int, src domain.Question) Question {
que := newQuestion(src, interactive.Interactive{})
intr := queIntrMap[src.Id]
que := newQuestion(src, intr)
res := results[que.Id]
que.ExamineResult = res.Result.ToUint8()
return que
Expand Down

0 comments on commit 56f0ac4

Please sign in to comment.