diff --git a/dal/dal.go b/dal/dal.go index 3acc8a5..aa33fab 100644 --- a/dal/dal.go +++ b/dal/dal.go @@ -133,9 +133,10 @@ func (d *DAL) Init() error { } type AmoDal struct { - conn *sql.DB - queries *sqlcgen.Queries - AmoRepo *amo.AmoRepository + conn *sql.DB + queries *sqlcgen.Queries + AmoRepo *amo.AmoRepository + QuestionRepo *question.QuestionRepository } func NewAmoDal(ctx context.Context, cred string) (*AmoDal, error) { @@ -158,10 +159,16 @@ func NewAmoDal(ctx context.Context, cred string) (*AmoDal, error) { Pool: pool, }) + questionRepo := question.NewQuestionRepository(question.Deps{ + Queries: queries, + Pool: pool, + }) + return &AmoDal{ - conn: pool, - queries: queries, - AmoRepo: amoRepo, + conn: pool, + queries: queries, + AmoRepo: amoRepo, + QuestionRepo: questionRepo, }, nil } diff --git a/repository/question/question.go b/repository/question/question.go index 866a35b..88e33e0 100644 --- a/repository/question/question.go +++ b/repository/question/question.go @@ -245,12 +245,12 @@ func (r *QuestionRepository) UpdateQuestion(ctx context.Context, record model.Qu params = append(params, record.Required, record.Version, record.Id) var placeholders []any - for i:=1;i<=len(params);i++ { + for i := 1; i <= len(params); i++ { placeholders = append(placeholders, i) } query = fmt.Sprintf(query, placeholders...) - + _, err := r.pool.ExecContext(ctx, query, params...) return err } @@ -455,3 +455,33 @@ func (r *QuestionRepository) ForSortingResults(ctx context.Context, allAnswers [ 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 +}