func persistProject(p Project, ps *persistence.PersistenceSession) error { owner, err := ps.Subject(p.Subject) if err != nil { return err } ownerRef := mgo.DBRef{Collection: "subject", Id: owner.Id} project := &persistence.Project{Owner: ownerRef, Name: p.Name, Description: p.Description} err = ps.CreateProject(project) return err }
func persistDocument(d Document, ps *persistence.PersistenceSession) error { owner, err := ps.Subject(d.Subject) if err != nil { return err } project, err := ps.Project(&owner, d.Project) if err != nil { return err } projectRef := mgo.DBRef{Collection: "project", Id: project.Id} document := &persistence.Document{Project: projectRef, Path: d.Path} err = ps.CreateDocument(document) return err }