Commits

Kakadu committed de21e18

trying to get questions with answers

Comments (0)

Files changed (2)

   end
   in
   (event,events,prev,next)
-(*
+
+let escape s = s
+               |> Str.global_replace (Str.regexp "\n") "\\n"
+               |> Str.global_replace (Str.regexp "\\") "\\\\"
+               |> Str.global_replace (Str.regexp "'") "\\'"
+
+let add_question ~nodeId ~text =
+  let cmd = sprintf "START n=node(%Ld)
+      CREATE (q:QUESTION_ITEM{text: '%s'})<-[:HAS_QUESTION]-n" nodeId (escape text)
+  in
   let ans = post_cypher cmd in
   print_endline ans;
-  match to_json ans with
-  | `Assoc [_;("data",`List[`List[`Assoc dj; `Assoc cur; `List nodes; prev; prevd; next; nextd ]])] ->
-     let wrap = function
-       | `Assoc p, `Assoc pd -> Some (event_of_json pd p)
-       | `Null, `Null -> None
-       | _ -> failwith "Wrong JSON format in wrap function"
-     in
-    (event_of_json dj cur,
-     List.map ~f:(function `Assoc d -> event_of_json dj d
-                         | _ -> failwith "Wrong JSON format during drop_assoc") nodes,
-     wrap (prev,prevd) ,wrap (next, nextd))
-  | _ -> failwith "Wrong JSON format in day_by_eventid"
-
-
- *)
+  Lwt.return true
+
+let questions_with_options_of_nodeId nodeId =
+  let cmd = sprintf "Start e=node(%Ld)
+                     MATCH (a)<-[:HAS_ANSWER*0..]-q<-[:HAS_QUESTION]-e
+                     RETURN q,collect(a)" nodeId
+  in
+  let ans = post_cypher cmd  in
+  print_endline ans;
+  match ans |> to_json |> YoUtil.unwrap_res with
+  | _ ->
+  Lwt.return []
+
 
 }}
 
-
+(* TODO: rename options into answers *)
 let questions_and_options_rpc
     : (eventId_t, Types.Question.t list) Eliom_pervasives.server_function
-  = server_function Json.t<eventId_t> Events_db.questions_with_options_of_nodeId
+  = server_function Json.t<eventId_t> Neo_db.questions_with_options_of_nodeId
 
 let get_node_by_id_rpc : (eventId_t, Types.Event.t) Eliom_pervasives.server_function
   = server_function Json.t<eventId_t> Neo_db.event_by_id
 
 let add_question_rpc: (eventId_t*string, bool) Eliom_pervasives.server_function
   = server_function Json.t<eventId_t*string>
-    (fun (nodeId,text) -> Events_db.insert_question ~nodeId ~text)
+    (fun (nodeId,text) -> Neo_db.add_question ~nodeId ~text)
 
 let remove_question_rpc: (questionId_t, bool) Eliom_pervasives.server_function
   = server_function Json.t<questionId_t> (fun questionId -> Events_db.remove_question ~questionId)