Skip to content

Commit

Permalink
技能关联 CaseSet 前端对接完成
Browse files Browse the repository at this point in the history
  • Loading branch information
flycash committed Aug 18, 2024
1 parent 757ad12 commit 445a466
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 31 deletions.
13 changes: 13 additions & 0 deletions internal/skill/internal/domain/skill.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ func (s Skill) questionSetLen() int {
return len(s.Basic.QuestionSets) + len(s.Intermediate.QuestionSets) + len(s.Advanced.QuestionSets)
}

func (s Skill) CaseSets() []int64 {
res := make([]int64, 0, s.caseSetLen())
res = append(res, s.Basic.CaseSets...)
res = append(res, s.Intermediate.CaseSets...)
res = append(res, s.Advanced.CaseSets...)
return res
}

func (s Skill) caseSetLen() int {
return len(s.Basic.CaseSets) + len(s.Intermediate.CaseSets) + len(s.Advanced.CaseSets)
}

func (s Skill) caseLen() int {
return len(s.Basic.Cases) + len(s.Intermediate.Cases) + len(s.Advanced.Cases)
}
Expand All @@ -58,4 +70,5 @@ type SkillLevel struct {
Questions []int64
Cases []int64
QuestionSets []int64
CaseSets []int64
}
112 changes: 109 additions & 3 deletions internal/skill/internal/integration/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,31 @@ func (s *HandlerTestSuite) SetupSuite() {
}
}), nil
}).AnyTimes()

caseSetSvc := casemocks.NewMockCaseSetService(ctrl)
caseSetSvc.EXPECT().GetByIds(gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, ids []int64) ([]cases.CaseSet, error) {
return slice.Map(ids, func(idx int, src int64) cases.CaseSet {
return cases.CaseSet{
ID: src,
Title: fmt.Sprintf("这是案例集%d", src),
Cases: []cases.Case{
{
Id: src*10 + src,
Title: fmt.Sprintf("这是案例%d", src*10+src),
},
{
Id: src*11 + src,
Title: fmt.Sprintf("这是案例%d", src*11+src),
},
},
}
}), nil
}).AnyTimes()
s.ctrl = ctrl
s.producer = evemocks.NewMockSyncEventProducer(s.ctrl)
handler, err := startup.InitHandler(
&baguwen.Module{Svc: queSvc, SetSvc: queSetSvc, ExamSvc: examSvc},
&cases.Module{Svc: caseSvc},
&cases.Module{Svc: caseSvc, SetSvc: caseSetSvc},
s.producer,
)
require.NoError(s.T(), err)
Expand Down Expand Up @@ -405,6 +425,12 @@ func (s *HandlerTestSuite) TestSaveRefs() {
Rid: 67,
Rtype: "case",
},
{
Sid: 1,
Slid: 3,
Rid: 78,
Rtype: "caseSet",
},
}
for idx := range refs {
ref := &(refs[idx])
Expand Down Expand Up @@ -447,6 +473,9 @@ func (s *HandlerTestSuite) TestSaveRefs() {
Cases: []web.Case{
{Id: 67},
},
CaseSets: []web.CaseSet{
{ID: 78},
},
},
},
},
Expand Down Expand Up @@ -509,6 +538,12 @@ func (s *HandlerTestSuite) TestSaveRefs() {
Rid: 67,
Rtype: "case",
},
{
Sid: 1,
Slid: 3,
Rid: 78,
Rtype: "caseSet",
},
}
for idx := range refs {
ref := &(refs[idx])
Expand Down Expand Up @@ -546,6 +581,9 @@ func (s *HandlerTestSuite) TestSaveRefs() {
Cases: []web.Case{
{Id: 67},
},
CaseSets: []web.CaseSet{
{ID: 78},
},
},
},
},
Expand Down Expand Up @@ -636,6 +674,26 @@ func (s *HandlerTestSuite) TestDetailRef() {
Ctime: time.Now().UnixMilli(),
Utime: time.Now().UnixMilli(),
},

{
Id: 4,
Slid: 2,
Sid: 2,
Rtype: "questionSet",
Rid: 1,
Ctime: time.Now().UnixMilli(),
Utime: time.Now().UnixMilli(),
},

