From 8f74ebbb15679d3b7ac31a52b1174c3a9cb5a30c Mon Sep 17 00:00:00 2001 From: Jack Gilcrest Date: Wed, 27 Mar 2024 15:06:11 -0600 Subject: [PATCH] Change phrase_hash to phrase in get-new-degrees --- crates/grapevine_server/src/mongo.rs | 31 +++------------------ crates/grapevine_server/src/routes/proof.rs | 20 ------------- 2 files changed, 4 insertions(+), 47 deletions(-) diff --git a/crates/grapevine_server/src/mongo.rs b/crates/grapevine_server/src/mongo.rs index 7236db9..1c8cfb0 100644 --- a/crates/grapevine_server/src/mongo.rs +++ b/crates/grapevine_server/src/mongo.rs @@ -454,7 +454,7 @@ impl GrapevineDB { "localField": "degree_proofs", "foreignField": "_id", "as": "userDegreeProofs", - "pipeline": [doc! { "$project": { "degree": 1, "phrase_hash": 1 } }] + "pipeline": [doc! { "$project": { "degree": 1, "phrase": 1 } }] } }, // look up the relationships made by this user @@ -477,7 +477,7 @@ impl GrapevineDB { "as": "relationshipDegreeProofs", "pipeline": [ doc! { "$match": { "inactive": { "$ne": true } } }, - doc! { "$project": { "degree": 1, "phrase_hash": 1 } } + doc! { "$project": { "degree": 1, "phrase": 1 } } ] } }, @@ -487,7 +487,7 @@ impl GrapevineDB { // find the lowest degree proof in each chain from relationship proofs and reference user proofs in this chain if exists doc! { "$group": { - "_id": "$relationshipDegreeProofs.phrase_hash", + "_id": "$relationshipDegreeProofs.phrase", "originalId": { "$first": "$relationshipDegreeProofs._id" }, "degree": { "$min": "$relationshipDegreeProofs.degree" }, "userProof": { @@ -496,7 +496,7 @@ impl GrapevineDB { "$filter": { "input": "$userDegreeProofs", "as": "userProof", - "cond": { "$eq": ["$$userProof.phrase_hash", "$relationshipDegreeProofs.phrase_hash"] } + "cond": { "$eq": ["$$userProof.phrase", "$relationshipDegreeProofs.phrase"] } } }, 0] } @@ -1173,29 +1173,6 @@ impl GrapevineDB { } } - /** - * Get chain of degree proofs linked to a phrase - * - * @param phrase_hash - hash of the phrase linking the proof chain together - */ - pub async fn get_proof_chain(&self, phrase_hash: &str) -> Vec { - let mut proofs: Vec = vec![]; - let query = doc! { "phrase_hash": phrase_hash }; - let projection = doc! { "_id": 1, "degree": 1 }; - let find_options = FindOptions::builder().projection(projection).build(); - let mut cursor = self.degree_proofs.find(query, find_options).await.unwrap(); - - while let Some(result) = cursor.next().await { - match result { - Ok(proof) => { - proofs.push(proof); - } - Err(e) => println!("Error: {:?}", e), - } - } - proofs - } - /** * Check to see if degree already exists between two accounts * diff --git a/crates/grapevine_server/src/routes/proof.rs b/crates/grapevine_server/src/routes/proof.rs index 9c99d75..da32aff 100644 --- a/crates/grapevine_server/src/routes/proof.rs +++ b/crates/grapevine_server/src/routes/proof.rs @@ -366,26 +366,6 @@ pub async fn get_proof_with_params( } } -/** - * Return a list of all proofs linked to a given phrase hash - * - * - * @param phrase hash - the hash of the phrase creating the proof chain - * @return - a vector of stringified OIDs of proofs within the given chain - * @return status: - * - 200 if successful retrieval - * - 401 if signature mismatch or nonce mismatch - * - 404 if user not found - * - 500 if db fails or other unknown issue - */ -#[get("/chain/")] -pub async fn get_proof_chain( - phrase_hash: String, - db: &State, -) -> Result>, Status> { - Ok(Json(db.get_proof_chain(&phrase_hash).await)) -} - /** * Get all created phrases */