add new que repo method, and add in amodal struct que repo
This commit is contained in:
parent
17d5622ed1
commit
5192490c05
19
dal/dal.go
19
dal/dal.go
@ -133,9 +133,10 @@ func (d *DAL) Init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AmoDal struct {
|
type AmoDal struct {
|
||||||
conn *sql.DB
|
conn *sql.DB
|
||||||
queries *sqlcgen.Queries
|
queries *sqlcgen.Queries
|
||||||
AmoRepo *amo.AmoRepository
|
AmoRepo *amo.AmoRepository
|
||||||
|
QuestionRepo *question.QuestionRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAmoDal(ctx context.Context, cred string) (*AmoDal, error) {
|
func NewAmoDal(ctx context.Context, cred string) (*AmoDal, error) {
|
||||||
@ -158,10 +159,16 @@ func NewAmoDal(ctx context.Context, cred string) (*AmoDal, error) {
|
|||||||
Pool: pool,
|
Pool: pool,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
questionRepo := question.NewQuestionRepository(question.Deps{
|
||||||
|
Queries: queries,
|
||||||
|
Pool: pool,
|
||||||
|
})
|
||||||
|
|
||||||
return &AmoDal{
|
return &AmoDal{
|
||||||
conn: pool,
|
conn: pool,
|
||||||
queries: queries,
|
queries: queries,
|
||||||
AmoRepo: amoRepo,
|
AmoRepo: amoRepo,
|
||||||
|
QuestionRepo: questionRepo,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,12 +245,12 @@ func (r *QuestionRepository) UpdateQuestion(ctx context.Context, record model.Qu
|
|||||||
params = append(params, record.Required, record.Version, record.Id)
|
params = append(params, record.Required, record.Version, record.Id)
|
||||||
|
|
||||||
var placeholders []any
|
var placeholders []any
|
||||||
for i:=1;i<=len(params);i++ {
|
for i := 1; i <= len(params); i++ {
|
||||||
placeholders = append(placeholders, i)
|
placeholders = append(placeholders, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
query = fmt.Sprintf(query, placeholders...)
|
query = fmt.Sprintf(query, placeholders...)
|
||||||
|
|
||||||
_, err := r.pool.ExecContext(ctx, query, params...)
|
_, err := r.pool.ExecContext(ctx, query, params...)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -455,3 +455,33 @@ func (r *QuestionRepository) ForSortingResults(ctx context.Context, allAnswers [
|
|||||||
|
|
||||||
return sortedAllAnswers, nil
|
return sortedAllAnswers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *QuestionRepository) GetQuestionListByIDs(ctx context.Context, ids []int32) ([]model.Question, error) {
|
||||||
|
rows, err := r.queries.GetQuestionListByIDs(ctx, ids)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var questions []model.Question
|
||||||
|
for _, row := range rows {
|
||||||
|
question := model.Question{
|
||||||
|
Id: uint64(row.ID),
|
||||||
|
QuizId: uint64(row.QuizID),
|
||||||
|
Title: row.Title,
|
||||||
|
Description: row.Description.String,
|
||||||
|
Type: string(row.Questiontype.([]byte)),
|
||||||
|
Required: row.Required.Bool,
|
||||||
|
Deleted: row.Deleted.Bool,
|
||||||
|
Page: int(row.Page.Int16),
|
||||||
|
Content: row.Content.String,
|
||||||
|
Version: int(row.Version.Int16),
|
||||||
|
ParentIds: row.ParentIds,
|
||||||
|
CreatedAt: row.CreatedAt.Time,
|
||||||
|
UpdatedAt: row.UpdatedAt.Time,
|
||||||
|
}
|
||||||
|
|
||||||
|
questions = append(questions, question)
|
||||||
|
}
|
||||||
|
|
||||||
|
return questions, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user