From 7564c35d192a12247dd2fbd7f6cc8f25c8d860dc Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sat, 7 Nov 2015 11:31:36 +0100 Subject: [PATCH] Empty relationship resource was added and Graph object knows how to find a vertex --- api/resources/node.hpp | 19 ++----------------- api/resources/relationship.hpp | 31 +++++++++++++++++++++++++++++++ storage/graph.hpp | 21 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 api/resources/relationship.hpp diff --git a/api/resources/node.hpp b/api/resources/node.hpp index 9af7e155e..3d8fd5034 100644 --- a/api/resources/node.hpp +++ b/api/resources/node.hpp @@ -70,23 +70,8 @@ public: task->run([this, &req]() -> Vertex* { // read id param uint64_t id = std::stoull(req.params[0]); - - // get atom iterator - auto atom_it = db->graph.vertices.begin(); - - // find the right atom - // TODO: better implementation - while (true) { - if (id == atom_it->id) { - // TODO: return latest version - return atom_it->first(); - } - if (!atom_it.has_next()) - break; - ++atom_it; - } - - return nullptr; + // TODO: transaction? + return db->graph.find_vertex(id); }, [&req, &res](Vertex* node) { if (node == nullptr) { diff --git a/api/resources/relationship.hpp b/api/resources/relationship.hpp new file mode 100644 index 000000000..80576bf84 --- /dev/null +++ b/api/resources/relationship.hpp @@ -0,0 +1,31 @@ +#ifndef MEMGRAPH_API_RESOURCES_RELATIONSHIP_HPP +#define MEMGRAPH_API_RESOURCES_RELATIONSHIP_HPP + +#include "api/restful/resource.hpp" + +#pragma url /relationship +class Relationships : public Resource +{ +public: + using Resource::Resource; + + void post(sp::Request& req, sp::Response& res) + { + return res.send("POST /db/data/relationship"); + } + +}; + +#pragma url /relationship/{id:\\d+} +class Relationship : public Resource +{ +public: + using Resource::Resource; + + void get(sp::Request& req, sp::Response& res) + { + return res.send("GET /db/data/relationship"); + } +}; + +#endif diff --git a/storage/graph.hpp b/storage/graph.hpp index c75cf4e2f..e61e5b974 100644 --- a/storage/graph.hpp +++ b/storage/graph.hpp @@ -38,6 +38,27 @@ public: return edges.insert(t); } + // TODO: this should probably return mvcc::Atom* + Vertex* find_vertex(uint64_t id) + { + // get atom iterator + auto atom_it = vertices.begin(); + + // find the right atom + // TODO: better implementation + while (true) { + if (id == atom_it->id) { + // TODO: return latest version + return atom_it->first(); + } + if (!atom_it.has_next()) + break; + ++atom_it; + } + + return nullptr; + } + VertexStore vertices; EdgeStore edges; };