func UpdateFeedback(node model.Node, feedback float64) { db := persistence.GetDatabase().DbMap() avg := node.LocalFeedbackAverage fc := node.FeedbackCount newAvg := computeNewAverage(avg, float64(fc), feedback) node.LocalFeedbackAverage = newAvg node.FeedbackCount = fc + 1 db.Update(&node) }
func FindOrCreateNode(name string, parent model.Node) model.Node { db := persistence.GetDatabase().DbMap() node := model.Node{} db.SelectOne(&node, "select * from nodes where Name=? and ParentId=?", name, parent.Id) if node.Id == 0 { node.Name = name insertAndAssociateNodeToParent(&node, parent) } return node }
func insertAndAssociateNodeToParent(node *model.Node, parent model.Node) { db := persistence.GetDatabase().DbMap() node.ParentId = parent.Id parent.ChildrenCount++ db.Update(&parent) db.Insert(&node) }