Skip to content

Commit 50e83a1

Browse files
committed
完成路线图功能
1 parent 97ba87d commit 50e83a1

File tree

36 files changed

+2257
-21
lines changed

36 files changed

+2257
-21
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@
4949
- credit - 10
5050
- project - 11
5151
- marketing - 12
52+
- roadmap - 13 # 路线图

internal/question/internal/repository/dao/question_set.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,12 @@ package dao
1616

1717
import (
1818
"context"
19-
"errors"
2019
"time"
2120

2221
"github.com/ego-component/egorm"
2322
"gorm.io/gorm"
2423
)
2524

26-
var (
27-
ErrInvalidQuestionID = errors.New("问题ID非法")
28-
)
29-
3025
type QuestionSetDAO interface {
3126
Create(ctx context.Context, qs QuestionSet) (int64, error)
3227
GetByID(ctx context.Context, id int64) (QuestionSet, error)
@@ -37,12 +32,19 @@ type QuestionSetDAO interface {
3732
Count(ctx context.Context) (int64, error)
3833
List(ctx context.Context, offset, limit int) ([]QuestionSet, error)
3934
UpdateNonZero(ctx context.Context, set QuestionSet) error
35+
GetByIDs(ctx context.Context, ids []int64) ([]QuestionSet, error)
4036
}
4137

4238
type GORMQuestionSetDAO struct {
4339
db *egorm.Component
4440
}
4541

42+
func (g *GORMQuestionSetDAO) GetByIDs(ctx context.Context, ids []int64) ([]QuestionSet, error) {
43+
var res []QuestionSet
44+
err := g.db.WithContext(ctx).Where("id IN ?", ids).Find(&res).Error
45+
return res, err
46+
}
47+
4648
func (g *GORMQuestionSetDAO) UpdateNonZero(ctx context.Context, set QuestionSet) error {
4749
set.Utime = time.Now().UnixMilli()
4850
return g.db.WithContext(ctx).Where("id = ?", set.Id).Updates(set).Error

internal/question/internal/repository/question_set.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,21 @@ type QuestionSetRepository interface {
3131
Total(ctx context.Context) (int64, error)
3232
List(ctx context.Context, offset int, limit int) ([]domain.QuestionSet, error)
3333
UpdateNonZero(ctx context.Context, set domain.QuestionSet) error
34+
GetByIDs(ctx context.Context, ids []int64) ([]domain.QuestionSet, error)
3435
}
3536

3637
type questionSetRepository struct {
3738
dao dao.QuestionSetDAO
3839
logger *elog.Component
3940
}
4041

42+
func (q *questionSetRepository) GetByIDs(ctx context.Context, ids []int64) ([]domain.QuestionSet, error) {
43+
qs, err := q.dao.GetByIDs(ctx, ids)
44+
return slice.Map(qs, func(idx int, src dao.QuestionSet) domain.QuestionSet {
45+
return q.toDomainQuestionSet(src)
46+
}), err
47+
}
48+
4149
func (q *questionSetRepository) UpdateNonZero(ctx context.Context, set domain.QuestionSet) error {
4250
return q.dao.UpdateNonZero(ctx, q.toEntityQuestionSet(set))
4351
}

internal/question/internal/service/question_set.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import (
2626
"golang.org/x/sync/errgroup"
2727
)
2828

29+
//go:generate mockgen -source=./question_set.go -destination=../../mocks/quetion_set.mock.go -package=quemocks -typed=true QuestionSetService
2930
type QuestionSetService interface {
3031
Save(ctx context.Context, set domain.QuestionSet) (int64, error)
3132
UpdateQuestions(ctx context.Context, set domain.QuestionSet) error
3233
List(ctx context.Context, offset, limit int) ([]domain.QuestionSet, int64, error)
3334
Detail(ctx context.Context, id int64) (domain.QuestionSet, error)
35+
GetByIds(ctx context.Context, ids []int64) ([]domain.QuestionSet, error)
3436
}
3537

3638
type questionSetService struct {
@@ -41,6 +43,10 @@ type questionSetService struct {
4143
syncTimeout time.Duration
4244
}
4345

46+
func (q *questionSetService) GetByIds(ctx context.Context, ids []int64) ([]domain.QuestionSet, error) {
47+
return q.repo.GetByIDs(ctx, ids)
48+
}
49+
4450
func NewQuestionSetService(repo repository.QuestionSetRepository,
4551
intrProducer event.InteractiveEventProducer,
4652
producer event.SyncDataToSearchEventProducer) QuestionSetService {

internal/question/mocks/quetion_set.mock.go

Lines changed: 235 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/question/module.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
package baguwen
1616

1717
type Module struct {
18-
Svc Service
19-
Hdl *Handler
20-
QsHdl *QuestionSetHandler
18+
Svc Service
19+
SetSvc QuestionSetService
20+
Hdl *Handler
21+
QsHdl *QuestionSetHandler
2122
}

internal/question/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ type Handler = web.Handler
2424
type QuestionSetHandler = web.QuestionSetHandler
2525

2626
type Service = service.Service
27+
type QuestionSetService = service.QuestionSetService
2728
type Question = domain.Question
29+
type QuestionSet = domain.QuestionSet

internal/question/wire_gen.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)