fix: add generative placeholders 4 question editing
This commit is contained in:
parent
e5ba6630d6
commit
5b57148b01
@ -216,34 +216,41 @@ func (r *QuestionRepository) UpdateQuestion(ctx context.Context, record model.Qu
|
||||
var params []interface{}
|
||||
|
||||
if record.Title != "" {
|
||||
query += ` title = $1,`
|
||||
query += ` title = $%d,`
|
||||
params = append(params, record.Title)
|
||||
}
|
||||
|
||||
if record.Description != "" {
|
||||
query += ` description = $2::text,`
|
||||
query += ` description = $%d::text,`
|
||||
params = append(params, record.Description)
|
||||
}
|
||||
|
||||
if record.Type != "" {
|
||||
query += ` questiontype = $3,`
|
||||
query += ` questiontype = $%d,`
|
||||
params = append(params, record.Type)
|
||||
}
|
||||
|
||||
if record.Content != "" {
|
||||
query += ` content = $4::text,`
|
||||
query += ` content = $%d::text,`
|
||||
params = append(params, record.Content)
|
||||
}
|
||||
|
||||
if record.Page != -1 {
|
||||
query += ` page = $5,`
|
||||
query += ` page = $%d,`
|
||||
params = append(params, record.Page)
|
||||
}
|
||||
|
||||
query += ` required = $6, version = $7 WHERE id = $8`
|
||||
query += ` required = $%d, version = $%d WHERE id = $%d`
|
||||
|
||||
params = append(params, record.Required, record.Version, record.Id)
|
||||
|
||||
var placeholders []any
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user