new handling for the response creation method
This commit is contained in:
parent
16ea424441
commit
af93405efb
@ -29,10 +29,10 @@ func NewAnswerRepository(deps Deps) *AnswerRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// test +
|
// 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 (
|
var (
|
||||||
answered []uint64
|
createdAnswers []model.Answer
|
||||||
errs []error
|
errs []error
|
||||||
)
|
)
|
||||||
|
|
||||||
tx, err := r.pool.BeginTx(ctx, nil)
|
tx, err := r.pool.BeginTx(ctx, nil)
|
||||||
@ -66,11 +66,29 @@ func (r *AnswerRepository) CreateAnswers(ctx context.Context, answers []model.An
|
|||||||
Utm: utmJSON,
|
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 {
|
if err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
} else {
|
} 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 nil, errs
|
||||||
}
|
}
|
||||||
|
|
||||||
return answered, errs
|
return createdAnswers, errs
|
||||||
}
|
}
|
||||||
|
|
||||||
// test +
|
// test +
|
||||||
|
Loading…
Reference in New Issue
Block a user