109 lines
2.7 KiB
Go
109 lines
2.7 KiB
Go
package repository
|
|
|
|
import (
|
|
dbgen "Yimaru-Backend/gen/db"
|
|
"Yimaru-Backend/internal/domain"
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
func (s *Store) CreatePracticeQuestion(
|
|
ctx context.Context,
|
|
practiceID int64,
|
|
question string,
|
|
questionVoicePrompt *string,
|
|
sampleAnswerVoicePrompt *string,
|
|
sampleAnswer *string,
|
|
tips *string,
|
|
qType string,
|
|
) (domain.PracticeQuestion, error) {
|
|
|
|
row, err := s.queries.CreatePracticeQuestion(ctx, dbgen.CreatePracticeQuestionParams{
|
|
PracticeID: practiceID,
|
|
Question: question,
|
|
QuestionVoicePrompt: pgtype.Text{String: *questionVoicePrompt},
|
|
SampleAnswerVoicePrompt: pgtype.Text{String: *sampleAnswerVoicePrompt},
|
|
SampleAnswer: pgtype.Text{String: *sampleAnswer},
|
|
Tips: pgtype.Text{String: *tips},
|
|
Type: qType,
|
|
})
|
|
if err != nil {
|
|
return domain.PracticeQuestion{}, err
|
|
}
|
|
|
|
return domain.PracticeQuestion{
|
|
ID: row.ID,
|
|
PracticeID: row.PracticeID,
|
|
Question: row.Question,
|
|
QuestionVoicePrompt: &row.QuestionVoicePrompt.String,
|
|
SampleAnswerVoicePrompt: &row.SampleAnswerVoicePrompt.String,
|
|
SampleAnswer: &row.SampleAnswer.String,
|
|
Tips: &row.Tips.String,
|
|
Type: row.Type,
|
|
}, nil
|
|
}
|
|
|
|
func (s *Store) GetQuestionsByPractice(
|
|
ctx context.Context,
|
|
practiceID int64,
|
|
) ([]domain.PracticeQuestion, error) {
|
|
|
|
rows, err := s.queries.GetQuestionsByPractice(ctx, practiceID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
questions := make([]domain.PracticeQuestion, 0, len(rows))
|
|
for _, row := range rows {
|
|
questions = append(questions, domain.PracticeQuestion{
|
|
ID: row.ID,
|
|
PracticeID: row.PracticeID,
|
|
Question: row.Question,
|
|
QuestionVoicePrompt: &row.QuestionVoicePrompt.String,
|
|
SampleAnswerVoicePrompt: &row.SampleAnswerVoicePrompt.String,
|
|
SampleAnswer: &row.SampleAnswer.String,
|
|
Tips: &row.Tips.String,
|
|
Type: row.Type,
|
|
})
|
|
}
|
|
|
|
return questions, nil
|
|
}
|
|
|
|
func (s *Store) UpdatePracticeQuestion(
|
|
ctx context.Context,
|
|
id int64,
|
|
question *string,
|
|
sampleAnswer *string,
|
|
tips *string,
|
|
qType *string,
|
|
) error {
|
|
|
|
return s.queries.UpdatePracticeQuestion(ctx, dbgen.UpdatePracticeQuestionParams{
|
|
Question: func() string {
|
|
if question != nil {
|
|
return *question
|
|
}
|
|
return ""
|
|
}(),
|
|
SampleAnswer: pgtype.Text{String: *sampleAnswer},
|
|
Tips: pgtype.Text{String: *tips},
|
|
Type: func() string {
|
|
if qType != nil {
|
|
return *qType
|
|
}
|
|
return ""
|
|
}(),
|
|
ID: id,
|
|
})
|
|
}
|
|
|
|
func (s *Store) DeletePracticeQuestion(
|
|
ctx context.Context,
|
|
id int64,
|
|
) error {
|
|
|
|
return s.queries.DeletePracticeQuestion(ctx, id)
|
|
}
|