Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change phrase_hash to phrase in get-new-degrees #46

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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