Empty relationship resource was added and Graph object knows how to find a vertex

This commit is contained in:
Marko Budiselic 2015-11-07 11:31:36 +01:00
parent 26b426e1fa
commit 7564c35d19
3 changed files with 54 additions and 17 deletions

View File

@ -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) {

View File

@ -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<Relationships, POST>
{
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<Relationship, GET>
{
public:
using Resource::Resource;
void get(sp::Request& req, sp::Response& res)
{
return res.send("GET /db/data/relationship");
}
};
#endif

View File

@ -38,6 +38,27 @@ public:
return edges.insert(t);
}
// TODO: this should probably return mvcc::Atom<Vertex>*
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;
};