-
Notifications
You must be signed in to change notification settings - Fork 1
96 endpoint for aggregate status list as from the spec #97
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
Open
Blindspot22
wants to merge
14
commits into
main
Choose a base branch
from
96-endpoint-for-aggregate-status-list-as-from-the-spec
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9863831
feat: added a find_all() method to fetch all status list records
Blindspot22 6e57e9e
feat: implemented aggregation_endpoint, token_claims(the new aggregat…
Blindspot22 cf766b1
feat: update README.md with status list aggregation implementaion and…
Blindspot22 747c8e3
feat: status list aggregation implementaion
Blindspot22 5e917ac
feat: test for the aggregation endpoint
Blindspot22 6033604
fix: fmt check
Blindspot22 4f85cb8
fix: Cargo Clippy Check
Blindspot22 886a356
feat: removed unnessary README.md changes
Blindspot22 cdd451e
Refactor: Align aggregation handler with project conventions
Blindspot22 1173a7d
fix: fmt checks
Blindspot22 d969ca5
Adjust: statuslists Endpoint on README.md documentation
Blindspot22 8df11e3
fix: Cargo Nextest
Blindspot22 04ef2b0
fix Nextest
Blindspot22 36ffa90
fix: fmt check
Blindspot22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use crate::utils::state::AppState; | ||
use crate::web::handlers::status_list::error::StatusListError; | ||
use axum::{extract::State, response::IntoResponse, Json}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct AggregationResponse { | ||
pub status_lists: Vec<String>, | ||
} | ||
|
||
pub async fn aggregation( | ||
State(state): State<AppState>, | ||
) -> Result<impl IntoResponse, StatusListError> { | ||
let records = state.status_list_repo.find_all().await.map_err(|e| { | ||
tracing::error!("Failed to fetch all status lists: {:?}", e); | ||
StatusListError::InternalServerError | ||
})?; | ||
let status_lists = records.into_iter().map(|rec| rec.sub).collect(); | ||
Ok(Json(AggregationResponse { status_lists })) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::{ | ||
models::{status_lists, StatusList, StatusListRecord}, | ||
test_utils::test_app_state, | ||
}; | ||
use axum::{body::to_bytes, http::StatusCode, Router}; | ||
use sea_orm::{DatabaseBackend, MockDatabase}; | ||
use std::sync::Arc; | ||
use tower::ServiceExt; // for .oneshot() | ||
|
||
#[tokio::test] | ||
async fn test_aggregation_returns_all_status_list_uris() { | ||
let status_list1 = StatusListRecord { | ||
list_id: "list1".to_string(), | ||
issuer: "issuer1".to_string(), | ||
status_list: StatusList { | ||
bits: 1, | ||
lst: "foo".to_string(), | ||
}, | ||
sub: "https://example.com/statuslists/list1".to_string(), | ||
}; | ||
let status_list2 = StatusListRecord { | ||
list_id: "list2".to_string(), | ||
issuer: "issuer2".to_string(), | ||
status_list: StatusList { | ||
bits: 1, | ||
lst: "bar".to_string(), | ||
}, | ||
sub: "https://example.com/statuslists/list2".to_string(), | ||
}; | ||
let mock_db = MockDatabase::new(DatabaseBackend::Postgres) | ||
.append_query_results::<status_lists::Model, Vec<_>, _>(vec![vec![ | ||
status_list1.clone(), | ||
status_list2.clone(), | ||
]]) | ||
.into_connection(); | ||
let app_state = test_app_state(Some(Arc::new(mock_db))).await; | ||
let app = Router::new() | ||
.route("/aggregation", axum::routing::get(aggregation)) | ||
.with_state(app_state); | ||
let response = app | ||
.oneshot( | ||
axum::http::Request::builder() | ||
.uri("/aggregation") | ||
.body(axum::body::Body::empty()) | ||
.unwrap(), | ||
) | ||
.await | ||
.unwrap(); | ||
assert_eq!(response.status(), StatusCode::OK); | ||
let body = to_bytes(response.into_body(), 1024 * 1024).await.unwrap(); | ||
let result: AggregationResponse = serde_json::from_slice(&body).unwrap(); | ||
assert_eq!(result.status_lists.len(), 2); | ||
assert!(result | ||
.status_lists | ||
.contains(&"https://example.com/statuslists/list1".to_string())); | ||
assert!(result | ||
.status_lists | ||
.contains(&"https://example.com/statuslists/list2".to_string())); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.