From d0d47f791b74cf2bf935535e93583990b9a382da Mon Sep 17 00:00:00 2001 From: xphoniex Date: Thu, 1 Jun 2023 12:26:27 +0000 Subject: [PATCH] node: Add access to routing.db on `profile` httpd: Use routing.db to return `trackings` of an RID Signed-off-by: xphoniex --- radicle-httpd/src/api.rs | 5 +++++ radicle-httpd/src/api/error.rs | 4 ++++ radicle-httpd/src/api/v1/delegates.rs | 8 +++++++- radicle-httpd/src/api/v1/projects.rs | 10 ++++++++-- radicle-httpd/src/test.rs | 3 +++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/radicle-httpd/src/api.rs b/radicle-httpd/src/api.rs index 750a2984a..a4a71919c 100644 --- a/radicle-httpd/src/api.rs +++ b/radicle-httpd/src/api.rs @@ -17,6 +17,7 @@ use tower_http::cors::{self, CorsLayer}; use radicle::cob::issue; use radicle::cob::patch; use radicle::identity::Id; +use radicle::node::routing::Store; use radicle::storage::{ReadRepository, ReadStorage}; use radicle::Profile; @@ -52,6 +53,8 @@ impl Context { let delegates = doc.delegates; let issues = issue::Issues::open(&repo)?.counts()?; let patches = patch::Patches::open(&repo)?.counts()?; + let routing = &self.profile.routing()?; + let trackings = routing.count(&id).unwrap_or_default(); Ok(project::Info { payload, @@ -60,6 +63,7 @@ impl Context { issues, patches, id, + trackings, }) } @@ -183,5 +187,6 @@ mod project { pub patches: cob::patch::PatchCounts, pub issues: cob::issue::IssueCounts, pub id: Id, + pub trackings: usize, } } diff --git a/radicle-httpd/src/api/error.rs b/radicle-httpd/src/api/error.rs index e20c6e84d..f1763e266 100644 --- a/radicle-httpd/src/api/error.rs +++ b/radicle-httpd/src/api/error.rs @@ -73,6 +73,10 @@ pub enum Error { /// Tracking store error. #[error(transparent)] TrackingStore(#[from] radicle::node::tracking::store::Error), + + /// Routing store error. + #[error(transparent)] + RoutingStore(#[from] radicle::node::routing::Error), } impl IntoResponse for Error { diff --git a/radicle-httpd/src/api/v1/delegates.rs b/radicle-httpd/src/api/v1/delegates.rs index 603eb287d..825416517 100644 --- a/radicle-httpd/src/api/v1/delegates.rs +++ b/radicle-httpd/src/api/v1/delegates.rs @@ -6,6 +6,7 @@ use axum::{Json, Router}; use radicle::cob::issue::Issues; use radicle::cob::patch::Patches; use radicle::identity::Did; +use radicle::node::routing::Store; use radicle::storage::{ReadRepository, ReadStorage}; use crate::api::error::Error; @@ -34,6 +35,7 @@ async fn delegates_projects_handler( let page = page.unwrap_or(0); let per_page = per_page.unwrap_or(10); let storage = &ctx.profile.storage; + let routing = &ctx.profile.routing()?; let projects = storage .repositories()? .into_iter() @@ -54,6 +56,8 @@ async fn delegates_projects_handler( let Ok(patches) = Patches::open(&repo) else { return None }; let Ok(patches) = patches.counts() else { return None }; + let trackings = routing.count(&id).unwrap_or_default(); + Some(Info { payload, delegates, @@ -61,6 +65,7 @@ async fn delegates_projects_handler( issues, patches, id, + trackings, }) }) .skip(page * per_page) @@ -107,7 +112,8 @@ mod routes { "open": 1, "closed": 0, }, - "id": RID + "id": RID, + "trackings": 0, } ]) ); diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index 55fccb3a9..38653962d 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -14,6 +14,7 @@ use tower_http::set_header::SetResponseHeaderLayer; use radicle::cob::{issue, patch, thread, ActorId, Tag}; use radicle::identity::Id; +use radicle::node::routing::Store; use radicle::node::NodeId; use radicle::storage::git::paths; use radicle::storage::{ReadRepository, ReadStorage, WriteRepository}; @@ -77,6 +78,7 @@ async fn project_root_handler( let page = page.unwrap_or(0); let per_page = per_page.unwrap_or(10); let storage = &ctx.profile.storage; + let routing = &ctx.profile.routing()?; let projects = storage .repositories()? .into_iter() @@ -91,6 +93,7 @@ async fn project_root_handler( let Ok(patches) = patch::Patches::open(&repo) else { return None }; let Ok(patches) = patches.counts() else { return None }; let delegates = doc.delegates; + let trackings = routing.count(&id).unwrap_or_default(); Some(Info { payload, @@ -99,6 +102,7 @@ async fn project_root_handler( issues, patches, id, + trackings, }) }) .skip(page * per_page) @@ -800,7 +804,8 @@ mod routes { "open": 1, "closed": 0, }, - "id": RID + "id": RID, + "trackings": 0, } ]) ); @@ -831,7 +836,8 @@ mod routes { "open": 1, "closed": 0, }, - "id": RID + "id": RID, + "trackings": 0, }) ); } diff --git a/radicle-httpd/src/test.rs b/radicle-httpd/src/test.rs index bbb0319e6..14a922bc9 100644 --- a/radicle-httpd/src/test.rs +++ b/radicle-httpd/src/test.rs @@ -16,6 +16,7 @@ use radicle::crypto::ssh::keystore::MemorySigner; use radicle::crypto::ssh::Keystore; use radicle::crypto::{KeyPair, Seed, Signer}; use radicle::git::{raw as git2, RefString}; +use radicle::node::routing as RoutingStore; use radicle::node::tracking::store as TrackingStore; use radicle::profile::Home; use radicle::storage::ReadStorage; @@ -85,7 +86,9 @@ pub fn contributor(dir: &Path) -> Context { fn seed_with_signer(dir: &Path, profile: radicle::Profile, signer: &G) -> Context { let tracking_db = dir.join("radicle").join("node").join("tracking.db"); + let routing_db = dir.join("radicle").join("node").join("routing.db"); TrackingStore::Config::open(tracking_db).unwrap(); + RoutingStore::Table::open(routing_db).unwrap(); let workdir = dir.join("hello-world");