Skip to content

Commit

Permalink
Read changeset id from create node payload
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Nov 7, 2023
1 parent ca3470c commit cc80093
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/api06/node_create_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ node_create_responder::node_create_responder(
mime::type mt, data_update & upd, const std::string &payload,
std::optional<osm_user_id_t> user_id)
: text_responder(mt) {

NodeXMLParser parser;
auto node = parser.process_message(payload);

OSMChange_Tracking change_tracking{};
osm_changeset_id_t cid = 1; // TODO get changeset id
osm_user_id_t uid = *user_id;
auto changeset_updater = upd.get_changeset_updater(cid, uid);
auto changeset_updater = upd.get_changeset_updater(node->changeset(), uid);
auto node_updater = upd.get_node_updater(change_tracking);

changeset_updater->lock_current_changeset(true);
NodeXMLParser parser;
auto node = parser.process_message(payload);
node_updater->add_node(node->lat(), node->lon(), cid, -1, node->tags());
node_updater->add_node(node->lat(), node->lon(), node->changeset(), -1, node->tags());
node_updater->process_new_nodes();
changeset_updater->update_changeset(node_updater->get_num_changes(),
node_updater->bbox());
Expand Down
14 changes: 10 additions & 4 deletions test/test_apidb_backend_node_changes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ void test_end_to_end(test_database &tdb, const std::string& title, const std::st
INSERT INTO changesets (id, user_id, created_at, closed_at, num_changes)
VALUES
(1, 1, now() at time zone 'utc', now() at time zone 'utc' + '1 hour' ::interval, 0);
(1, 1, now() at time zone 'utc' - '12 hour' ::interval,
now() at time zone 'utc' - '11 hour' ::interval, 0),
(2, 1, now() at time zone 'utc', now() at time zone 'utc' + '1 hour' ::interval, 0);
)");

const std::string baseauth = "Basic ZGVtbzpwYXNzd29yZA==";
const std::string generator = "Test";
const osm_nwr_id_t target_version = 1;
const osm_changeset_id_t target_changeset_id = 2;
const osm_user_id_t target_user_id = 1;
const std::string target_display_name = "demo";

auto sel_factory = tdb.get_data_selection_factory();
auto upd_factory = tdb.get_data_update_factory();
Expand Down Expand Up @@ -72,7 +78,7 @@ void test_end_to_end(test_database &tdb, const std::string& title, const std::st
assert_equal<size_t>(f.m_nodes.size(), 1, fmt::format("number of nodes written for {}", title));
assert_equal<test_formatter::node_t>(
test_formatter::node_t(
element_info(node_id, 1, 1, f.m_nodes[0].elem.timestamp, 1, std::string("demo"), true),
element_info(node_id, target_version, target_changeset_id, f.m_nodes[0].elem.timestamp, target_user_id, target_display_name, true),
target_lon, target_lat, target_tags
),
f.m_nodes[0], title);
Expand All @@ -88,15 +94,15 @@ int main(int, char **) {
test_end_to_end(tdb, "node without tags",
R"(<?xml version="1.0" encoding="UTF-8"?>
<osm>
<node lat="12" lon="34" changeset="1"/>
<node lat="12" lon="34" changeset="2"/>
</osm>)",
12, 34, tags_t());
});
tdb.run_update([](test_database &tdb) {
test_end_to_end(tdb, "node with tags",
R"(<?xml version="1.0" encoding="UTF-8"?>
<osm>
<node lat="21" lon="43" changeset="1">
<node lat="21" lon="43" changeset="2">
<tag k="natural" v="tree"/>
<tag k="height" v="19"/>
</node>
Expand Down

0 comments on commit cc80093

Please sign in to comment.