new handling for the response creation method

This commit is contained in:
Pavel 2024-06-01 21:09:32 +03:00
parent 16ea424441
commit af93405efb

@ -29,10 +29,10 @@ func NewAnswerRepository(deps Deps) *AnswerRepository {
}
// test +
func (r *AnswerRepository) CreateAnswers(ctx context.Context, answers []model.Answer, session, fp string, quizID uint64) ([]uint64, []error) {
func (r *AnswerRepository) CreateAnswers(ctx context.Context, answers []model.Answer, session, fp string, quizID uint64) ([]model.Answer, []error) {
var (
answered []uint64
errs []error
createdAnswers []model.Answer
errs []error
)
tx, err := r.pool.BeginTx(ctx, nil)
@ -66,11 +66,29 @@ func (r *AnswerRepository) CreateAnswers(ctx context.Context, answers []model.An
Utm: utmJSON,
}
err = r.queries.InsertAnswers(ctx, params)
row, err := r.queries.InsertAnswers(ctx, params)
createdAnswer := model.Answer{
Id: uint64(row.ID),
Content: row.Content.String,
QuizId: uint64(row.QuizID),
QuestionId: uint64(row.QuestionID),
Fingerprint: row.Fingerprint.String,
Session: row.Session.String,
Result: row.Result.Bool,
New: row.New.Bool,
Email: row.Email,
DeviceType: row.DeviceType,
Device: row.Device,
OS: row.Os,
Browser: row.Browser,
IP: row.Ip,
Start: row.Start,
}
if err != nil {
errs = append(errs, err)
} else {
answered = append(answered, ans.QuestionId)
createdAnswers = append(createdAnswers, createdAnswer)
}
}
@ -80,7 +98,7 @@ func (r *AnswerRepository) CreateAnswers(ctx context.Context, answers []model.An
return nil, errs
}
return answered, errs
return createdAnswers, errs
}
// test +