TKIDD74O5N6F3NX5YN35DXNRDJBMYNRG4EIEV2OH2ZGJ4WALCFUAC
panic(fmt.Errorf("not implemented"))
// create todo node
id := uuid.NewString()
todo := rg.NodeNew(todoLabel, id,
redisProps{
"text": input.Text,
"user": input.UserID})
r.graph.AddNode(todo)
// create edge connecting the node and owner
owner := rg.EdgeNew(ownerRelation, todo, r.graph.Nodes[input.UserID], nil)
r.graph.AddEdge(owner)
if _, err := r.graph.Commit(); err != nil {
return nil, fmt.Errorf("CreateTodo: %w", err)
}
return &model.Todo{
ID: id,
Properties: redisProps{
"text": input.Text,
},
UserID: input.UserID,
}, nil
id, ok := r.GetByIndex(0).(string)
if !ok {
return nil, fmt.Errorf("Todos: %+v ID not found", r)
}
prop, ok := r.GetByIndex(1).(map[string]interface{})
if !ok {
return nil, fmt.Errorf("Todos: %+v properties not found", r)
}
user, ok := r.GetByIndex(2).(string)
if !ok {
return nil, fmt.Errorf("Todos: %+v user not found", r)
todo, err := TodoParse(r)
if err != nil {
return nil, fmt.Errorf("Todos: %w", err)
}
func TodoParse(r *rg.Record) (*model.Todo, error) {
id, ok := r.GetByIndex(0).(string)
if !ok {
return nil, fmt.Errorf("TodoParse: %+v ID not found", r)
}
prop, ok := r.GetByIndex(1).(redisProps)
if !ok {
return nil, fmt.Errorf("TodoParse: %+v properties not found", r)
}
user, ok := r.GetByIndex(2).(string)
if !ok {
return nil, fmt.Errorf("TodoParse: %+v user not found", r)
}
return &model.Todo{
ID: id,
Properties: prop,
UserID: user,
}, nil
func UserParse(r *rg.Record) (*model.User, error) {
id, ok := r.GetByIndex(0).(string)
if !ok {
return nil, fmt.Errorf("UserParse: %+v ID not found", r)
}
name, ok := r.GetByIndex(1).(string)
if !ok {
return nil, fmt.Errorf("UserParse: %+v Name not found", r)
}
return &model.User{
ID: id,
Name: name,
}, nil
}