-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from avored/209-move-element-data-type-to-be-…
…inside-the-component-table 209 move element data type to be inside the component table
- Loading branch information
Showing
16 changed files
with
497 additions
and
235 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,52 +1,77 @@ | ||
use std::sync::Arc; | ||
use axum::extract::State; | ||
use axum::Json; | ||
use crate::responses::ApiResponse; | ||
use crate::avored_state::AvoRedState; | ||
use crate::error::Result; | ||
use crate::models::component_model::ComponentModel; | ||
|
||
pub async fn component_all_api_handler( | ||
state: State<Arc<AvoRedState>> | ||
) -> Result<Json<Vec<ComponentModel>>> { | ||
) -> Result<Json<ApiResponse<Vec<ComponentModel>>>> { | ||
println!("->> {:<12} - component_all_api_handler", "HANDLER"); | ||
|
||
Ok(Json(state.component_service.all(&state.db).await?)) | ||
let all_components = state.component_service.all(&state.db).await?; | ||
let response = ApiResponse { | ||
status: true, | ||
data: all_components | ||
}; | ||
Ok(Json(response)) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use axum::body::Body; | ||
use axum::http::StatusCode; | ||
use serde_json::{json, Value}; | ||
use tower::ServiceExt; | ||
use crate::api::handlers::setup::post_setup_avored_handler::SetupViewModel; | ||
use crate::api::rest_api_routes::tests::{get_axum_app, send_post_request}; | ||
use crate::error::Result; | ||
use crate::api::rest_api_routes::tests::{get_auth_token, get_axum_app, send_get_request}; | ||
use crate::responses::ApiResponse; | ||
use crate::error::{Result, Error}; | ||
use crate::models::component_model::ComponentModel; | ||
use crate::repositories::into_iter_objects; | ||
|
||
#[tokio::test] | ||
async fn test_component_all_api_handler() -> Result<()> | ||
{ | ||
let app = get_axum_app().await.unwrap(); | ||
let body = Body::from( | ||
r#"{ | ||
"email": "[email protected]", | ||
"password": "admin123" | ||
let (app, state) = get_axum_app().await.unwrap(); | ||
let token = get_auth_token(state.clone())?; | ||
|
||
}"#, | ||
); | ||
let sql = " | ||
CREATE components:content_id_1 CONTENT { | ||
name: 'unittest name 1', | ||
identifier: 'unittest identifier 1', | ||
element_type: 'TEXT', | ||
element_type: '[]', | ||
created_at: time::now(), | ||
updated_at: time::now(), | ||
} | ||
"; | ||
|
||
//@todo check for component-all-api with success response | ||
let response = app.oneshot(send_post_request("/api/setup", body)).await.unwrap(); | ||
let (ds, ses) = &state.db; | ||
|
||
assert_eq!(response.status(), StatusCode::OK); | ||
let dummy_res = SetupViewModel { | ||
status: true | ||
let query_responses = ds.execute(sql, ses, None).await?; | ||
let result_object_option = into_iter_objects(query_responses)?.next(); | ||
let result_object = match result_object_option { | ||
Some(object) => object, | ||
None => Err(Error::Generic("no record found".to_string())), | ||
}; | ||
let component_model: ComponentModel = result_object?.try_into()?; | ||
|
||
let mut all_components: Vec<ComponentModel> = vec![]; | ||
all_components.push(component_model); | ||
|
||
let dummy_res = ApiResponse { | ||
status: true, | ||
data: all_components | ||
}; | ||
|
||
let response = app.oneshot(send_get_request("/api/component-all", token)).await.unwrap(); | ||
|
||
assert_eq!(response.status(), StatusCode::OK); | ||
let res_b = response.into_body(); | ||
let body = axum::body::to_bytes(res_b, usize::MAX).await.unwrap(); | ||
let body: Value = serde_json::from_slice(&body).unwrap(); | ||
assert_eq!(body, json!(&dummy_res)); | ||
|
||
println!("Component_ALL: {:?}", json!(&dummy_res)); | ||
Ok(()) | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.