From 79e15a0292bb44a3d1f0420b9030d1a0cfcc15d5 Mon Sep 17 00:00:00 2001 From: zwl <1633720889@qq.com> Date: Sun, 5 Jan 2025 10:25:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E5=88=97=E8=A1=A8=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=80=BB=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integration/case_set_handler_test.go | 2 + .../internal/integration/handler_test.go | 2 + .../cases/internal/repository/case_set.go | 6 +- internal/cases/internal/repository/cases.go | 5 + .../internal/repository/dao/cases_set.go | 10 ++ internal/cases/internal/service/case_set.go | 21 ++- internal/cases/internal/service/cases.go | 22 ++- .../cases/internal/web/case_set_handler.go | 3 +- internal/cases/internal/web/handler.go | 3 +- internal/cases/mocks/case_set.mock.go | 152 +++++++++--------- internal/cases/mocks/cases.mock.go | 110 ++++++------- .../internal/integration/project_test.go | 116 ++++++------- .../project/internal/repository/dao/dao.go | 10 ++ .../project/internal/repository/repository.go | 5 + internal/project/internal/service/service.go | 23 ++- internal/project/internal/web/handler.go | 11 +- .../internal/integration/handler_test.go | 104 ++++++------ .../internal/integration/set_handler_test.go | 3 + internal/question/internal/job/knowledge.go | 2 +- .../internal/repository/dao/question.go | 9 +- .../internal/repository/dao/question_set.go | 11 +- .../question/internal/repository/question.go | 5 + .../internal/repository/question_set.go | 4 + .../question/internal/service/question.go | 21 ++- .../question/internal/service/question_set.go | 22 ++- internal/question/internal/web/handler.go | 14 +- .../internal/web/question_set_handler.go | 3 +- internal/question/mocks/question.mock.go | 124 +++++++------- internal/question/mocks/quetion_set.mock.go | 15 +- 29 files changed, 504 insertions(+), 334 deletions(-) diff --git a/internal/cases/internal/integration/case_set_handler_test.go b/internal/cases/internal/integration/case_set_handler_test.go index bb0ae1d1..bf09cd36 100644 --- a/internal/cases/internal/integration/case_set_handler_test.go +++ b/internal/cases/internal/integration/case_set_handler_test.go @@ -594,6 +594,7 @@ func (s *CaseSetTestSuite) TestCaseSet_ListAllCaseSets() { wantCode: 200, wantResp: test.Result[web.CaseSetList]{ Data: web.CaseSetList{ + Total: 100, CaseSets: []web.CaseSet{ { Id: 100, @@ -636,6 +637,7 @@ func (s *CaseSetTestSuite) TestCaseSet_ListAllCaseSets() { wantCode: 200, wantResp: test.Result[web.CaseSetList]{ Data: web.CaseSetList{ + Total: 100, CaseSets: []web.CaseSet{ { Id: 1, diff --git a/internal/cases/internal/integration/handler_test.go b/internal/cases/internal/integration/handler_test.go index 69c1c0d4..74b31ee8 100644 --- a/internal/cases/internal/integration/handler_test.go +++ b/internal/cases/internal/integration/handler_test.go @@ -151,6 +151,7 @@ func (s *HandlerTestSuite) TestPubList() { wantCode: 200, wantResp: test.Result[web.CasesList]{ Data: web.CasesList{ + Total: 100, Cases: []web.Case{ { Id: 100, @@ -191,6 +192,7 @@ func (s *HandlerTestSuite) TestPubList() { wantCode: 200, wantResp: test.Result[web.CasesList]{ Data: web.CasesList{ + Total: 100, Cases: []web.Case{ { Id: 1, diff --git a/internal/cases/internal/repository/case_set.go b/internal/cases/internal/repository/case_set.go index 0722ecea..ba7cc37c 100644 --- a/internal/cases/internal/repository/case_set.go +++ b/internal/cases/internal/repository/case_set.go @@ -19,7 +19,7 @@ type CaseSetRepository interface { Total(ctx context.Context) (int64, error) List(ctx context.Context, offset int, limit int) ([]domain.CaseSet, error) UpdateNonZero(ctx context.Context, set domain.CaseSet) error - + CountByBiz(ctx context.Context, biz string) (int64, error) GetByIDs(ctx context.Context, ids []int64) ([]domain.CaseSet, error) // GetByIDsWithCases 会同步把关联的 Case 也找出来,但是只是找 id,具体内容没有找 GetByIDsWithCases(ctx context.Context, ids []int64) ([]domain.CaseSet, error) @@ -32,6 +32,10 @@ type caseSetRepo struct { dao dao.CaseSetDAO } +func (c *caseSetRepo) CountByBiz(ctx context.Context, biz string) (int64, error) { + return c.dao.CountByBiz(ctx, biz) +} + func NewCaseSetRepo(caseSetDao dao.CaseSetDAO) CaseSetRepository { return &caseSetRepo{ dao: caseSetDao, diff --git a/internal/cases/internal/repository/cases.go b/internal/cases/internal/repository/cases.go index 846e76c3..dcf2697b 100644 --- a/internal/cases/internal/repository/cases.go +++ b/internal/cases/internal/repository/cases.go @@ -18,6 +18,7 @@ type CaseRepo interface { PubList(ctx context.Context, offset int, limit int) ([]domain.Case, error) GetPubByID(ctx context.Context, caseId int64) (domain.Case, error) GetPubByIDs(ctx context.Context, ids []int64) ([]domain.Case, error) + PubCount(ctx context.Context) (int64, error) // Sync 保存到制作库,而后同步到线上库 Sync(ctx context.Context, ca domain.Case) (int64, error) // 管理端接口 @@ -35,6 +36,10 @@ type caseRepo struct { caseDao dao.CaseDAO } +func (c *caseRepo) PubCount(ctx context.Context) (int64, error) { + return c.caseDao.PublishCaseCount(ctx) +} + func (c *caseRepo) Ids(ctx context.Context) ([]int64, error) { return c.caseDao.Ids(ctx) } diff --git a/internal/cases/internal/repository/dao/cases_set.go b/internal/cases/internal/repository/dao/cases_set.go index 6b02bcbc..4cfec4b4 100644 --- a/internal/cases/internal/repository/dao/cases_set.go +++ b/internal/cases/internal/repository/dao/cases_set.go @@ -16,6 +16,7 @@ type CaseSetDAO interface { UpdateCasesByID(ctx context.Context, id int64, cids []int64) error Count(ctx context.Context) (int64, error) + CountByBiz(ctx context.Context, biz string) (int64, error) List(ctx context.Context, offset, limit int) ([]CaseSet, error) UpdateNonZero(ctx context.Context, set CaseSet) error GetByIDs(ctx context.Context, ids []int64) ([]CaseSet, error) @@ -29,6 +30,15 @@ type caseSetDAO struct { db *egorm.Component } +func (c *caseSetDAO) CountByBiz(ctx context.Context, biz string) (int64, error) { + var count int64 + db := c.db.WithContext(ctx) + err := db. + Model(&CaseSet{}). + Where("biz = ?", biz).Count(&count).Error + return count, err +} + func (c *caseSetDAO) GetRefCasesByIDs(ctx context.Context, ids []int64) ([]CaseSetCase, error) { var res []CaseSetCase err := c.db.WithContext(ctx).Where("cs_id IN ?", ids).Find(&res).Error diff --git a/internal/cases/internal/service/case_set.go b/internal/cases/internal/service/case_set.go index 83da5e4f..064ab923 100644 --- a/internal/cases/internal/service/case_set.go +++ b/internal/cases/internal/service/case_set.go @@ -23,7 +23,7 @@ type CaseSetService interface { GetByIdsWithCases(ctx context.Context, ids []int64) ([]domain.CaseSet, error) ListByBiz(ctx context.Context, offset, limit int, biz string) ([]domain.CaseSet, error) - ListDefault(ctx context.Context, offset, limit int) ([]domain.CaseSet, error) + ListDefault(ctx context.Context, offset, limit int) (int64, []domain.CaseSet, error) GetByBiz(ctx context.Context, biz string, bizId int64) (domain.CaseSet, error) GetCandidates(ctx context.Context, id int64, offset int, limit int) ([]domain.Case, int64, error) } @@ -64,8 +64,23 @@ func (c *caseSetSvc) GetCandidates(ctx context.Context, id int64, offset int, li return c.caRepo.Exclude(ctx, cids, offset, limit) } -func (c *caseSetSvc) ListDefault(ctx context.Context, offset, limit int) ([]domain.CaseSet, error) { - return c.repo.ListByBiz(ctx, offset, limit, domain.DefaultBiz) +func (c *caseSetSvc) ListDefault(ctx context.Context, offset, limit int) (int64, []domain.CaseSet, error) { + var ( + eg errgroup.Group + total int64 + css []domain.CaseSet + ) + eg.Go(func() error { + var err error + css, err = c.repo.ListByBiz(ctx, offset, limit, domain.DefaultBiz) + return err + }) + eg.Go(func() error { + var err error + total, err = c.repo.CountByBiz(ctx, domain.DefaultBiz) + return err + }) + return total, css, eg.Wait() } func (c *caseSetSvc) ListByBiz(ctx context.Context, offset, limit int, biz string) ([]domain.CaseSet, error) { diff --git a/internal/cases/internal/service/cases.go b/internal/cases/internal/service/cases.go index 86781049..a08979c4 100644 --- a/internal/cases/internal/service/cases.go +++ b/internal/cases/internal/service/cases.go @@ -19,7 +19,7 @@ type Service interface { Publish(ctx context.Context, ca domain.Case) (int64, error) List(ctx context.Context, offset int, limit int) ([]domain.Case, int64, error) - PubList(ctx context.Context, offset int, limit int) ([]domain.Case, error) + PubList(ctx context.Context, offset int, limit int) (int64, []domain.Case, error) GetPubByIDs(ctx context.Context, ids []int64) ([]domain.Case, error) Detail(ctx context.Context, caseId int64) (domain.Case, error) PubDetail(ctx context.Context, caseId int64) (domain.Case, error) @@ -84,8 +84,24 @@ func (s *service) List(ctx context.Context, offset int, limit int) ([]domain.Cas return caseList, total, nil } -func (s *service) PubList(ctx context.Context, offset int, limit int) ([]domain.Case, error) { - return s.repo.PubList(ctx, offset, limit) +func (s *service) PubList(ctx context.Context, offset int, limit int) (int64, []domain.Case, error) { + var ( + eg errgroup.Group + cas []domain.Case + total int64 + ) + eg.Go(func() error { + var err error + cas, err = s.repo.PubList(ctx, offset, limit) + return err + }) + eg.Go(func() error { + var err error + total, err = s.repo.PubCount(ctx) + return err + }) + return total, cas, eg.Wait() + } func (s *service) Detail(ctx context.Context, caseId int64) (domain.Case, error) { diff --git a/internal/cases/internal/web/case_set_handler.go b/internal/cases/internal/web/case_set_handler.go index b54a831a..c524b91a 100644 --- a/internal/cases/internal/web/case_set_handler.go +++ b/internal/cases/internal/web/case_set_handler.go @@ -46,7 +46,7 @@ func (h *CaseSetHandler) PrivateRoutes(server *gin.Engine) { // ListCaseSets 展示个人案例集 func (h *CaseSetHandler) ListCaseSets(ctx *ginx.Context, req Page) (ginx.Result, error) { - data, err := h.svc.ListDefault(ctx, req.Offset, req.Limit) + count, data, err := h.svc.ListDefault(ctx, req.Offset, req.Limit) if err != nil { return systemErrorResult, err } @@ -67,6 +67,7 @@ func (h *CaseSetHandler) ListCaseSets(ctx *ginx.Context, req Page) (ginx.Result, } return ginx.Result{ Data: CaseSetList{ + Total: count, CaseSets: slice.Map(data, func(idx int, src domain.CaseSet) CaseSet { qs := newCaseSet(src) qs.Interactive = newInteractive(intrs[src.ID]) diff --git a/internal/cases/internal/web/handler.go b/internal/cases/internal/web/handler.go index 1bf9f1b4..ce8657e8 100644 --- a/internal/cases/internal/web/handler.go +++ b/internal/cases/internal/web/handler.go @@ -57,7 +57,7 @@ func (h *Handler) MemberRoutes(server *gin.Engine) { } func (h *Handler) PubList(ctx *ginx.Context, req Page) (ginx.Result, error) { - data, err := h.svc.PubList(ctx, req.Offset, req.Limit) + count, data, err := h.svc.PubList(ctx, req.Offset, req.Limit) if err != nil { return systemErrorResult, err } @@ -78,6 +78,7 @@ func (h *Handler) PubList(ctx *ginx.Context, req Page) (ginx.Result, error) { } return ginx.Result{ Data: CasesList{ + Total: count, Cases: slice.Map(data, func(idx int, ca domain.Case) Case { return Case{ Id: ca.Id, diff --git a/internal/cases/mocks/case_set.mock.go b/internal/cases/mocks/case_set.mock.go index 71f751d4..c699b5cf 100644 --- a/internal/cases/mocks/case_set.mock.go +++ b/internal/cases/mocks/case_set.mock.go @@ -5,6 +5,7 @@ // // mockgen -source=./case_set.go -destination=../../mocks/case_set.mock.go -package=casemocks -typed CaseSetService // + // Package casemocks is a generated GoMock package. package casemocks @@ -49,31 +50,31 @@ func (m *MockCaseSetService) Detail(ctx context.Context, id int64) (domain.CaseS } // Detail indicates an expected call of Detail. -func (mr *MockCaseSetServiceMockRecorder) Detail(ctx, id any) *CaseSetServiceDetailCall { +func (mr *MockCaseSetServiceMockRecorder) Detail(ctx, id any) *MockCaseSetServiceDetailCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Detail", reflect.TypeOf((*MockCaseSetService)(nil).Detail), ctx, id) - return &CaseSetServiceDetailCall{Call: call} + return &MockCaseSetServiceDetailCall{Call: call} } -// CaseSetServiceDetailCall wrap *gomock.Call -type CaseSetServiceDetailCall struct { +// MockCaseSetServiceDetailCall wrap *gomock.Call +type MockCaseSetServiceDetailCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *CaseSetServiceDetailCall) Return(arg0 domain.CaseSet, arg1 error) *CaseSetServiceDetailCall { +func (c *MockCaseSetServiceDetailCall) Return(arg0 domain.CaseSet, arg1 error) *MockCaseSetServiceDetailCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *CaseSetServiceDetailCall) Do(f func(context.Context, int64) (domain.CaseSet, error)) *CaseSetServiceDetailCall { +func (c *MockCaseSetServiceDetailCall) Do(f func(context.Context, int64) (domain.CaseSet, error)) *MockCaseSetServiceDetailCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *CaseSetServiceDetailCall) DoAndReturn(f func(context.Context, int64) (domain.CaseSet, error)) *CaseSetServiceDetailCall { +func (c *MockCaseSetServiceDetailCall) DoAndReturn(f func(context.Context, int64) (domain.CaseSet, error)) *MockCaseSetServiceDetailCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -88,31 +89,31 @@ func (m *MockCaseSetService) GetByBiz(ctx context.Context, biz string, bizId int } // GetByBiz indicates an expected call of GetByBiz. -func (mr *MockCaseSetServiceMockRecorder) GetByBiz(ctx, biz, bizId any) *CaseSetServiceGetByBizCall { +func (mr *MockCaseSetServiceMockRecorder) GetByBiz(ctx, biz, bizId any) *MockCaseSetServiceGetByBizCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByBiz", reflect.TypeOf((*MockCaseSetService)(nil).GetByBiz), ctx, biz, bizId) - return &CaseSetServiceGetByBizCall{Call: call} + return &MockCaseSetServiceGetByBizCall{Call: call} } -// CaseSetServiceGetByBizCall wrap *gomock.Call -type CaseSetServiceGetByBizCall struct { +// MockCaseSetServiceGetByBizCall wrap *gomock.Call +type MockCaseSetServiceGetByBizCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *CaseSetServiceGetByBizCall) Return(arg0 domain.CaseSet, arg1 error) *CaseSetServiceGetByBizCall { +func (c *MockCaseSetServiceGetByBizCall) Return(arg0 domain.CaseSet, arg1 error) *MockCaseSetServiceGetByBizCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *CaseSetServiceGetByBizCall) Do(f func(context.Context, string, int64) (domain.CaseSet, error)) *CaseSetServiceGetByBizCall { +func (c *MockCaseSetServiceGetByBizCall) Do(f func(context.Context, string, int64) (domain.CaseSet, error)) *MockCaseSetServiceGetByBizCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *CaseSetServiceGetByBizCall) DoAndReturn(f func(context.Context, string, int64) (domain.CaseSet, error)) *CaseSetServiceGetByBizCall { +func (c *MockCaseSetServiceGetByBizCall) DoAndReturn(f func(context.Context, string, int64) (domain.CaseSet, error)) *MockCaseSetServiceGetByBizCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -127,31 +128,31 @@ func (m *MockCaseSetService) GetByIds(ctx context.Context, ids []int64) ([]domai } // GetByIds indicates an expected call of GetByIds. -func (mr *MockCaseSetServiceMockRecorder) GetByIds(ctx, ids any) *CaseSetServiceGetByIdsCall { +func (mr *MockCaseSetServiceMockRecorder) GetByIds(ctx, ids any) *MockCaseSetServiceGetByIdsCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByIds", reflect.TypeOf((*MockCaseSetService)(nil).GetByIds), ctx, ids) - return &CaseSetServiceGetByIdsCall{Call: call} + return &MockCaseSetServiceGetByIdsCall{Call: call} } -// CaseSetServiceGetByIdsCall wrap *gomock.Call -type CaseSetServiceGetByIdsCall struct { +// MockCaseSetServiceGetByIdsCall wrap *gomock.Call +type MockCaseSetServiceGetByIdsCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *CaseSetServiceGetByIdsCall) Return(arg0 []domain.CaseSet, arg1 error) *CaseSetServiceGetByIdsCall { +func (c *MockCaseSetServiceGetByIdsCall) Return(arg0 []domain.CaseSet, arg1 error) *MockCaseSetServiceGetByIdsCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *CaseSetServiceGetByIdsCall) Do(f func(context.Context, []int64) ([]domain.CaseSet, error)) *CaseSetServiceGetByIdsCall { +func (c *MockCaseSetServiceGetByIdsCall) Do(f func(context.Context, []int64) ([]domain.CaseSet, error)) *MockCaseSetServiceGetByIdsCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *CaseSetServiceGetByIdsCall) DoAndReturn(f func(context.Context, []int64) ([]domain.CaseSet, error)) *CaseSetServiceGetByIdsCall { +func (c *MockCaseSetServiceGetByIdsCall) DoAndReturn(f func(context.Context, []int64) ([]domain.CaseSet, error)) *MockCaseSetServiceGetByIdsCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -166,31 +167,31 @@ func (m *MockCaseSetService) GetByIdsWithCases(ctx context.Context, ids []int64) } // GetByIdsWithCases indicates an expected call of GetByIdsWithCases. -func (mr *MockCaseSetServiceMockRecorder) GetByIdsWithCases(ctx, ids any) *CaseSetServiceGetByIdsWithCasesCall { +func (mr *MockCaseSetServiceMockRecorder) GetByIdsWithCases(ctx, ids any) *MockCaseSetServiceGetByIdsWithCasesCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByIdsWithCases", reflect.TypeOf((*MockCaseSetService)(nil).GetByIdsWithCases), ctx, ids) - return &CaseSetServiceGetByIdsWithCasesCall{Call: call} + return &MockCaseSetServiceGetByIdsWithCasesCall{Call: call} } -// CaseSetServiceGetByIdsWithCasesCall wrap *gomock.Call -type CaseSetServiceGetByIdsWithCasesCall struct { +// MockCaseSetServiceGetByIdsWithCasesCall wrap *gomock.Call +type MockCaseSetServiceGetByIdsWithCasesCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *CaseSetServiceGetByIdsWithCasesCall) Return(arg0 []domain.CaseSet, arg1 error) *CaseSetServiceGetByIdsWithCasesCall { +func (c *MockCaseSetServiceGetByIdsWithCasesCall) Return(arg0 []domain.CaseSet, arg1 error) *MockCaseSetServiceGetByIdsWithCasesCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *CaseSetServiceGetByIdsWithCasesCall) Do(f func(context.Context, []int64) ([]domain.CaseSet, error)) *CaseSetServiceGetByIdsWithCasesCall { +func (c *MockCaseSetServiceGetByIdsWithCasesCall) Do(f func(context.Context, []int64) ([]domain.CaseSet, error)) *MockCaseSetServiceGetByIdsWithCasesCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *CaseSetServiceGetByIdsWithCasesCall) DoAndReturn(f func(context.Context, []int64) ([]domain.CaseSet, error)) *CaseSetServiceGetByIdsWithCasesCall { +func (c *MockCaseSetServiceGetByIdsWithCasesCall) DoAndReturn(f func(context.Context, []int64) ([]domain.CaseSet, error)) *MockCaseSetServiceGetByIdsWithCasesCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -206,31 +207,31 @@ func (m *MockCaseSetService) GetCandidates(ctx context.Context, id int64, offset } // GetCandidates indicates an expected call of GetCandidates. -func (mr *MockCaseSetServiceMockRecorder) GetCandidates(ctx, id, offset, limit any) *CaseSetServiceGetCandidatesCall { +func (mr *MockCaseSetServiceMockRecorder) GetCandidates(ctx, id, offset, limit any) *MockCaseSetServiceGetCandidatesCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCandidates", reflect.TypeOf((*MockCaseSetService)(nil).GetCandidates), ctx, id, offset, limit) - return &CaseSetServiceGetCandidatesCall{Call: call} + return &MockCaseSetServiceGetCandidatesCall{Call: call} } -// CaseSetServiceGetCandidatesCall wrap *gomock.Call -type CaseSetServiceGetCandidatesCall struct { +// MockCaseSetServiceGetCandidatesCall wrap *gomock.Call +type MockCaseSetServiceGetCandidatesCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *CaseSetServiceGetCandidatesCall) Return(arg0 []domain.Case, arg1 int64, arg2 error) *CaseSetServiceGetCandidatesCall { +func (c *MockCaseSetServiceGetCandidatesCall) Return(arg0 []domain.Case, arg1 int64, arg2 error) *MockCaseSetServiceGetCandidatesCall { c.Call = c.Call.Return(arg0, arg1, arg2) return c } // Do rewrite *gomock.Call.Do -func (c *CaseSetServiceGetCandidatesCall) Do(f func(context.Context, int64, int, int) ([]domain.Case, int64, error)) *CaseSetServiceGetCandidatesCall { +func (c *MockCaseSetServiceGetCandidatesCall) Do(f func(context.Context, int64, int, int) ([]domain.Case, int64, error)) *MockCaseSetServiceGetCandidatesCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *CaseSetServiceGetCandidatesCall) DoAndReturn(f func(context.Context, int64, int, int) ([]domain.Case, int64, error)) *CaseSetServiceGetCandidatesCall { +func (c *MockCaseSetServiceGetCandidatesCall) DoAndReturn(f func(context.Context, int64, int, int) ([]domain.Case, int64, error)) *MockCaseSetServiceGetCandidatesCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -246,31 +247,31 @@ func (m *MockCaseSetService) List(ctx context.Context, offset, limit int) ([]dom } // List indicates an expected call of List. -func (mr *MockCaseSetServiceMockRecorder) List(ctx, offset, limit any) *CaseSetServiceListCall { +func (mr *MockCaseSetServiceMockRecorder) List(ctx, offset, limit any) *MockCaseSetServiceListCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockCaseSetService)(nil).List), ctx, offset, limit) - return &CaseSetServiceListCall{Call: call} + return &MockCaseSetServiceListCall{Call: call} } -// CaseSetServiceListCall wrap *gomock.Call -type CaseSetServiceListCall struct { +// MockCaseSetServiceListCall wrap *gomock.Call +type MockCaseSetServiceListCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *CaseSetServiceListCall) Return(arg0 []domain.CaseSet, arg1 int64, arg2 error) *CaseSetServiceListCall { +func (c *MockCaseSetServiceListCall) Return(arg0 []domain.CaseSet, arg1 int64, arg2 error) *MockCaseSetServiceListCall { c.Call = c.Call.Return(arg0, arg1, arg2) return c } // Do rewrite *gomock.Call.Do -func (c *CaseSetServiceListCall) Do(f func(context.Context, int, int) ([]domain.CaseSet, int64, error)) *CaseSetServiceListCall { +func (c *MockCaseSetServiceListCall) Do(f func(context.Context, int, int) ([]domain.CaseSet, int64, error)) *MockCaseSetServiceListCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *CaseSetServiceListCall) DoAndReturn(f func(context.Context, int, int) ([]domain.CaseSet, int64, error)) *CaseSetServiceListCall { +func (c *MockCaseSetServiceListCall) DoAndReturn(f func(context.Context, int, int) ([]domain.CaseSet, int64, error)) *MockCaseSetServiceListCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -285,70 +286,71 @@ func (m *MockCaseSetService) ListByBiz(ctx context.Context, offset, limit int, b } // ListByBiz indicates an expected call of ListByBiz. -func (mr *MockCaseSetServiceMockRecorder) ListByBiz(ctx, offset, limit, biz any) *CaseSetServiceListByBizCall { +func (mr *MockCaseSetServiceMockRecorder) ListByBiz(ctx, offset, limit, biz any) *MockCaseSetServiceListByBizCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListByBiz", reflect.TypeOf((*MockCaseSetService)(nil).ListByBiz), ctx, offset, limit, biz) - return &CaseSetServiceListByBizCall{Call: call} + return &MockCaseSetServiceListByBizCall{Call: call} } -// CaseSetServiceListByBizCall wrap *gomock.Call -type CaseSetServiceListByBizCall struct { +// MockCaseSetServiceListByBizCall wrap *gomock.Call +type MockCaseSetServiceListByBizCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *CaseSetServiceListByBizCall) Return(arg0 []domain.CaseSet, arg1 error) *CaseSetServiceListByBizCall { +func (c *MockCaseSetServiceListByBizCall) Return(arg0 []domain.CaseSet, arg1 error) *MockCaseSetServiceListByBizCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *CaseSetServiceListByBizCall) Do(f func(context.Context, int, int, string) ([]domain.CaseSet, error)) *CaseSetServiceListByBizCall { +func (c *MockCaseSetServiceListByBizCall) Do(f func(context.Context, int, int, string) ([]domain.CaseSet, error)) *MockCaseSetServiceListByBizCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *CaseSetServiceListByBizCall) DoAndReturn(f func(context.Context, int, int, string) ([]domain.CaseSet, error)) *CaseSetServiceListByBizCall { +func (c *MockCaseSetServiceListByBizCall) DoAndReturn(f func(context.Context, int, int, string) ([]domain.CaseSet, error)) *MockCaseSetServiceListByBizCall { c.Call = c.Call.DoAndReturn(f) return c } // ListDefault mocks base method. -func (m *MockCaseSetService) ListDefault(ctx context.Context, offset, limit int) ([]domain.CaseSet, error) { +func (m *MockCaseSetService) ListDefault(ctx context.Context, offset, limit int) (int64, []domain.CaseSet, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ListDefault", ctx, offset, limit) - ret0, _ := ret[0].([]domain.CaseSet) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret0, _ := ret[0].(int64) + ret1, _ := ret[1].([]domain.CaseSet) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } // ListDefault indicates an expected call of ListDefault. -func (mr *MockCaseSetServiceMockRecorder) ListDefault(ctx, offset, limit any) *CaseSetServiceListDefaultCall { +func (mr *MockCaseSetServiceMockRecorder) ListDefault(ctx, offset, limit any) *MockCaseSetServiceListDefaultCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListDefault", reflect.TypeOf((*MockCaseSetService)(nil).ListDefault), ctx, offset, limit) - return &CaseSetServiceListDefaultCall{Call: call} + return &MockCaseSetServiceListDefaultCall{Call: call} } -// CaseSetServiceListDefaultCall wrap *gomock.Call -type CaseSetServiceListDefaultCall struct { +// MockCaseSetServiceListDefaultCall wrap *gomock.Call +type MockCaseSetServiceListDefaultCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *CaseSetServiceListDefaultCall) Return(arg0 []domain.CaseSet, arg1 error) *CaseSetServiceListDefaultCall { - c.Call = c.Call.Return(arg0, arg1) +func (c *MockCaseSetServiceListDefaultCall) Return(arg0 int64, arg1 []domain.CaseSet, arg2 error) *MockCaseSetServiceListDefaultCall { + c.Call = c.Call.Return(arg0, arg1, arg2) return c } // Do rewrite *gomock.Call.Do -func (c *CaseSetServiceListDefaultCall) Do(f func(context.Context, int, int) ([]domain.CaseSet, error)) *CaseSetServiceListDefaultCall { +func (c *MockCaseSetServiceListDefaultCall) Do(f func(context.Context, int, int) (int64, []domain.CaseSet, error)) *MockCaseSetServiceListDefaultCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *CaseSetServiceListDefaultCall) DoAndReturn(f func(context.Context, int, int) ([]domain.CaseSet, error)) *CaseSetServiceListDefaultCall { +func (c *MockCaseSetServiceListDefaultCall) DoAndReturn(f func(context.Context, int, int) (int64, []domain.CaseSet, error)) *MockCaseSetServiceListDefaultCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -363,31 +365,31 @@ func (m *MockCaseSetService) Save(ctx context.Context, set domain.CaseSet) (int6 } // Save indicates an expected call of Save. -func (mr *MockCaseSetServiceMockRecorder) Save(ctx, set any) *CaseSetServiceSaveCall { +func (mr *MockCaseSetServiceMockRecorder) Save(ctx, set any) *MockCaseSetServiceSaveCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Save", reflect.TypeOf((*MockCaseSetService)(nil).Save), ctx, set) - return &CaseSetServiceSaveCall{Call: call} + return &MockCaseSetServiceSaveCall{Call: call} } -// CaseSetServiceSaveCall wrap *gomock.Call -type CaseSetServiceSaveCall struct { +// MockCaseSetServiceSaveCall wrap *gomock.Call +type MockCaseSetServiceSaveCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *CaseSetServiceSaveCall) Return(arg0 int64, arg1 error) *CaseSetServiceSaveCall { +func (c *MockCaseSetServiceSaveCall) Return(arg0 int64, arg1 error) *MockCaseSetServiceSaveCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *CaseSetServiceSaveCall) Do(f func(context.Context, domain.CaseSet) (int64, error)) *CaseSetServiceSaveCall { +func (c *MockCaseSetServiceSaveCall) Do(f func(context.Context, domain.CaseSet) (int64, error)) *MockCaseSetServiceSaveCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *CaseSetServiceSaveCall) DoAndReturn(f func(context.Context, domain.CaseSet) (int64, error)) *CaseSetServiceSaveCall { +func (c *MockCaseSetServiceSaveCall) DoAndReturn(f func(context.Context, domain.CaseSet) (int64, error)) *MockCaseSetServiceSaveCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -401,31 +403,31 @@ func (m *MockCaseSetService) UpdateCases(ctx context.Context, set domain.CaseSet } // UpdateCases indicates an expected call of UpdateCases. -func (mr *MockCaseSetServiceMockRecorder) UpdateCases(ctx, set any) *CaseSetServiceUpdateCasesCall { +func (mr *MockCaseSetServiceMockRecorder) UpdateCases(ctx, set any) *MockCaseSetServiceUpdateCasesCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateCases", reflect.TypeOf((*MockCaseSetService)(nil).UpdateCases), ctx, set) - return &CaseSetServiceUpdateCasesCall{Call: call} + return &MockCaseSetServiceUpdateCasesCall{Call: call} } -// CaseSetServiceUpdateCasesCall wrap *gomock.Call -type CaseSetServiceUpdateCasesCall struct { +// MockCaseSetServiceUpdateCasesCall wrap *gomock.Call +type MockCaseSetServiceUpdateCasesCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *CaseSetServiceUpdateCasesCall) Return(arg0 error) *CaseSetServiceUpdateCasesCall { +func (c *MockCaseSetServiceUpdateCasesCall) Return(arg0 error) *MockCaseSetServiceUpdateCasesCall { c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *CaseSetServiceUpdateCasesCall) Do(f func(context.Context, domain.CaseSet) error) *CaseSetServiceUpdateCasesCall { +func (c *MockCaseSetServiceUpdateCasesCall) Do(f func(context.Context, domain.CaseSet) error) *MockCaseSetServiceUpdateCasesCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *CaseSetServiceUpdateCasesCall) DoAndReturn(f func(context.Context, domain.CaseSet) error) *CaseSetServiceUpdateCasesCall { +func (c *MockCaseSetServiceUpdateCasesCall) DoAndReturn(f func(context.Context, domain.CaseSet) error) *MockCaseSetServiceUpdateCasesCall { c.Call = c.Call.DoAndReturn(f) return c } diff --git a/internal/cases/mocks/cases.mock.go b/internal/cases/mocks/cases.mock.go index 062558fc..53ae78ad 100644 --- a/internal/cases/mocks/cases.mock.go +++ b/internal/cases/mocks/cases.mock.go @@ -5,6 +5,7 @@ // // mockgen -source=./cases.go -destination=../../mocks/cases.mock.go -package=casemocks -typed Service // + // Package casemocks is a generated GoMock package. package casemocks @@ -49,31 +50,31 @@ func (m *MockService) Detail(ctx context.Context, caseId int64) (domain.Case, er } // Detail indicates an expected call of Detail. -func (mr *MockServiceMockRecorder) Detail(ctx, caseId any) *ServiceDetailCall { +func (mr *MockServiceMockRecorder) Detail(ctx, caseId any) *MockServiceDetailCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Detail", reflect.TypeOf((*MockService)(nil).Detail), ctx, caseId) - return &ServiceDetailCall{Call: call} + return &MockServiceDetailCall{Call: call} } -// ServiceDetailCall wrap *gomock.Call -type ServiceDetailCall struct { +// MockServiceDetailCall wrap *gomock.Call +type MockServiceDetailCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServiceDetailCall) Return(arg0 domain.Case, arg1 error) *ServiceDetailCall { +func (c *MockServiceDetailCall) Return(arg0 domain.Case, arg1 error) *MockServiceDetailCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *ServiceDetailCall) Do(f func(context.Context, int64) (domain.Case, error)) *ServiceDetailCall { +func (c *MockServiceDetailCall) Do(f func(context.Context, int64) (domain.Case, error)) *MockServiceDetailCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServiceDetailCall) DoAndReturn(f func(context.Context, int64) (domain.Case, error)) *ServiceDetailCall { +func (c *MockServiceDetailCall) DoAndReturn(f func(context.Context, int64) (domain.Case, error)) *MockServiceDetailCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -88,31 +89,31 @@ func (m *MockService) GetPubByIDs(ctx context.Context, ids []int64) ([]domain.Ca } // GetPubByIDs indicates an expected call of GetPubByIDs. -func (mr *MockServiceMockRecorder) GetPubByIDs(ctx, ids any) *ServiceGetPubByIDsCall { +func (mr *MockServiceMockRecorder) GetPubByIDs(ctx, ids any) *MockServiceGetPubByIDsCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPubByIDs", reflect.TypeOf((*MockService)(nil).GetPubByIDs), ctx, ids) - return &ServiceGetPubByIDsCall{Call: call} + return &MockServiceGetPubByIDsCall{Call: call} } -// ServiceGetPubByIDsCall wrap *gomock.Call -type ServiceGetPubByIDsCall struct { +// MockServiceGetPubByIDsCall wrap *gomock.Call +type MockServiceGetPubByIDsCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServiceGetPubByIDsCall) Return(arg0 []domain.Case, arg1 error) *ServiceGetPubByIDsCall { +func (c *MockServiceGetPubByIDsCall) Return(arg0 []domain.Case, arg1 error) *MockServiceGetPubByIDsCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *ServiceGetPubByIDsCall) Do(f func(context.Context, []int64) ([]domain.Case, error)) *ServiceGetPubByIDsCall { +func (c *MockServiceGetPubByIDsCall) Do(f func(context.Context, []int64) ([]domain.Case, error)) *MockServiceGetPubByIDsCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServiceGetPubByIDsCall) DoAndReturn(f func(context.Context, []int64) ([]domain.Case, error)) *ServiceGetPubByIDsCall { +func (c *MockServiceGetPubByIDsCall) DoAndReturn(f func(context.Context, []int64) ([]domain.Case, error)) *MockServiceGetPubByIDsCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -128,31 +129,31 @@ func (m *MockService) List(ctx context.Context, offset, limit int) ([]domain.Cas } // List indicates an expected call of List. -func (mr *MockServiceMockRecorder) List(ctx, offset, limit any) *ServiceListCall { +func (mr *MockServiceMockRecorder) List(ctx, offset, limit any) *MockServiceListCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockService)(nil).List), ctx, offset, limit) - return &ServiceListCall{Call: call} + return &MockServiceListCall{Call: call} } -// ServiceListCall wrap *gomock.Call -type ServiceListCall struct { +// MockServiceListCall wrap *gomock.Call +type MockServiceListCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServiceListCall) Return(arg0 []domain.Case, arg1 int64, arg2 error) *ServiceListCall { +func (c *MockServiceListCall) Return(arg0 []domain.Case, arg1 int64, arg2 error) *MockServiceListCall { c.Call = c.Call.Return(arg0, arg1, arg2) return c } // Do rewrite *gomock.Call.Do -func (c *ServiceListCall) Do(f func(context.Context, int, int) ([]domain.Case, int64, error)) *ServiceListCall { +func (c *MockServiceListCall) Do(f func(context.Context, int, int) ([]domain.Case, int64, error)) *MockServiceListCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServiceListCall) DoAndReturn(f func(context.Context, int, int) ([]domain.Case, int64, error)) *ServiceListCall { +func (c *MockServiceListCall) DoAndReturn(f func(context.Context, int, int) ([]domain.Case, int64, error)) *MockServiceListCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -167,70 +168,71 @@ func (m *MockService) PubDetail(ctx context.Context, caseId int64) (domain.Case, } // PubDetail indicates an expected call of PubDetail. -func (mr *MockServiceMockRecorder) PubDetail(ctx, caseId any) *ServicePubDetailCall { +func (mr *MockServiceMockRecorder) PubDetail(ctx, caseId any) *MockServicePubDetailCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PubDetail", reflect.TypeOf((*MockService)(nil).PubDetail), ctx, caseId) - return &ServicePubDetailCall{Call: call} + return &MockServicePubDetailCall{Call: call} } -// ServicePubDetailCall wrap *gomock.Call -type ServicePubDetailCall struct { +// MockServicePubDetailCall wrap *gomock.Call +type MockServicePubDetailCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServicePubDetailCall) Return(arg0 domain.Case, arg1 error) *ServicePubDetailCall { +func (c *MockServicePubDetailCall) Return(arg0 domain.Case, arg1 error) *MockServicePubDetailCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *ServicePubDetailCall) Do(f func(context.Context, int64) (domain.Case, error)) *ServicePubDetailCall { +func (c *MockServicePubDetailCall) Do(f func(context.Context, int64) (domain.Case, error)) *MockServicePubDetailCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServicePubDetailCall) DoAndReturn(f func(context.Context, int64) (domain.Case, error)) *ServicePubDetailCall { +func (c *MockServicePubDetailCall) DoAndReturn(f func(context.Context, int64) (domain.Case, error)) *MockServicePubDetailCall { c.Call = c.Call.DoAndReturn(f) return c } // PubList mocks base method. -func (m *MockService) PubList(ctx context.Context, offset, limit int) ([]domain.Case, error) { +func (m *MockService) PubList(ctx context.Context, offset, limit int) (int64, []domain.Case, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "PubList", ctx, offset, limit) - ret0, _ := ret[0].([]domain.Case) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret0, _ := ret[0].(int64) + ret1, _ := ret[1].([]domain.Case) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } // PubList indicates an expected call of PubList. -func (mr *MockServiceMockRecorder) PubList(ctx, offset, limit any) *ServicePubListCall { +func (mr *MockServiceMockRecorder) PubList(ctx, offset, limit any) *MockServicePubListCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PubList", reflect.TypeOf((*MockService)(nil).PubList), ctx, offset, limit) - return &ServicePubListCall{Call: call} + return &MockServicePubListCall{Call: call} } -// ServicePubListCall wrap *gomock.Call -type ServicePubListCall struct { +// MockServicePubListCall wrap *gomock.Call +type MockServicePubListCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServicePubListCall) Return(arg0 []domain.Case, arg1 error) *ServicePubListCall { - c.Call = c.Call.Return(arg0, arg1) +func (c *MockServicePubListCall) Return(arg0 int64, arg1 []domain.Case, arg2 error) *MockServicePubListCall { + c.Call = c.Call.Return(arg0, arg1, arg2) return c } // Do rewrite *gomock.Call.Do -func (c *ServicePubListCall) Do(f func(context.Context, int, int) ([]domain.Case, error)) *ServicePubListCall { +func (c *MockServicePubListCall) Do(f func(context.Context, int, int) (int64, []domain.Case, error)) *MockServicePubListCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServicePubListCall) DoAndReturn(f func(context.Context, int, int) ([]domain.Case, error)) *ServicePubListCall { +func (c *MockServicePubListCall) DoAndReturn(f func(context.Context, int, int) (int64, []domain.Case, error)) *MockServicePubListCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -245,31 +247,31 @@ func (m *MockService) Publish(ctx context.Context, ca domain.Case) (int64, error } // Publish indicates an expected call of Publish. -func (mr *MockServiceMockRecorder) Publish(ctx, ca any) *ServicePublishCall { +func (mr *MockServiceMockRecorder) Publish(ctx, ca any) *MockServicePublishCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Publish", reflect.TypeOf((*MockService)(nil).Publish), ctx, ca) - return &ServicePublishCall{Call: call} + return &MockServicePublishCall{Call: call} } -// ServicePublishCall wrap *gomock.Call -type ServicePublishCall struct { +// MockServicePublishCall wrap *gomock.Call +type MockServicePublishCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServicePublishCall) Return(arg0 int64, arg1 error) *ServicePublishCall { +func (c *MockServicePublishCall) Return(arg0 int64, arg1 error) *MockServicePublishCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *ServicePublishCall) Do(f func(context.Context, domain.Case) (int64, error)) *ServicePublishCall { +func (c *MockServicePublishCall) Do(f func(context.Context, domain.Case) (int64, error)) *MockServicePublishCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServicePublishCall) DoAndReturn(f func(context.Context, domain.Case) (int64, error)) *ServicePublishCall { +func (c *MockServicePublishCall) DoAndReturn(f func(context.Context, domain.Case) (int64, error)) *MockServicePublishCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -284,31 +286,31 @@ func (m *MockService) Save(ctx context.Context, ca domain.Case) (int64, error) { } // Save indicates an expected call of Save. -func (mr *MockServiceMockRecorder) Save(ctx, ca any) *ServiceSaveCall { +func (mr *MockServiceMockRecorder) Save(ctx, ca any) *MockServiceSaveCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Save", reflect.TypeOf((*MockService)(nil).Save), ctx, ca) - return &ServiceSaveCall{Call: call} + return &MockServiceSaveCall{Call: call} } -// ServiceSaveCall wrap *gomock.Call -type ServiceSaveCall struct { +// MockServiceSaveCall wrap *gomock.Call +type MockServiceSaveCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServiceSaveCall) Return(arg0 int64, arg1 error) *ServiceSaveCall { +func (c *MockServiceSaveCall) Return(arg0 int64, arg1 error) *MockServiceSaveCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *ServiceSaveCall) Do(f func(context.Context, domain.Case) (int64, error)) *ServiceSaveCall { +func (c *MockServiceSaveCall) Do(f func(context.Context, domain.Case) (int64, error)) *MockServiceSaveCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServiceSaveCall) DoAndReturn(f func(context.Context, domain.Case) (int64, error)) *ServiceSaveCall { +func (c *MockServiceSaveCall) DoAndReturn(f func(context.Context, domain.Case) (int64, error)) *MockServiceSaveCall { c.Call = c.Call.DoAndReturn(f) return c } diff --git a/internal/project/internal/integration/project_test.go b/internal/project/internal/integration/project_test.go index 23452e2a..9c00dc7a 100644 --- a/internal/project/internal/integration/project_test.go +++ b/internal/project/internal/integration/project_test.go @@ -135,7 +135,7 @@ func (s *ProjectTestSuite) TestProjectList() { req web.Page wantCode int - wantResp test.Result[[]web.Project] + wantResp test.Result[web.ProjectList] }{ { name: "从头获取成功", @@ -144,42 +144,45 @@ func (s *ProjectTestSuite) TestProjectList() { Limit: 2, }, wantCode: 200, - wantResp: test.Result[[]web.Project]{ - Data: []web.Project{ - { - Id: 9, - SN: "SN9", - Title: "标题9", - Status: domain.ProjectStatusPublished.ToUint8(), - Labels: []string{"标签9"}, - Desc: "描述9", - Utime: 9, - CodeSPU: "code-spu-9", - ProductSPU: "product-spu-9", - Interactive: web.Interactive{ - ViewCnt: 10, - LikeCnt: 11, - CollectCnt: 12, - Liked: true, - Collected: false, + wantResp: test.Result[web.ProjectList]{ + Data: web.ProjectList{ + Total: 5, + Projects: []web.Project{ + { + Id: 9, + SN: "SN9", + Title: "标题9", + Status: domain.ProjectStatusPublished.ToUint8(), + Labels: []string{"标签9"}, + Desc: "描述9", + Utime: 9, + CodeSPU: "code-spu-9", + ProductSPU: "product-spu-9", + Interactive: web.Interactive{ + ViewCnt: 10, + LikeCnt: 11, + CollectCnt: 12, + Liked: true, + Collected: false, + }, }, - }, - { - Id: 7, - SN: "SN7", - Title: "标题7", - Status: domain.ProjectStatusPublished.ToUint8(), - Labels: []string{"标签7"}, - Desc: "描述7", - Utime: 7, - CodeSPU: "code-spu-7", - ProductSPU: "product-spu-7", - Interactive: web.Interactive{ - ViewCnt: 8, - LikeCnt: 9, - CollectCnt: 10, - Liked: true, - Collected: false, + { + Id: 7, + SN: "SN7", + Title: "标题7", + Status: domain.ProjectStatusPublished.ToUint8(), + Labels: []string{"标签7"}, + Desc: "描述7", + Utime: 7, + CodeSPU: "code-spu-7", + ProductSPU: "product-spu-7", + Interactive: web.Interactive{ + ViewCnt: 8, + LikeCnt: 9, + CollectCnt: 10, + Liked: true, + Collected: false, + }, }, }, }, @@ -192,24 +195,27 @@ func (s *ProjectTestSuite) TestProjectList() { Limit: 2, }, wantCode: 200, - wantResp: test.Result[[]web.Project]{ - Data: []web.Project{ - { - Id: 1, - SN: "SN1", - Title: "标题1", - Status: domain.ProjectStatusPublished.ToUint8(), - Labels: []string{"标签1"}, - Desc: "描述1", - Utime: 1, - CodeSPU: "code-spu-1", - ProductSPU: "product-spu-1", - Interactive: web.Interactive{ - ViewCnt: 2, - LikeCnt: 3, - CollectCnt: 4, - Liked: true, - Collected: false, + wantResp: test.Result[web.ProjectList]{ + Data: web.ProjectList{ + Total: 5, + Projects: []web.Project{ + { + Id: 1, + SN: "SN1", + Title: "标题1", + Status: domain.ProjectStatusPublished.ToUint8(), + Labels: []string{"标签1"}, + Desc: "描述1", + Utime: 1, + CodeSPU: "code-spu-1", + ProductSPU: "product-spu-1", + Interactive: web.Interactive{ + ViewCnt: 2, + LikeCnt: 3, + CollectCnt: 4, + Liked: true, + Collected: false, + }, }, }, }, @@ -224,7 +230,7 @@ func (s *ProjectTestSuite) TestProjectList() { "/project/list", iox.NewJSONReader(tc.req)) req.Header.Set("content-type", "application/json") require.NoError(t, err) - recorder := test.NewJSONResponseRecorder[[]web.Project]() + recorder := test.NewJSONResponseRecorder[web.ProjectList]() s.server.ServeHTTP(recorder, req) require.Equal(t, tc.wantCode, recorder.Code) assert.Equal(t, tc.wantResp, recorder.MustScan()) diff --git a/internal/project/internal/repository/dao/dao.go b/internal/project/internal/repository/dao/dao.go index 7ed2a108..ad71e346 100644 --- a/internal/project/internal/repository/dao/dao.go +++ b/internal/project/internal/repository/dao/dao.go @@ -23,6 +23,7 @@ import ( type ProjectDAO interface { List(ctx context.Context, offset int, limit int) ([]PubProject, error) + Count(ctx context.Context) (int64, error) GetById(ctx context.Context, id int64) (PubProject, error) BriefById(ctx context.Context, id int64) (PubProject, error) Resumes(ctx context.Context, pid int64) ([]PubProjectResume, error) @@ -106,6 +107,15 @@ func (dao *GORMProjectDAO) List(ctx context.Context, offset int, limit int) ([]P return res, err } +func (dao *GORMProjectDAO) Count(ctx context.Context) (int64, error) { + var count int64 + err := dao.db.WithContext(ctx). + Model(&PubProject{}). + Where("status = ?", + domain.ProjectStatusPublished.ToUint8()).Count(&count).Error + return count, err +} + func NewGORMProjectDAO(db *egorm.Component) ProjectDAO { return &GORMProjectDAO{ db: db, diff --git a/internal/project/internal/repository/repository.go b/internal/project/internal/repository/repository.go index a0c50ec8..969c2b27 100644 --- a/internal/project/internal/repository/repository.go +++ b/internal/project/internal/repository/repository.go @@ -27,6 +27,7 @@ import ( // Repository C 端接口 type Repository interface { List(ctx context.Context, offset int, limit int) ([]domain.Project, error) + Count(ctx context.Context) (int64, error) Detail(ctx context.Context, id int64) (domain.Project, error) Brief(ctx context.Context, id int64) (domain.Project, error) } @@ -37,6 +38,10 @@ type CachedRepository struct { dao dao.ProjectDAO } +func (repo *CachedRepository) Count(ctx context.Context) (int64, error) { + return repo.dao.Count(ctx) +} + func (repo *CachedRepository) Brief(ctx context.Context, id int64) (domain.Project, error) { //TODO implement me prj, err := repo.dao.BriefById(ctx, id) return repo.prjToDomain(prj, nil, nil, nil, nil, nil), err diff --git a/internal/project/internal/service/service.go b/internal/project/internal/service/service.go index 0fd569af..73cff76e 100644 --- a/internal/project/internal/service/service.go +++ b/internal/project/internal/service/service.go @@ -18,6 +18,8 @@ import ( "context" "time" + "golang.org/x/sync/errgroup" + "github.com/ecodeclub/webook/internal/project/internal/event" "github.com/gotomicro/ego/core/elog" @@ -27,7 +29,7 @@ import ( // Service C 端接口 type Service interface { - List(ctx context.Context, offset int, limit int) ([]domain.Project, error) + List(ctx context.Context, offset int, limit int) (int64, []domain.Project, error) Detail(ctx context.Context, id int64) (domain.Project, error) // Brief 获得 project 本身的内容 Brief(ctx context.Context, id int64) (domain.Project, error) @@ -62,8 +64,23 @@ func (s *service) Detail(ctx context.Context, id int64) (domain.Project, error) return prj, err } -func (s *service) List(ctx context.Context, offset int, limit int) ([]domain.Project, error) { - return s.repo.List(ctx, offset, limit) +func (s *service) List(ctx context.Context, offset int, limit int) (int64, []domain.Project, error) { + var ( + eg errgroup.Group + total int64 + projects []domain.Project + ) + eg.Go(func() error { + var err error + projects, err = s.repo.List(ctx, offset, limit) + return err + }) + eg.Go(func() error { + var err error + total, err = s.repo.Count(ctx) + return err + }) + return total, projects, eg.Wait() } func NewService(repo repository.Repository, producer event.InteractiveEventProducer) Service { diff --git a/internal/project/internal/web/handler.go b/internal/project/internal/web/handler.go index c763ed1b..08cd9f5d 100644 --- a/internal/project/internal/web/handler.go +++ b/internal/project/internal/web/handler.go @@ -57,7 +57,7 @@ func (h *Handler) PrivateRoutes(server *gin.Engine) { } func (h *Handler) List(ctx *ginx.Context, req Page) (ginx.Result, error) { - data, err := h.svc.List(ctx, req.Offset, req.Limit) + count, data, err := h.svc.List(ctx, req.Offset, req.Limit) if err != nil { return systemErrorResult, err } @@ -77,9 +77,12 @@ func (h *Handler) List(ctx *ginx.Context, req Page) (ginx.Result, error) { } } return ginx.Result{ - Data: slice.Map(data, func(idx int, src domain.Project) Project { - return newProject(src, intrs[src.Id]) - }), + Data: ProjectList{ + Total: count, + Projects: slice.Map(data, func(idx int, src domain.Project) Project { + return newProject(src, intrs[src.Id]) + }), + }, }, nil } diff --git a/internal/question/internal/integration/handler_test.go b/internal/question/internal/integration/handler_test.go index 8b6b3bb9..84c25876 100644 --- a/internal/question/internal/integration/handler_test.go +++ b/internal/question/internal/integration/handler_test.go @@ -167,7 +167,7 @@ func (s *HandlerTestSuite) TestPubList() { req web.Page wantCode int - wantResp test.Result[[]web.Question] + wantResp test.Result[web.QuestionList] }{ { name: "获取成功", @@ -176,38 +176,41 @@ func (s *HandlerTestSuite) TestPubList() { Offset: 0, }, wantCode: 200, - wantResp: test.Result[[]web.Question]{ - Data: []web.Question{ - { - Id: 100, - Title: "这是标题 99", - Content: "这是解析 99", - Status: domain.UnPublishedStatus.ToUint8(), - Utime: 123, - Biz: domain.DefaultBiz, - BizId: 100, - Interactive: web.Interactive{ - ViewCnt: 101, - LikeCnt: 102, - CollectCnt: 103, - Liked: false, - Collected: true, + wantResp: test.Result[web.QuestionList]{ + Data: web.QuestionList{ + Total: 100, + Questions: []web.Question{ + { + Id: 100, + Title: "这是标题 99", + Content: "这是解析 99", + Status: domain.UnPublishedStatus.ToUint8(), + Utime: 123, + Biz: domain.DefaultBiz, + BizId: 100, + Interactive: web.Interactive{ + ViewCnt: 101, + LikeCnt: 102, + CollectCnt: 103, + Liked: false, + Collected: true, + }, }, - }, - { - Id: 99, - Title: "这是标题 98", - Content: "这是解析 98", - Status: domain.UnPublishedStatus.ToUint8(), - Utime: 123, - Biz: domain.DefaultBiz, - BizId: 99, - Interactive: web.Interactive{ - ViewCnt: 100, - LikeCnt: 101, - CollectCnt: 102, - Liked: true, - Collected: false, + { + Id: 99, + Title: "这是标题 98", + Content: "这是解析 98", + Status: domain.UnPublishedStatus.ToUint8(), + Utime: 123, + Biz: domain.DefaultBiz, + BizId: 99, + Interactive: web.Interactive{ + ViewCnt: 100, + LikeCnt: 101, + CollectCnt: 102, + Liked: true, + Collected: false, + }, }, }, }, @@ -220,22 +223,25 @@ func (s *HandlerTestSuite) TestPubList() { Offset: 99, }, wantCode: 200, - wantResp: test.Result[[]web.Question]{ - Data: []web.Question{ - { - Id: 1, - Title: "这是标题 0", - Content: "这是解析 0", - Biz: domain.DefaultBiz, - BizId: 1, - Status: domain.UnPublishedStatus.ToUint8(), - Utime: 123, - Interactive: web.Interactive{ - ViewCnt: 2, - LikeCnt: 3, - CollectCnt: 4, - Liked: true, - Collected: false, + wantResp: test.Result[web.QuestionList]{ + Data: web.QuestionList{ + Total: 100, + Questions: []web.Question{ + { + Id: 1, + Title: "这是标题 0", + Content: "这是解析 0", + Biz: domain.DefaultBiz, + BizId: 1, + Status: domain.UnPublishedStatus.ToUint8(), + Utime: 123, + Interactive: web.Interactive{ + ViewCnt: 2, + LikeCnt: 3, + CollectCnt: 4, + Liked: true, + Collected: false, + }, }, }, }, @@ -250,7 +256,7 @@ func (s *HandlerTestSuite) TestPubList() { "/question/list", iox.NewJSONReader(tc.req)) req.Header.Set("content-type", "application/json") require.NoError(t, err) - recorder := test.NewJSONResponseRecorder[[]web.Question]() + recorder := test.NewJSONResponseRecorder[web.QuestionList]() s.server.ServeHTTP(recorder, req) require.Equal(t, tc.wantCode, recorder.Code) assert.Equal(t, tc.wantResp, recorder.MustScan()) diff --git a/internal/question/internal/integration/set_handler_test.go b/internal/question/internal/integration/set_handler_test.go index 7d446db3..927bd967 100644 --- a/internal/question/internal/integration/set_handler_test.go +++ b/internal/question/internal/integration/set_handler_test.go @@ -643,7 +643,9 @@ func (s *SetHandlerTestSuite) TestQuestionSet_ListAllQuestionSets() { }, wantCode: 200, wantResp: test.Result[web.QuestionSetList]{ + Data: web.QuestionSetList{ + Total: 100, QuestionSets: []web.QuestionSet{ { Id: 100, @@ -686,6 +688,7 @@ func (s *SetHandlerTestSuite) TestQuestionSet_ListAllQuestionSets() { wantCode: 200, wantResp: test.Result[web.QuestionSetList]{ Data: web.QuestionSetList{ + Total: 100, QuestionSets: []web.QuestionSet{ { Id: 1, diff --git a/internal/question/internal/job/knowledge.go b/internal/question/internal/job/knowledge.go index 2c21ba47..81e2569a 100644 --- a/internal/question/internal/job/knowledge.go +++ b/internal/question/internal/job/knowledge.go @@ -84,7 +84,7 @@ func (s *KnowledgeJobStarter) Export(ctx ejob.Context, writer io.Writer) error { func (s *KnowledgeJobStarter) Batch(ctx ejob.Context, offset, limit int, writer *csv.Writer) (int, error) { batchCtx, cancel := context.WithTimeout(ctx.Ctx, time.Second*3) defer cancel() - ques, err := s.svc.PubList(batchCtx, offset, limit) + _, ques, err := s.svc.PubList(batchCtx, offset, limit) if err != nil { return 0, err } diff --git a/internal/question/internal/repository/dao/question.go b/internal/question/internal/repository/dao/question.go index 57a6607a..30696f6b 100644 --- a/internal/question/internal/repository/dao/question.go +++ b/internal/question/internal/repository/dao/question.go @@ -39,7 +39,7 @@ type QuestionDAO interface { // 线上库 API PubList(ctx context.Context, offset int, limit int, biz string) ([]PublishQuestion, error) - PubCount(ctx context.Context) (int64, error) + PubCount(ctx context.Context, biz string) (int64, error) GetPubByID(ctx context.Context, qid int64) (PublishQuestion, []PublishAnswerElement, error) GetPubByIDs(ctx context.Context, qids []int64) ([]PublishQuestion, error) NotInTotal(ctx context.Context, ids []int64) (int64, error) @@ -192,12 +192,13 @@ func (g *GORMQuestionDAO) PubList(ctx context.Context, offset int, limit int, bi return res, err } -func (g *GORMQuestionDAO) PubCount(ctx context.Context) (int64, error) { +func (g *GORMQuestionDAO) PubCount(ctx context.Context, biz string) (int64, error) { var res int64 - err := g.db.WithContext(ctx).Model(&PublishQuestion{}).Select("COUNT(id)").Count(&res).Error + err := g.db.WithContext(ctx). + Where("biz = ?", biz). + Model(&PublishQuestion{}).Select("COUNT(id)").Count(&res).Error return res, err } - func (g *GORMQuestionDAO) GetByID(ctx context.Context, id int64) (Question, []AnswerElement, error) { var q Question db := g.db.WithContext(ctx) diff --git a/internal/question/internal/repository/dao/question_set.go b/internal/question/internal/repository/dao/question_set.go index 91e7d186..d962b7d4 100644 --- a/internal/question/internal/repository/dao/question_set.go +++ b/internal/question/internal/repository/dao/question_set.go @@ -30,7 +30,7 @@ type QuestionSetDAO interface { GetQuestionsByID(ctx context.Context, id int64) ([]Question, error) UpdateQuestionsByID(ctx context.Context, id int64, qids []int64) error - + CountByBiz(ctx context.Context, biz string) (int64, error) Count(ctx context.Context) (int64, error) List(ctx context.Context, offset, limit int) ([]QuestionSet, error) UpdateNonZero(ctx context.Context, set QuestionSet) error @@ -45,6 +45,15 @@ type GORMQuestionSetDAO struct { db *egorm.Component } +func (g *GORMQuestionSetDAO) CountByBiz(ctx context.Context, biz string) (int64, error) { + var res int64 + db := g.db.WithContext(ctx).Model(&QuestionSet{}) + err := db.Select("COUNT(id)"). + Where("biz = ?", biz). + Count(&res).Error + return res, err +} + func (g *GORMQuestionSetDAO) GetByIDsWithQuestions(ctx context.Context, ids []int64) ([]QuestionSet, map[int64][]Question, error) { var sets []QuestionSet db := g.db.WithContext(ctx) diff --git a/internal/question/internal/repository/question.go b/internal/question/internal/repository/question.go index f551e05e..b1448e04 100644 --- a/internal/question/internal/repository/question.go +++ b/internal/question/internal/repository/question.go @@ -34,6 +34,7 @@ type Repository interface { PubList(ctx context.Context, offset int, limit int, biz string) ([]domain.Question, error) // Sync 保存到制作库,而后同步到线上库 Sync(ctx context.Context, que *domain.Question) (int64, error) + PubCount(ctx context.Context, biz string) (int64, error) List(ctx context.Context, offset int, limit int) ([]domain.Question, error) Total(ctx context.Context) (int64, error) Update(ctx context.Context, question *domain.Question) error @@ -59,6 +60,10 @@ type CachedRepository struct { logger *elog.Component } +func (c *CachedRepository) PubCount(ctx context.Context, biz string) (int64, error) { + return c.dao.PubCount(ctx, biz) +} + func (c *CachedRepository) QuestionIds(ctx context.Context) ([]int64, error) { return c.dao.Ids(ctx) } diff --git a/internal/question/internal/repository/question_set.go b/internal/question/internal/repository/question_set.go index d39df6b0..68f59e88 100644 --- a/internal/question/internal/repository/question_set.go +++ b/internal/question/internal/repository/question_set.go @@ -35,6 +35,7 @@ type QuestionSetRepository interface { GetByIDsWithQuestion(ctx context.Context, ids []int64) ([]domain.QuestionSet, error) ListByBiz(ctx context.Context, offset, limit int, biz string) ([]domain.QuestionSet, error) GetByBiz(ctx context.Context, biz string, bizId int64) (domain.QuestionSet, error) + CountByBiz(ctx context.Context, biz string) (int64, error) } var _ QuestionSetRepository = &questionSetRepository{} @@ -44,6 +45,9 @@ type questionSetRepository struct { logger *elog.Component } +func (q *questionSetRepository) CountByBiz(ctx context.Context, biz string) (int64, error) { + return q.dao.CountByBiz(ctx, biz) +} func (q *questionSetRepository) GetByIDsWithQuestion(ctx context.Context, ids []int64) ([]domain.QuestionSet, error) { qsets, questionMap, err := q.dao.GetByIDsWithQuestions(ctx, ids) if err != nil { diff --git a/internal/question/internal/service/question.go b/internal/question/internal/service/question.go index b35e5fb4..475647cb 100644 --- a/internal/question/internal/service/question.go +++ b/internal/question/internal/service/question.go @@ -40,7 +40,7 @@ type Service interface { Delete(ctx context.Context, qid int64) error // PubList 只会返回八股文的数据 - PubList(ctx context.Context, offset int, limit int) ([]domain.Question, error) + PubList(ctx context.Context, offset int, limit int) (int64, []domain.Question, error) // GetPubByIDs 目前只会获取基础信息,也就是不包括答案在内的信息 GetPubByIDs(ctx context.Context, ids []int64) ([]domain.Question, error) PubDetail(ctx context.Context, qid int64) (domain.Question, error) @@ -103,8 +103,23 @@ func (s *service) List(ctx context.Context, offset int, limit int) ([]domain.Que return qs, total, eg.Wait() } -func (s *service) PubList(ctx context.Context, offset int, limit int) ([]domain.Question, error) { - return s.repo.PubList(ctx, offset, limit, domain.DefaultBiz) +func (s *service) PubList(ctx context.Context, offset int, limit int) (int64, []domain.Question, error) { + var ( + eg errgroup.Group + qs []domain.Question + total int64 + ) + eg.Go(func() error { + var err error + qs, err = s.repo.PubList(ctx, offset, limit, domain.DefaultBiz) + return err + }) + eg.Go(func() error { + var err error + total, err = s.repo.PubCount(ctx, domain.DefaultBiz) + return err + }) + return total, qs, eg.Wait() } func (s *service) Save(ctx context.Context, question *domain.Question) (int64, error) { diff --git a/internal/question/internal/service/question_set.go b/internal/question/internal/service/question_set.go index 8b924be1..af3f6aa3 100644 --- a/internal/question/internal/service/question_set.go +++ b/internal/question/internal/service/question_set.go @@ -35,7 +35,7 @@ type QuestionSetService interface { Save(ctx context.Context, set domain.QuestionSet) (int64, error) UpdateQuestions(ctx context.Context, set domain.QuestionSet) error List(ctx context.Context, offset, limit int) ([]domain.QuestionSet, int64, error) - ListDefault(ctx context.Context, offset, limit int) ([]domain.QuestionSet, error) + ListDefault(ctx context.Context, offset, limit int) ([]domain.QuestionSet, int64, error) Detail(ctx context.Context, id int64) (domain.QuestionSet, error) GetByIds(ctx context.Context, ids []int64) ([]domain.QuestionSet, error) DetailByBiz(ctx context.Context, biz string, bizId int64) (domain.QuestionSet, error) @@ -75,8 +75,24 @@ func (q *questionSetService) DetailByBiz(ctx context.Context, biz string, bizId return q.repo.GetByBiz(ctx, biz, bizId) } -func (q *questionSetService) ListDefault(ctx context.Context, offset, limit int) ([]domain.QuestionSet, error) { - return q.repo.ListByBiz(ctx, offset, limit, domain.DefaultBiz) +func (q *questionSetService) ListDefault(ctx context.Context, offset, limit int) ([]domain.QuestionSet, int64, error) { + var ( + eg errgroup.Group + qs []domain.QuestionSet + total int64 + ) + eg.Go(func() error { + var err error + qs, err = q.repo.ListByBiz(ctx, offset, limit, domain.DefaultBiz) + return err + }) + eg.Go(func() error { + var err error + total, err = q.repo.CountByBiz(ctx, domain.DefaultBiz) + return err + }) + return qs, total, eg.Wait() + } func (q *questionSetService) GetByIds(ctx context.Context, ids []int64) ([]domain.QuestionSet, error) { diff --git a/internal/question/internal/web/handler.go b/internal/question/internal/web/handler.go index ed80c1d3..c6be43ea 100644 --- a/internal/question/internal/web/handler.go +++ b/internal/question/internal/web/handler.go @@ -116,7 +116,7 @@ func (h *Handler) PubDetail(ctx *ginx.Context, } func (h *Handler) PubList(ctx *ginx.Context, req Page) (ginx.Result, error) { - data, err := h.svc.PubList(ctx, req.Offset, req.Limit) + count, data, err := h.svc.PubList(ctx, req.Offset, req.Limit) if err != nil { return systemErrorResult, err } @@ -138,9 +138,15 @@ func (h *Handler) PubList(ctx *ginx.Context, req Page) (ginx.Result, error) { // 获得数据 return ginx.Result{ - // 在 C 端是下拉刷新 - Data: slice.Map(data, func(idx int, src domain.Question) Question { + Data: h.toQuestionList(data, count, intrs), + }, nil +} + +func (h *Handler) toQuestionList(data []domain.Question, cnt int64, intrs map[int64]interactive.Interactive) QuestionList { + return QuestionList{ + Total: cnt, + Questions: slice.Map(data, func(idx int, src domain.Question) Question { return newQuestion(src, intrs[src.Id]) }), - }, nil + } } diff --git a/internal/question/internal/web/question_set_handler.go b/internal/question/internal/web/question_set_handler.go index a07d226a..fe0c0f7c 100644 --- a/internal/question/internal/web/question_set_handler.go +++ b/internal/question/internal/web/question_set_handler.go @@ -63,7 +63,7 @@ func (h *QuestionSetHandler) PrivateRoutes(server *gin.Engine) { // ListQuestionSets 展示个人题集 func (h *QuestionSetHandler) ListQuestionSets(ctx *ginx.Context, req Page) (ginx.Result, error) { - data, err := h.svc.ListDefault(ctx, req.Offset, req.Limit) + data, count, err := h.svc.ListDefault(ctx, req.Offset, req.Limit) if err != nil { return systemErrorResult, err } @@ -84,6 +84,7 @@ func (h *QuestionSetHandler) ListQuestionSets(ctx *ginx.Context, req Page) (ginx } return ginx.Result{ Data: QuestionSetList{ + Total: count, QuestionSets: slice.Map(data, func(idx int, src domain.QuestionSet) QuestionSet { qs := newQuestionSet(src) qs.Interactive = newInteractive(intrs[src.Id]) diff --git a/internal/question/mocks/question.mock.go b/internal/question/mocks/question.mock.go index 8c025f43..af509b4b 100644 --- a/internal/question/mocks/question.mock.go +++ b/internal/question/mocks/question.mock.go @@ -5,6 +5,7 @@ // // mockgen -source=./question.go -destination=../../mocks/question.mock.go -package=quemocks -typed=true Service // + // Package quemocks is a generated GoMock package. package quemocks @@ -48,31 +49,31 @@ func (m *MockService) Delete(ctx context.Context, qid int64) error { } // Delete indicates an expected call of Delete. -func (mr *MockServiceMockRecorder) Delete(ctx, qid any) *ServiceDeleteCall { +func (mr *MockServiceMockRecorder) Delete(ctx, qid any) *MockServiceDeleteCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockService)(nil).Delete), ctx, qid) - return &ServiceDeleteCall{Call: call} + return &MockServiceDeleteCall{Call: call} } -// ServiceDeleteCall wrap *gomock.Call -type ServiceDeleteCall struct { +// MockServiceDeleteCall wrap *gomock.Call +type MockServiceDeleteCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServiceDeleteCall) Return(arg0 error) *ServiceDeleteCall { +func (c *MockServiceDeleteCall) Return(arg0 error) *MockServiceDeleteCall { c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *ServiceDeleteCall) Do(f func(context.Context, int64) error) *ServiceDeleteCall { +func (c *MockServiceDeleteCall) Do(f func(context.Context, int64) error) *MockServiceDeleteCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServiceDeleteCall) DoAndReturn(f func(context.Context, int64) error) *ServiceDeleteCall { +func (c *MockServiceDeleteCall) DoAndReturn(f func(context.Context, int64) error) *MockServiceDeleteCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -87,31 +88,31 @@ func (m *MockService) Detail(ctx context.Context, qid int64) (domain.Question, e } // Detail indicates an expected call of Detail. -func (mr *MockServiceMockRecorder) Detail(ctx, qid any) *ServiceDetailCall { +func (mr *MockServiceMockRecorder) Detail(ctx, qid any) *MockServiceDetailCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Detail", reflect.TypeOf((*MockService)(nil).Detail), ctx, qid) - return &ServiceDetailCall{Call: call} + return &MockServiceDetailCall{Call: call} } -// ServiceDetailCall wrap *gomock.Call -type ServiceDetailCall struct { +// MockServiceDetailCall wrap *gomock.Call +type MockServiceDetailCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServiceDetailCall) Return(arg0 domain.Question, arg1 error) *ServiceDetailCall { +func (c *MockServiceDetailCall) Return(arg0 domain.Question, arg1 error) *MockServiceDetailCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *ServiceDetailCall) Do(f func(context.Context, int64) (domain.Question, error)) *ServiceDetailCall { +func (c *MockServiceDetailCall) Do(f func(context.Context, int64) (domain.Question, error)) *MockServiceDetailCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServiceDetailCall) DoAndReturn(f func(context.Context, int64) (domain.Question, error)) *ServiceDetailCall { +func (c *MockServiceDetailCall) DoAndReturn(f func(context.Context, int64) (domain.Question, error)) *MockServiceDetailCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -126,31 +127,31 @@ func (m *MockService) GetPubByIDs(ctx context.Context, ids []int64) ([]domain.Qu } // GetPubByIDs indicates an expected call of GetPubByIDs. -func (mr *MockServiceMockRecorder) GetPubByIDs(ctx, ids any) *ServiceGetPubByIDsCall { +func (mr *MockServiceMockRecorder) GetPubByIDs(ctx, ids any) *MockServiceGetPubByIDsCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPubByIDs", reflect.TypeOf((*MockService)(nil).GetPubByIDs), ctx, ids) - return &ServiceGetPubByIDsCall{Call: call} + return &MockServiceGetPubByIDsCall{Call: call} } -// ServiceGetPubByIDsCall wrap *gomock.Call -type ServiceGetPubByIDsCall struct { +// MockServiceGetPubByIDsCall wrap *gomock.Call +type MockServiceGetPubByIDsCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServiceGetPubByIDsCall) Return(arg0 []domain.Question, arg1 error) *ServiceGetPubByIDsCall { +func (c *MockServiceGetPubByIDsCall) Return(arg0 []domain.Question, arg1 error) *MockServiceGetPubByIDsCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *ServiceGetPubByIDsCall) Do(f func(context.Context, []int64) ([]domain.Question, error)) *ServiceGetPubByIDsCall { +func (c *MockServiceGetPubByIDsCall) Do(f func(context.Context, []int64) ([]domain.Question, error)) *MockServiceGetPubByIDsCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServiceGetPubByIDsCall) DoAndReturn(f func(context.Context, []int64) ([]domain.Question, error)) *ServiceGetPubByIDsCall { +func (c *MockServiceGetPubByIDsCall) DoAndReturn(f func(context.Context, []int64) ([]domain.Question, error)) *MockServiceGetPubByIDsCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -166,31 +167,31 @@ func (m *MockService) List(ctx context.Context, offset, limit int) ([]domain.Que } // List indicates an expected call of List. -func (mr *MockServiceMockRecorder) List(ctx, offset, limit any) *ServiceListCall { +func (mr *MockServiceMockRecorder) List(ctx, offset, limit any) *MockServiceListCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockService)(nil).List), ctx, offset, limit) - return &ServiceListCall{Call: call} + return &MockServiceListCall{Call: call} } -// ServiceListCall wrap *gomock.Call -type ServiceListCall struct { +// MockServiceListCall wrap *gomock.Call +type MockServiceListCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServiceListCall) Return(arg0 []domain.Question, arg1 int64, arg2 error) *ServiceListCall { +func (c *MockServiceListCall) Return(arg0 []domain.Question, arg1 int64, arg2 error) *MockServiceListCall { c.Call = c.Call.Return(arg0, arg1, arg2) return c } // Do rewrite *gomock.Call.Do -func (c *ServiceListCall) Do(f func(context.Context, int, int) ([]domain.Question, int64, error)) *ServiceListCall { +func (c *MockServiceListCall) Do(f func(context.Context, int, int) ([]domain.Question, int64, error)) *MockServiceListCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServiceListCall) DoAndReturn(f func(context.Context, int, int) ([]domain.Question, int64, error)) *ServiceListCall { +func (c *MockServiceListCall) DoAndReturn(f func(context.Context, int, int) ([]domain.Question, int64, error)) *MockServiceListCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -205,70 +206,71 @@ func (m *MockService) PubDetail(ctx context.Context, qid int64) (domain.Question } // PubDetail indicates an expected call of PubDetail. -func (mr *MockServiceMockRecorder) PubDetail(ctx, qid any) *ServicePubDetailCall { +func (mr *MockServiceMockRecorder) PubDetail(ctx, qid any) *MockServicePubDetailCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PubDetail", reflect.TypeOf((*MockService)(nil).PubDetail), ctx, qid) - return &ServicePubDetailCall{Call: call} + return &MockServicePubDetailCall{Call: call} } -// ServicePubDetailCall wrap *gomock.Call -type ServicePubDetailCall struct { +// MockServicePubDetailCall wrap *gomock.Call +type MockServicePubDetailCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServicePubDetailCall) Return(arg0 domain.Question, arg1 error) *ServicePubDetailCall { +func (c *MockServicePubDetailCall) Return(arg0 domain.Question, arg1 error) *MockServicePubDetailCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *ServicePubDetailCall) Do(f func(context.Context, int64) (domain.Question, error)) *ServicePubDetailCall { +func (c *MockServicePubDetailCall) Do(f func(context.Context, int64) (domain.Question, error)) *MockServicePubDetailCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServicePubDetailCall) DoAndReturn(f func(context.Context, int64) (domain.Question, error)) *ServicePubDetailCall { +func (c *MockServicePubDetailCall) DoAndReturn(f func(context.Context, int64) (domain.Question, error)) *MockServicePubDetailCall { c.Call = c.Call.DoAndReturn(f) return c } // PubList mocks base method. -func (m *MockService) PubList(ctx context.Context, offset, limit int) ([]domain.Question, error) { +func (m *MockService) PubList(ctx context.Context, offset, limit int) (int64, []domain.Question, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "PubList", ctx, offset, limit) - ret0, _ := ret[0].([]domain.Question) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret0, _ := ret[0].(int64) + ret1, _ := ret[1].([]domain.Question) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } // PubList indicates an expected call of PubList. -func (mr *MockServiceMockRecorder) PubList(ctx, offset, limit any) *ServicePubListCall { +func (mr *MockServiceMockRecorder) PubList(ctx, offset, limit any) *MockServicePubListCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PubList", reflect.TypeOf((*MockService)(nil).PubList), ctx, offset, limit) - return &ServicePubListCall{Call: call} + return &MockServicePubListCall{Call: call} } -// ServicePubListCall wrap *gomock.Call -type ServicePubListCall struct { +// MockServicePubListCall wrap *gomock.Call +type MockServicePubListCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServicePubListCall) Return(arg0 []domain.Question, arg1 error) *ServicePubListCall { - c.Call = c.Call.Return(arg0, arg1) +func (c *MockServicePubListCall) Return(arg0 int64, arg1 []domain.Question, arg2 error) *MockServicePubListCall { + c.Call = c.Call.Return(arg0, arg1, arg2) return c } // Do rewrite *gomock.Call.Do -func (c *ServicePubListCall) Do(f func(context.Context, int, int) ([]domain.Question, error)) *ServicePubListCall { +func (c *MockServicePubListCall) Do(f func(context.Context, int, int) (int64, []domain.Question, error)) *MockServicePubListCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServicePubListCall) DoAndReturn(f func(context.Context, int, int) ([]domain.Question, error)) *ServicePubListCall { +func (c *MockServicePubListCall) DoAndReturn(f func(context.Context, int, int) (int64, []domain.Question, error)) *MockServicePubListCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -283,31 +285,31 @@ func (m *MockService) Publish(ctx context.Context, que *domain.Question) (int64, } // Publish indicates an expected call of Publish. -func (mr *MockServiceMockRecorder) Publish(ctx, que any) *ServicePublishCall { +func (mr *MockServiceMockRecorder) Publish(ctx, que any) *MockServicePublishCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Publish", reflect.TypeOf((*MockService)(nil).Publish), ctx, que) - return &ServicePublishCall{Call: call} + return &MockServicePublishCall{Call: call} } -// ServicePublishCall wrap *gomock.Call -type ServicePublishCall struct { +// MockServicePublishCall wrap *gomock.Call +type MockServicePublishCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServicePublishCall) Return(arg0 int64, arg1 error) *ServicePublishCall { +func (c *MockServicePublishCall) Return(arg0 int64, arg1 error) *MockServicePublishCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *ServicePublishCall) Do(f func(context.Context, *domain.Question) (int64, error)) *ServicePublishCall { +func (c *MockServicePublishCall) Do(f func(context.Context, *domain.Question) (int64, error)) *MockServicePublishCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServicePublishCall) DoAndReturn(f func(context.Context, *domain.Question) (int64, error)) *ServicePublishCall { +func (c *MockServicePublishCall) DoAndReturn(f func(context.Context, *domain.Question) (int64, error)) *MockServicePublishCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -322,31 +324,31 @@ func (m *MockService) Save(ctx context.Context, question *domain.Question) (int6 } // Save indicates an expected call of Save. -func (mr *MockServiceMockRecorder) Save(ctx, question any) *ServiceSaveCall { +func (mr *MockServiceMockRecorder) Save(ctx, question any) *MockServiceSaveCall { mr.mock.ctrl.T.Helper() call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Save", reflect.TypeOf((*MockService)(nil).Save), ctx, question) - return &ServiceSaveCall{Call: call} + return &MockServiceSaveCall{Call: call} } -// ServiceSaveCall wrap *gomock.Call -type ServiceSaveCall struct { +// MockServiceSaveCall wrap *gomock.Call +type MockServiceSaveCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *ServiceSaveCall) Return(arg0 int64, arg1 error) *ServiceSaveCall { +func (c *MockServiceSaveCall) Return(arg0 int64, arg1 error) *MockServiceSaveCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *ServiceSaveCall) Do(f func(context.Context, *domain.Question) (int64, error)) *ServiceSaveCall { +func (c *MockServiceSaveCall) Do(f func(context.Context, *domain.Question) (int64, error)) *MockServiceSaveCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *ServiceSaveCall) DoAndReturn(f func(context.Context, *domain.Question) (int64, error)) *ServiceSaveCall { +func (c *MockServiceSaveCall) DoAndReturn(f func(context.Context, *domain.Question) (int64, error)) *MockServiceSaveCall { c.Call = c.Call.DoAndReturn(f) return c } diff --git a/internal/question/mocks/quetion_set.mock.go b/internal/question/mocks/quetion_set.mock.go index 5a90fadb..5a5d1448 100644 --- a/internal/question/mocks/quetion_set.mock.go +++ b/internal/question/mocks/quetion_set.mock.go @@ -277,12 +277,13 @@ func (c *MockQuestionSetServiceListCall) DoAndReturn(f func(context.Context, int } // ListDefault mocks base method. -func (m *MockQuestionSetService) ListDefault(ctx context.Context, offset, limit int) ([]domain.QuestionSet, error) { +func (m *MockQuestionSetService) ListDefault(ctx context.Context, offset, limit int) ([]domain.QuestionSet, int64, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ListDefault", ctx, offset, limit) ret0, _ := ret[0].([]domain.QuestionSet) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret1, _ := ret[1].(int64) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 } // ListDefault indicates an expected call of ListDefault. @@ -298,19 +299,19 @@ type MockQuestionSetServiceListDefaultCall struct { } // Return rewrite *gomock.Call.Return -func (c *MockQuestionSetServiceListDefaultCall) Return(arg0 []domain.QuestionSet, arg1 error) *MockQuestionSetServiceListDefaultCall { - c.Call = c.Call.Return(arg0, arg1) +func (c *MockQuestionSetServiceListDefaultCall) Return(arg0 []domain.QuestionSet, arg1 int64, arg2 error) *MockQuestionSetServiceListDefaultCall { + c.Call = c.Call.Return(arg0, arg1, arg2) return c } // Do rewrite *gomock.Call.Do -func (c *MockQuestionSetServiceListDefaultCall) Do(f func(context.Context, int, int) ([]domain.QuestionSet, error)) *MockQuestionSetServiceListDefaultCall { +func (c *MockQuestionSetServiceListDefaultCall) Do(f func(context.Context, int, int) ([]domain.QuestionSet, int64, error)) *MockQuestionSetServiceListDefaultCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockQuestionSetServiceListDefaultCall) DoAndReturn(f func(context.Context, int, int) ([]domain.QuestionSet, error)) *MockQuestionSetServiceListDefaultCall { +func (c *MockQuestionSetServiceListDefaultCall) DoAndReturn(f func(context.Context, int, int) ([]domain.QuestionSet, int64, error)) *MockQuestionSetServiceListDefaultCall { c.Call = c.Call.DoAndReturn(f) return c }