Skip to content

Commit

Permalink
move find_all to entity_api
Browse files Browse the repository at this point in the history
  • Loading branch information
calebbourg committed Nov 16, 2023
1 parent 3ca3c9d commit 4e25708
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions entity_api/src/organization.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use entity::organization;
use organization::{Entity, Model};
use sea_orm::{entity::prelude::*, ActiveValue, DatabaseConnection};
use serde_json::json;

pub async fn find_all(db: &DatabaseConnection) -> Vec<Model> {
Entity::find().all(db).await.unwrap_or(vec![])
}

pub(crate) async fn seed_database(db: &DatabaseConnection) {
let organization_names = [
"Jim Hodapp Coaching",
Expand Down
1 change: 1 addition & 0 deletions web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
entity = { path = "../entity" }
entity_api = { path = "../entity_api" }
service = { path = "../service" }

axum = "0.6.20"
Expand Down
6 changes: 2 additions & 4 deletions web/src/controller/organization_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use sea_orm::ActiveModelTrait;
use sea_orm::ActiveValue::{NotSet, Set};
use sea_orm::DeleteResult;
use serde_json::json;
use entity_api::organization as OrganizationApi;

extern crate log;
use log::*;
Expand All @@ -21,10 +22,7 @@ impl OrganizationController {
/// --request GET \
/// http://localhost:3000/organizations
pub async fn index(State(app_state): State<AppState>) -> impl IntoResponse {
let organizations = organization::Entity::find()
.all(&app_state.database_connection.unwrap())
.await
.unwrap_or(vec![]);
let organizations = OrganizationApi::find_all(&app_state.database_connection.unwrap()).await;

Json(organizations)
}
Expand Down

0 comments on commit 4e25708

Please sign in to comment.