Browse Source

Allow group targets to be updated, fixes #18

pull/315/head
Rob Cutmore 5 years ago
parent
commit
ec1c711b9b
1 changed files with 18 additions and 1 deletions
  1. +18
    -1
      models/group.go

+ 18
- 1
models/group.go View File

@ -156,12 +156,15 @@ func PutGroup(g *Group) error {
for _, t := range ts {
if t.Email == nt.Email {
tExists = true
nt.Id = t.Id
break
}
}
// If the target is not in the db, we add it
// Add target if not in database, otherwise update target information.
if !tExists {
insertTargetIntoGroup(nt, g.Id)
} else {
UpdateTarget(nt)
}
}
err = db.Save(g).Error
@ -220,6 +223,20 @@ func insertTargetIntoGroup(t Target, gid int64) error {
return nil
}
// UpdateTarget updates the given target information in the database.
func UpdateTarget(target Target) error {
targetInfo := map[string]interface{}{
"first_name": target.FirstName,
"last_name": target.LastName,
"position": target.Position,
}
err := db.Model(&target).Where("id = ?", target.Id).Updates(targetInfo).Error
if err != nil {
Logger.Printf("Error updating target information for %s\n", target.Email)
}
return err
}
// GetTargets performs a many-to-many select to get all the Targets for a Group
func GetTargets(gid int64) ([]Target, error) {
ts := []Target{}

Loading…
Cancel
Save