Skip to content

Commit

Permalink
Merge pull request #46 from Mach-34/fix/hash-in-find-degrees
Browse files Browse the repository at this point in the history
Change phrase_hash to phrase in get-new-degrees
  • Loading branch information
jp4g authored Mar 27, 2024
2 parents e4e42da + 8f74ebb commit b163c83
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 47 deletions.
31 changes: 4 additions & 27 deletions crates/grapevine_server/src/mongo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 } }
]
}
},
Expand All @@ -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": {
Expand All @@ -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]
}
Expand Down Expand Up @@ -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<DegreeProof> {
let mut proofs: Vec<DegreeProof> = 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
*
Expand Down
20 changes: 0 additions & 20 deletions crates/grapevine_server/src/routes/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/<phrase_hash>")]
pub async fn get_proof_chain(
phrase_hash: String,
db: &State<GrapevineDB>,
) -> Result<Json<Vec<DegreeProof>>, Status> {
Ok(Json(db.get_proof_chain(&phrase_hash).await))
}

/**
* Get all created phrases
*/
Expand Down

0 comments on commit b163c83

Please sign in to comment.