Skip to content

Commit

Permalink
完成路线图功能
Browse files Browse the repository at this point in the history
  • Loading branch information
flycash committed Jul 8, 2024
1 parent 669c0ec commit 829d15a
Show file tree
Hide file tree
Showing 36 changed files with 2,257 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@
- credit - 10
- project - 11
- marketing - 12
- roadmap - 13 # 路线图
12 changes: 7 additions & 5 deletions internal/question/internal/repository/dao/question_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@ package dao

import (
"context"
"errors"
"time"

"github.com/ego-component/egorm"
"gorm.io/gorm"
)

var (
ErrInvalidQuestionID = errors.New("问题ID非法")
)

type QuestionSetDAO interface {
Create(ctx context.Context, qs QuestionSet) (int64, error)
GetByID(ctx context.Context, id int64) (QuestionSet, error)
Expand All @@ -37,12 +32,19 @@ type QuestionSetDAO interface {
Count(ctx context.Context) (int64, error)
List(ctx context.Context, offset, limit int) ([]QuestionSet, error)
UpdateNonZero(ctx context.Context, set QuestionSet) error
GetByIDs(ctx context.Context, ids []int64) ([]QuestionSet, error)
}

type GORMQuestionSetDAO struct {
db *egorm.Component
}

func (g *GORMQuestionSetDAO) GetByIDs(ctx context.Context, ids []int64) ([]QuestionSet, error) {
var res []QuestionSet
err := g.db.WithContext(ctx).Where("id IN ?", ids).Find(&res).Error
return res, err
}

func (g *GORMQuestionSetDAO) UpdateNonZero(ctx context.Context, set QuestionSet) error {
set.Utime = time.Now().UnixMilli()
return g.db.WithContext(ctx).Where("id = ?", set.Id).Updates(set).Error
Expand Down
8 changes: 8 additions & 0 deletions internal/question/internal/repository/question_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ type QuestionSetRepository interface {
Total(ctx context.Context) (int64, error)
List(ctx context.Context, offset int, limit int) ([]domain.QuestionSet, error)
UpdateNonZero(ctx context.Context, set domain.QuestionSet) error
GetByIDs(ctx context.Context, ids []int64) ([]domain.QuestionSet, error)
}

type questionSetRepository struct {
dao dao.QuestionSetDAO
logger *elog.Component
}

func (q *questionSetRepository) GetByIDs(ctx context.Context, ids []int64) ([]domain.QuestionSet, error) {
qs, err := q.dao.GetByIDs(ctx, ids)
return slice.Map(qs, func(idx int, src dao.QuestionSet) domain.QuestionSet {
return q.toDomainQuestionSet(src)
}), err
}

func (q *questionSetRepository) UpdateNonZero(ctx context.Context, set domain.QuestionSet) error {
return q.dao.UpdateNonZero(ctx, q.toEntityQuestionSet(set))
}
Expand Down
6 changes: 6 additions & 0 deletions internal/question/internal/service/question_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import (
"golang.org/x/sync/errgroup"
)

//go:generate mockgen -source=./question_set.go -destination=../../mocks/quetion_set.mock.go -package=quemocks -typed=true QuestionSetService
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)
Detail(ctx context.Context, id int64) (domain.QuestionSet, error)
GetByIds(ctx context.Context, ids []int64) ([]domain.QuestionSet, error)
}

type questionSetService struct {
Expand All @@ -41,6 +43,10 @@ type questionSetService struct {
syncTimeout time.Duration
}

func (q *questionSetService) GetByIds(ctx context.Context, ids []int64) ([]domain.QuestionSet, error) {
return q.repo.GetByIDs(ctx, ids)
}

func NewQuestionSetService(repo repository.QuestionSetRepository,
intrProducer event.InteractiveEventProducer,
producer event.SyncDataToSearchEventProducer) QuestionSetService {
Expand Down
235 changes: 235 additions & 0 deletions internal/question/mocks/quetion_set.mock.go

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

7 changes: 4 additions & 3 deletions internal/question/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
package baguwen

type Module struct {
Svc Service
Hdl *Handler
QsHdl *QuestionSetHandler
Svc Service
SetSvc QuestionSetService
Hdl *Handler
QsHdl *QuestionSetHandler
}
2 changes: 2 additions & 0 deletions internal/question/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ type Handler = web.Handler
type QuestionSetHandler = web.QuestionSetHandler

type Service = service.Service
type QuestionSetService = service.QuestionSetService
type Question = domain.Question
type QuestionSet = domain.QuestionSet
13 changes: 7 additions & 6 deletions internal/question/wire_gen.go

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

Loading

0 comments on commit 829d15a

Please sign in to comment.