Skip to content

Commit

Permalink
fix 600
Browse files Browse the repository at this point in the history
  • Loading branch information
ddadaal committed Feb 2, 2024
1 parent 2161c88 commit b142c1b
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions repositories/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,42 @@ func (r *SummaryRepository) GetAll() ([]*models.Summary, error) {

func (r *SummaryRepository) Insert(summary *models.Summary) error {

itemsToCreate := []interface{}{summary}
if err := r.db.Transaction(func(tx *gorm.DB) error {
if err := r.db.Create(summary).Error; err != nil {
return err
}

// required due to setting gorm:"-" in the model definition
// see https://github.com/muety/wakapi/issues/600#issuecomment-1921723789
// see https://github.com/muety/wakapi/pull/592#discussion_r1450478355
for _, item := range summary.Machines {
itemsToCreate = append(itemsToCreate, item)
}
itemsToCreate := []*models.SummaryItem{}

for _, item := range summary.Languages {
itemsToCreate = append(itemsToCreate, item)
}
// required due to setting gorm:"-" in the model definition
// see https://github.com/muety/wakapi/issues/600#issuecomment-1921723789
// see https://github.com/muety/wakapi/pull/592#discussion_r1450478355
for _, item := range summary.Machines {
item.SummaryID = summary.ID
itemsToCreate = append(itemsToCreate, item)
}

for _, item := range summary.OperatingSystems {
itemsToCreate = append(itemsToCreate, item)
}
for _, item := range summary.Languages {
item.SummaryID = summary.ID
itemsToCreate = append(itemsToCreate, item)
}

for _, item := range summary.Editors {
itemsToCreate = append(itemsToCreate, item)
}
for _, item := range summary.OperatingSystems {
item.SummaryID = summary.ID
itemsToCreate = append(itemsToCreate, item)
}

for _, item := range summary.Editors {
item.SummaryID = summary.ID
itemsToCreate = append(itemsToCreate, item)
}

if err := r.db.Create(itemsToCreate).Error; err != nil {
return err
}

if err := r.db.Create(itemsToCreate).Error; err != nil {
return nil
}); err != nil {
return err
}

Expand Down

0 comments on commit b142c1b

Please sign in to comment.