Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

准备 Release V0.3.0 #266

Merged
merged 12 commits into from
Aug 31, 2024
13 changes: 13 additions & 0 deletions .run/webook.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="webook" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="webook" />
<working_directory value="$PROJECT_DIR$" />
<go_parameters value="--tags=mock" />
<parameters value="--config=config/local.yaml" />
<kind value="PACKAGE" />
<package value="github.com/ecodeclub/webook" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/main.go" />
<method v="2" />
</configuration>
</component>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
- marketing - 12
- roadmap - 13 # 路线图
- bff - 14

- resume - 15
## 内部 APP ID
因为整个后台会被用于所有的 APP(我们会有很多 AI 应用)

Expand Down
5 changes: 4 additions & 1 deletion internal/ai/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ import (
"github.com/gotomicro/ego/core/econf"
)

func InitHandlerFacade(common []handler.Builder, zhipu *zhipu.Handler) *biz.FacadeHandler {
func InitHandlerFacade(common []handler.Builder,
zhipu *zhipu.Handler) *biz.FacadeHandler {
que := InitQuestionExamineHandler(common, zhipu)
c := InitCaseExamineHandler(common, zhipu)
return biz.NewHandler(map[string]handler.Handler{
que.Biz(): que,
c.Biz(): c,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ func (c *CompositionHandler) Handle(ctx context.Context, req domain.LLMRequest)
return c.root.Handle(ctx, req)
}

func (c *CompositionHandler) Name() string {
return c.name
}

func (c *CompositionHandler) Biz() string {
return c.name
}
Expand Down
37 changes: 35 additions & 2 deletions internal/bff/internal/integration/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ func (c *CollectionHandlerTestSuite) SetupSuite() {
return resMap, nil
}).AnyTimes()

caseExamSvc := casemocks.NewMockExamineService(ctrl)
caseExamSvc.EXPECT().GetResults(gomock.Any(), gomock.Any(), gomock.Any()).
DoAndReturn(func(ctx context.Context, uid int64, ids []int64) (map[int64]cases.ExamineResult, error) {
res := make(map[int64]cases.ExamineResult, len(ids))
for _, id := range ids {
res[id] = cases.ExamineResult{
Cid: id,
// 偶数不通过,基数通过
Result: cases.ExamineResultEnum(id % 2),
}
}
return res, nil
}).AnyTimes()

caseSvc := casemocks.NewMockService(ctrl)
caseSvc.EXPECT().GetPubByIDs(gomock.Any(), gomock.Any()).DoAndReturn(
func(ctx context.Context, ids []int64) ([]cases.Case, error) {
Expand All @@ -117,17 +131,27 @@ func (c *CollectionHandlerTestSuite) SetupSuite() {
}), nil
}).AnyTimes()
caseSetSvc := casemocks.NewMockCaseSetService(ctrl)
caseSetSvc.EXPECT().GetByIds(gomock.Any(), gomock.Any()).
caseSetSvc.EXPECT().GetByIdsWithCases(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 + 1,
Title: fmt.Sprintf("这是案例%d", src*10+1),
},
{
Id: src*10 + 2,
Title: fmt.Sprintf("这是案例%d", src*10+2),
},
},
}
}), nil
}).AnyTimes()
handler, _ := st.InitHandler(&interactive.Module{Svc: intrSvc},
&cases.Module{Svc: caseSvc, SetSvc: caseSetSvc},
&cases.Module{Svc: caseSvc, SetSvc: caseSetSvc, ExamineSvc: caseExamSvc},
&baguwen.Module{Svc: queSvc, SetSvc: queSetSvc, ExamSvc: examSvc})
econf.Set("server", map[string]any{"contextTimeout": "1s"})
server := egin.Load("server").Build()
Expand Down Expand Up @@ -208,6 +232,15 @@ func (c *CollectionHandlerTestSuite) Test_Handler() {
CaseSet: web.CaseSet{
ID: 5,
Title: "这是案例集5",
Cases: []web.Case{
{
ID: 51,
ExamineResult: 1,
},
{
ID: 52,
},
},
},
},
}, recorder.MustScan().Data)
Expand Down
2 changes: 1 addition & 1 deletion internal/bff/internal/integration/startup/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func InitHandler(intrModule *interactive.Module,
web.NewHandler,
wire.FieldsOf(new(*interactive.Module), "Svc"),
wire.FieldsOf(new(*baguwen.Module), "Svc", "SetSvc", "ExamSvc"),
wire.FieldsOf(new(*cases.Module), "Svc", "SetSvc"),
wire.FieldsOf(new(*cases.Module), "ExamineSvc", "Svc", "SetSvc"),
)
return new(web.Handler), nil
}
Expand Down
5 changes: 3 additions & 2 deletions internal/bff/internal/integration/startup/wire_gen.go

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

48 changes: 34 additions & 14 deletions internal/bff/internal/web/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ const (

func (h *Handler) CollectionRecords(ctx *ginx.Context, req CollectionInfoReq, sess session.Session) (ginx.Result, error) {
uid := sess.Claims().Uid
recordCtx := ctx.Request.Context()
// 获取收藏记录
records, err := h.intrSvc.CollectionInfo(ctx, uid, req.ID, req.Offset, req.Limit)
records, err := h.intrSvc.CollectionInfo(recordCtx, uid, req.ID, req.Offset, req.Limit)
if err != nil {
return systemErrorResult, err
}
var (
eg errgroup.Group
csm map[int64]cases.Case
cssmap map[int64]cases.CaseSet
qsm map[int64]baguwen.Question
qssmap map[int64]baguwen.QuestionSet
examResMap map[int64]baguwen.ExamResult
eg errgroup.Group
csm map[int64]cases.Case
cssmap map[int64]cases.CaseSet
qsm map[int64]baguwen.Question
qssmap map[int64]baguwen.QuestionSet
queExamResMap map[int64]baguwen.ExamResult
caseExamResMap map[int64]cases.ExamineResult
csets []cases.CaseSet
)
var qids, cids, csids, qsids, qid2s []int64
for _, record := range records {
Expand All @@ -48,22 +51,22 @@ func (h *Handler) CollectionRecords(ctx *ginx.Context, req CollectionInfoReq, se
qid2s = append(qid2s, qids...)

eg.Go(func() error {
cs, err1 := h.caseSvc.GetPubByIDs(ctx, cids)
cs, err1 := h.caseSvc.GetPubByIDs(recordCtx, cids)
csm = slice.ToMap(cs, func(element cases.Case) int64 {
return element.Id
})
return err1
})

eg.Go(func() error {
qs, err1 := h.queSvc.GetPubByIDs(ctx, qids)
qs, err1 := h.queSvc.GetPubByIDs(recordCtx, qids)
qsm = slice.ToMap(qs, func(element baguwen.Question) int64 {
return element.Id
})
return err1
})
eg.Go(func() error {
qsets, qerr := h.queSetSvc.GetByIDsWithQuestion(ctx, qsids)
qsets, qerr := h.queSetSvc.GetByIDsWithQuestion(recordCtx, qsids)
qssmap = slice.ToMap(qsets, func(element baguwen.QuestionSet) int64 {
return element.Id
})
Expand All @@ -74,7 +77,8 @@ func (h *Handler) CollectionRecords(ctx *ginx.Context, req CollectionInfoReq, se
})

eg.Go(func() error {
csets, cserr := h.caseSetSvc.GetByIds(ctx, csids)
var cserr error
csets, cserr = h.caseSetSvc.GetByIdsWithCases(recordCtx, csids)
cssmap = slice.ToMap(csets, func(element cases.CaseSet) int64 {
return element.ID
})
Expand All @@ -83,14 +87,30 @@ func (h *Handler) CollectionRecords(ctx *ginx.Context, req CollectionInfoReq, se
if err = eg.Wait(); err != nil {
return systemErrorResult, err
}

for _, cs := range csets {
cids = append(cids, cs.Cids()...)
}
eg = errgroup.Group{}
eg.Go(func() error {
var err1 error
queExamResMap, err1 = h.queExamSvc.GetResults(recordCtx, uid, qid2s)
return err1
})

eg.Go(func() error {
var err1 error
caseExamResMap, err1 = h.caseExamSvc.GetResults(recordCtx, uid, cids)
return err1
})
// 获取进度
examResMap, err = h.examSvc.GetResults(ctx, uid, qid2s)
if err != nil {

if err = eg.Wait(); err != nil {
return systemErrorResult, err
}

res := slice.Map(records, func(idx int, src interactive.CollectionRecord) CollectionRecord {
return newCollectionRecord(src, csm, cssmap, qsm, qssmap, examResMap)
return newCollectionRecord(src, csm, cssmap, qsm, qssmap, queExamResMap, caseExamResMap)
})
return ginx.Result{
Data: res,
Expand Down
29 changes: 16 additions & 13 deletions internal/bff/internal/web/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,32 @@ import (
)

type Handler struct {
intrSvc interactive.Service
caseSvc cases.Service
caseSetSvc cases.SetService
queSvc baguwen.Service
queSetSvc baguwen.QuestionSetService
examSvc baguwen.ExamService
intrSvc interactive.Service
caseSvc cases.Service
caseSetSvc cases.SetService
caseExamSvc cases.ExamineService
queSvc baguwen.Service
queSetSvc baguwen.QuestionSetService
queExamSvc baguwen.ExamService
}

func NewHandler(
intrSvc interactive.Service,
caseSvc cases.Service,
caseSetSvc cases.SetService,
caseExamineSvc cases.ExamineService,
queSvc baguwen.Service,
queSetSvc baguwen.QuestionSetService,
examSvc baguwen.ExamService,
queExamSvc baguwen.ExamService,
) *Handler {
return &Handler{
intrSvc: intrSvc,
caseSvc: caseSvc,
queSvc: queSvc,
queSetSvc: queSetSvc,
examSvc: examSvc,
caseSetSvc: caseSetSvc,
intrSvc: intrSvc,
caseSvc: caseSvc,
queSvc: queSvc,
queSetSvc: queSetSvc,
queExamSvc: queExamSvc,
caseSetSvc: caseSetSvc,
caseExamSvc: caseExamineSvc,
}
}

Expand Down
27 changes: 20 additions & 7 deletions internal/bff/internal/web/vo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package web

import (
"github.com/ecodeclub/ekit/slice"
"github.com/ecodeclub/webook/internal/cases"
"github.com/ecodeclub/webook/internal/interactive"
baguwen "github.com/ecodeclub/webook/internal/question"
Expand All @@ -21,8 +22,9 @@ type CollectionRecord struct {
}

type Case struct {
ID int64 `json:"id"`
Title string `json:"title"`
ID int64 `json:"id"`
Title string `json:"title"`
ExamineResult uint8 `json:"examineResult"`
}

type Question struct {
Expand All @@ -48,7 +50,8 @@ func newCollectionRecord(record interactive.CollectionRecord,
csm map[int64]cases.CaseSet,
qm map[int64]baguwen.Question,
qsm map[int64]baguwen.QuestionSet,
examMap map[int64]baguwen.ExamResult,
queExamMap map[int64]baguwen.ExamResult,
caseExamMap map[int64]cases.ExamineResult,
) CollectionRecord {
res := CollectionRecord{
Id: record.Id,
Expand All @@ -57,20 +60,30 @@ func newCollectionRecord(record interactive.CollectionRecord,
case CaseBiz:
res.Case = setCases(record, cm)
case QuestionBiz:
res.Question = setQuestion(record, qm, examMap)
res.Question = setQuestion(record, qm, queExamMap)
case QuestionSetBiz:
res.QuestionSet = setQuestionSet(record, qsm, examMap)
res.QuestionSet = setQuestionSet(record, qsm, queExamMap)
case CaseSetBiz:
res.CaseSet = setCaseSet(record, csm)
res.CaseSet = setCaseSet(record, csm, caseExamMap)
}
return res
}

func setCaseSet(ca interactive.CollectionRecord, csm map[int64]cases.CaseSet) CaseSet {
func setCaseSet(
ca interactive.CollectionRecord,
csm map[int64]cases.CaseSet,
caseExamMap map[int64]cases.ExamineResult,
) CaseSet {
cs := csm[ca.CaseSet]
return CaseSet{
ID: cs.ID,
Title: cs.Title,
Cases: slice.Map(cs.Cases, func(idx int, src cases.Case) Case {
return Case{
ID: src.Id,
ExamineResult: caseExamMap[src.Id].Result.ToUint8(),
}
}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/bff/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func InitModule(intrModule *interactive.Module,
web.NewHandler,
wire.FieldsOf(new(*baguwen.Module), "Svc", "SetSvc", "ExamSvc"),
wire.FieldsOf(new(*interactive.Module), "Svc"),
wire.FieldsOf(new(*cases.Module), "SetSvc", "Svc"),
wire.FieldsOf(new(*cases.Module), "SetSvc", "Svc", "ExamineSvc"),
wire.Struct(new(Module), "*"),
)
return new(Module), nil
Expand Down
5 changes: 3 additions & 2 deletions internal/bff/wire_gen.go

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

9 changes: 3 additions & 6 deletions internal/cases/internal/domain/examine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ func (r CaseResult) ToUint8() uint8 {
const (
// ResultFailed 完全没通过,或者完全没有考过,我们不需要区别这两种状态
ResultFailed CaseResult = iota
// ResultBasic 只回答出来了 15K 的部分
ResultBasic
// ResultIntermediate 回答了 25K 部分
ResultIntermediate
// ResultAdvanced 回答出来了 35K 部分
ResultAdvanced
// ResultPassed 回答通过
// 注意案例这边只有符合或者不符合,没有级别的评判
ResultPassed
)
Loading
Loading