{
Id: 5,
Slid: 2,
Sid: 2,
Rtype: "caseSet",
Rid: 1,
Ctime: time.Now().UnixMilli(),
Utime: time.Now().UnixMilli(),
},
})
sid := web.Sid{
Sid: 2,
Expand Down Expand Up @@ -667,20 +725,33 @@ func (s *HandlerTestSuite) TestDetailRef() {
{Id: 1, Title: "这是案例1"},
},
QuestionSets: []web.QuestionSet{},
CaseSets: []web.CaseSet{},
},
Intermediate: web.SkillLevel{
Id: 2,
Desc: "mysql_desc_inter",
Questions: []web.Question{
{Id: 1, Title: "这是问题1"},
},
QuestionSets: []web.QuestionSet{},
Cases: []web.Case{},
QuestionSets: []web.QuestionSet{
{ID: 1, Title: "这是题集1", Questions: []web.Question{
{Id: 11, Title: "这是题目11"},
{Id: 12, Title: "这是题目12"},
}},
},
Cases: []web.Case{},
CaseSets: []web.CaseSet{
{ID: 1, Title: "这是案例集1", Cases: []web.Case{
{Id: 11, Title: "这是案例11"},
{Id: 12, Title: "这是案例12"},
}},
},
},
Advanced: web.SkillLevel{
Questions: []web.Question{},
Cases: []web.Case{},
QuestionSets: []web.QuestionSet{},
CaseSets: []web.CaseSet{},
},
}, resp)
}
Expand Down Expand Up @@ -732,16 +803,19 @@ func (s *HandlerTestSuite) TestList() {
Questions: []web.Question{},
Cases: []web.Case{},
QuestionSets: []web.QuestionSet{},
CaseSets: []web.CaseSet{},
},
Intermediate: web.SkillLevel{
Questions: []web.Question{},
Cases: []web.Case{},
QuestionSets: []web.QuestionSet{},
CaseSets: []web.CaseSet{},
},
Advanced: web.SkillLevel{
Questions: []web.Question{},
Cases: []web.Case{},
QuestionSets: []web.QuestionSet{},
CaseSets: []web.CaseSet{},
},
},
{
Expand All @@ -756,16 +830,19 @@ func (s *HandlerTestSuite) TestList() {
Questions: []web.Question{},
Cases: []web.Case{},
QuestionSets: []web.QuestionSet{},
CaseSets: []web.CaseSet{},
},
Intermediate: web.SkillLevel{
Questions: []web.Question{},
Cases: []web.Case{},
QuestionSets: []web.QuestionSet{},
CaseSets: []web.CaseSet{},
},
Advanced: web.SkillLevel{
Questions: []web.Question{},
Cases: []web.Case{},
QuestionSets: []web.QuestionSet{},
CaseSets: []web.CaseSet{},
},
},
},
Expand Down Expand Up @@ -795,16 +872,19 @@ func (s *HandlerTestSuite) TestList() {
Questions: []web.Question{},
Cases: []web.Case{},
QuestionSets: []web.QuestionSet{},
CaseSets: []web.CaseSet{},
},
Intermediate: web.SkillLevel{
Questions: []web.Question{},
Cases: []web.Case{},
QuestionSets: []web.QuestionSet{},
CaseSets: []web.CaseSet{},
},
Advanced: web.SkillLevel{
Questions: []web.Question{},
Cases: []web.Case{},
QuestionSets: []web.QuestionSet{},
CaseSets: []web.CaseSet{},
},
},
},
Expand Down Expand Up @@ -876,6 +956,15 @@ func (s *HandlerTestSuite) TestRefsByLevelIDs() {
Ctime: time.Now().UnixMilli(),
Utime: time.Now().UnixMilli(),
},
{
Id: 6,
Slid: 2,
Sid: 2,
Rtype: "caseSet",
Rid: 6,
Ctime: time.Now().UnixMilli(),
Utime: time.Now().UnixMilli(),
},
}).Error
require.NoError(s.T(), err)
testCases := []struct {
Expand Down Expand Up @@ -919,6 +1008,7 @@ func (s *HandlerTestSuite) TestRefsByLevelIDs() {
},
},
},
CaseSets: []web.CaseSet{},
},
{
Id: 2,
Expand All @@ -944,6 +1034,22 @@ func (s *HandlerTestSuite) TestRefsByLevelIDs() {
},
},
},
CaseSets: []web.CaseSet{
{
ID: 6,
Title: "这是案例集6",
Cases: []web.Case{
{
Id: 66,
Title: "这是案例66",
},
{
Id: 72,
Title: "这是案例72",
},
},
},
},
},
},
},
Expand Down
5 changes: 2 additions & 3 deletions internal/skill/internal/integration/startup/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ func initHandler(
p event.SyncEventProducer) (*web.Handler, error) {
wire.Build(
InitSkillDAO,
wire.FieldsOf(new(*baguwen.Module), "Svc"),
wire.FieldsOf(new(*cases.Module), "Svc"),
wire.FieldsOf(new(*baguwen.Module), "SetSvc"),
wire.FieldsOf(new(*baguwen.Module), "Svc", "SetSvc"),
wire.FieldsOf(new(*cases.Module), "Svc", "SetSvc"),
wire.FieldsOf(new(*baguwen.Module), "ExamSvc"),
cache.NewSkillCache,
repository.NewSkillRepo,
Expand Down
5 changes: 3 additions & 2 deletions internal/skill/internal/integration/startup/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/skill/internal/repository/dao/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const (
LevelAdvanced = "advanced"
RTypeQuestion = "question"
RTypeCase = "case"
RTypeCaseSet = "caseSet"
RTypeQuestionSet = "questionSet"
)

Expand Down
18 changes: 18 additions & 0 deletions internal/skill/internal/repository/skill.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func (s *skillRepo) LevelInfo(ctx context.Context, id int64) (domain.SkillLevel,
level.Cases = levels[0].Cases
level.Questions = levels[0].Questions
level.QuestionSets = levels[0].QuestionSets
level.CaseSets = levels[0].CaseSets
}
return level, nil
}
Expand All @@ -71,11 +72,13 @@ func (s *skillRepo) RefsByLevelIDs(ctx context.Context, ids []int64) ([]domain.S
ques, _ := m.Get(fmt.Sprintf(keyPattern, dao.RTypeQuestion, src))
cs, _ := m.Get(fmt.Sprintf(keyPattern, dao.RTypeCase, src))
questionSets, _ := m.Get(fmt.Sprintf(keyPattern, dao.RTypeQuestionSet, src))
caseSets, _ := m.Get(fmt.Sprintf(keyPattern, dao.RTypeCaseSet, src))
return domain.SkillLevel{
Id: src,
Questions: ques,
Cases: cs,
QuestionSets: questionSets,
CaseSets: caseSets,
}
}), nil
}
Expand Down Expand Up @@ -143,6 +146,17 @@ func (s *skillRepo) toRef(sid int64, level domain.SkillLevel) []dao.SkillRef {
})
}

