Exemplo n.º 1
0
func updatePopularNames(db *sql.DB, fk int64, table_name string, names []string) {
	posted_names := getNamesMap(names)

	current_names_slices, err := repository.GetPopularNames(db, fk, table_name)
	current_names := getNamesMap(current_names_slices)
	if err != nil {
		return
	}

	new_names := getNewNames(current_names, posted_names)
	for _, new_name := range new_names {
		repository.InsertPopularName(db, fk, table_name, new_name)
	}

	deleted_names := getDeletedNames(current_names, posted_names)
	for _, deleted_name := range deleted_names {
		repository.DeletePopularName(db, deleted_name)
	}
}
Exemplo n.º 2
0
func insertPopularNames(db *sql.DB, fk int64, table_name string, names []string) {
	for _, new_name := range names {
		repository.InsertPopularName(db, fk, table_name, new_name)
	}
}