Commits

Kakadu committed e893567

Adding and removing questions and interpretations

Comments (0)

Files changed (2)

                       path=(f)-[:FOLLOWED_BY*0..]->(l)
                       return d,nodes(path);" date_text in
   let ans = post_cypher cmd1 in
-  print_endline ans;
+  (*print_endline ans;*)
   match to_json ans with
   | `Assoc [_;("data",`List [`List [`Assoc dj; `List nodes ]])] ->
      Lwt.return @@ List.map ~f:(function `Assoc x -> event_of_json ~dj x | _ -> assert false) nodes
   print_endline ans;
   Lwt.return true
 
+let remove_question ~questionId =
+  let cmd = sprintf "START q=node(%Ld)
+     MATCH n-[rq:HAS_QUESTION]->q
+     OPTIONAL MATCH q-[ra:HAS_ANSWER]->intrp
+     DELETE intrp,ra,rq,q;" questionId
+  in
+  let (_ans:string) = post_cypher cmd in
+  (*print_endline _ans;*)
+  Lwt.return true
+
+let add_option ~questionId ~text =
+  let cmd = sprintf "START q=node(%Ld)
+      CREATE (i:ANSWER_ITEM{text: '%s'})<-[:HAS_ANSWER]-q" questionId (escape text)
+  in
+  let (_:string) = post_cypher cmd in
+  Lwt.return true
+
+let remove_option ~optionId =
+  let cmd = sprintf "START intrp=node(%Ld)
+      MATCH (q:QUESTION_ITEM)-[r:HAS_ANSWER]->intrp
+      DELETE intrp,r;" optionId
+  in
+  let (_ans:string) = post_cypher cmd in
+  (*print_endline _ans;*)
+  Lwt.return true
 
 let interpret_of_json ej : Types.Option.t =
   let id = id_from_node_json ej in
   Types.Question.({id; options; text})
 
 let questions_with_options_of_nodeId nodeId =
-  let cmd = sprintf "Start e=node(%Ld)
-                     MATCH (a)<-[:HAS_ANSWER*0..]-q<-[:HAS_QUESTION]-e
+  let cmd = sprintf "START e=node(%Ld)
+                     MATCH q<-[:HAS_QUESTION]-e
+                     OPTIONAL MATCH q-[:HAS_ANSWER]->(a)
                      RETURN q,collect(a)" nodeId
   in
   let ans = post_cypher cmd  in
     (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)
+  = server_function Json.t<questionId_t> (fun questionId -> Neo_db.remove_question ~questionId)
 
 let remove_event_rpc
   : (int64, int64) Eliom_pervasives.server_function
 
 let add_option_rpc: (optionId_t*string, bool) Eliom_pervasives.server_function
   = server_function Json.t<optionId_t*string>
-    (fun (questionId,text) -> Events_db.insert_option ~questionId ~text)
+    (fun (questionId,text) -> Neo_db.add_option ~questionId ~text)
 
 let remove_option_rpc: (optionId_t, bool) Eliom_pervasives.server_function
-  = server_function Json.t<optionId_t> (fun optionId -> Events_db.remove_option ~optionId)
+  = server_function Json.t<optionId_t> (fun optionId -> Neo_db.remove_option ~optionId)
 
 let get_user_by_id_rpc : (int64, Ukraine_user.t) Eliom_pervasives.server_function
   = server_function Json.t<int64> Ukraine_user.by_id