for i := 0; i < len(level.CaseSets); i++ {
res = append(res, dao.SkillRef{
Rid: level.CaseSets[i],
Rtype: dao.RTypeCaseSet,
Sid: sid,
Slid: level.Id,
Ctime: now,
Utime: now,
})
}

return res
}

Expand Down Expand Up @@ -233,6 +247,7 @@ func (s *skillRepo) skillToInfoDomain(skill dao.Skill,
slQues, _ := reqsMap.Get(fmt.Sprintf("%d_%s", sl.Id, dao.RTypeQuestion))
slCases, _ := reqsMap.Get(fmt.Sprintf("%d_%s", sl.Id, dao.RTypeCase))
slQueSets, _ := reqsMap.Get(fmt.Sprintf("%d_%s", sl.Id, dao.RTypeQuestionSet))
slCaseSets, _ := reqsMap.Get(fmt.Sprintf("%d_%s", sl.Id, dao.RTypeCaseSet))
dsl.Questions = slice.Map(slQues, func(idx int, src dao.SkillRef) int64 {
return src.Rid
})
Expand All @@ -242,6 +257,9 @@ func (s *skillRepo) skillToInfoDomain(skill dao.Skill,
dsl.QuestionSets = slice.Map(slQueSets, func(idx int, src dao.SkillRef) int64 {
return src.Rid
})
dsl.CaseSets = slice.Map(slCaseSets, func(idx int, src dao.SkillRef) int64 {
return src.Rid
})
switch sl.Level {
case dao.LevelBasic:
res.Basic = dsl
Expand Down
Loading

0 comments on commit 445a466

Please sign in to comment.