review
This commit is contained in:
parent
6ffc0d2c99
commit
6153017b62
22 changed files with 835 additions and 100 deletions
|
|
@ -38,6 +38,7 @@ type Question struct {
|
|||
ID uint `gorm:"primaryKey"`
|
||||
Text string `gorm:"type:text;not null"`
|
||||
Type string `gorm:"size:32;not null"`
|
||||
CodeSnippet string `gorm:"type:text;not null;default:''"`
|
||||
ReferenceAnswer string `gorm:"type:text;not null;default:''"`
|
||||
Deprecated bool `gorm:"not null;default:false"`
|
||||
Options []QuestionOption `gorm:"foreignKey:QuestionID;constraint:OnDelete:CASCADE"`
|
||||
|
|
|
|||
|
|
@ -46,8 +46,9 @@ func questionsToService(values []dbmodel.Question) []servicemodel.Question {
|
|||
}
|
||||
result[i] = servicemodel.Question{
|
||||
ID: value.ID, Text: value.Text, Type: value.Type,
|
||||
Options: options, ReferenceAnswer: value.ReferenceAnswer,
|
||||
Deprecated: value.Deprecated,
|
||||
Options: options, CodeSnippet: value.CodeSnippet,
|
||||
ReferenceAnswer: value.ReferenceAnswer,
|
||||
Deprecated: value.Deprecated,
|
||||
}
|
||||
}
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -147,7 +147,8 @@ func (s *Store) CreateQuestion(ctx context.Context, value servicemodel.Question)
|
|||
}
|
||||
entity := dbmodel.Question{
|
||||
Text: value.Text, Type: value.Type, Options: options,
|
||||
ReferenceAnswer: value.ReferenceAnswer, Deprecated: value.Deprecated,
|
||||
CodeSnippet: value.CodeSnippet, ReferenceAnswer: value.ReferenceAnswer,
|
||||
Deprecated: value.Deprecated,
|
||||
}
|
||||
if err := s.db.WithContext(ctx).Create(&entity).Error; err != nil {
|
||||
return servicemodel.Question{}, mapError(err)
|
||||
|
|
@ -159,7 +160,8 @@ func (s *Store) UpdateQuestion(ctx context.Context, id uint, value servicemodel.
|
|||
err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
result := tx.Model(&dbmodel.Question{}).Where("id = ?", id).
|
||||
Updates(map[string]any{
|
||||
"text": value.Text, "type": value.Type, "reference_answer": value.ReferenceAnswer,
|
||||
"text": value.Text, "type": value.Type, "code_snippet": value.CodeSnippet,
|
||||
"reference_answer": value.ReferenceAnswer,
|
||||
})
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue