Skip to content

Commit

Permalink
Add soil_types get all and get one endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
evanjt committed Sep 24, 2024
1 parent 31f7458 commit b9a27cc
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 92 deletions.
1 change: 0 additions & 1 deletion src/areas/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use sea_orm::{query::*, DatabaseConnection};
use sea_query::Expr;
use serde::Serialize;
use serde_json::Value;
use tracing_subscriber::registry::Data;
use utoipa::ToSchema;
use uuid::Uuid;

Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async fn main() {
.nest("/v1/plot_samples", samples::views::router(db.clone()))
.nest("/v1/sensors", sensors::views::router(db.clone()))
.nest("/v1/transects", transects::views::router(db.clone()))
.nest("/v1/soil_types", soil::types::views::router(db.clone()))
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()))
.merge(Redoc::with_url("/redoc", ApiDoc::openapi()))
.merge(Scalar::with_url("/scalar", ApiDoc::openapi()));
Expand Down
152 changes: 76 additions & 76 deletions src/samples/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,85 +144,85 @@ impl PlotSample {
plot_samples
}

pub async fn get_one(id: Uuid, db: &DatabaseConnection) -> Option<Self> {
let sample = crate::samples::db::Entity::find()
.filter(crate::samples::db::Column::Id.eq(id))
.one(db)
.await
.unwrap()
.unwrap();
// pub async fn get_one(id: Uuid, db: &DatabaseConnection) -> Option<Self> {
// let sample = crate::samples::db::Entity::find()
// .filter(crate::samples::db::Column::Id.eq(id))
// .one(db)
// .await
// .unwrap()
// .unwrap();

let plot_obj = crate::plots::db::Entity::find()
.filter(crate::plots::db::Column::Id.eq(sample.plot_id))
.one(db)
.await
.unwrap()
.unwrap();
// let plot_obj = crate::plots::db::Entity::find()
// .filter(crate::plots::db::Column::Id.eq(sample.plot_id))
// .one(db)
// .await
// .unwrap()
// .unwrap();

let area = crate::areas::db::Entity::find()
.filter(crate::areas::db::Column::Id.eq(plot_obj.area_id))
.one(db)
.await
.unwrap()
.unwrap();
// let area = crate::areas::db::Entity::find()
// .filter(crate::areas::db::Column::Id.eq(plot_obj.area_id))
// .one(db)
// .await
// .unwrap()
// .unwrap();

let project = crate::projects::db::Entity::find()
.filter(crate::projects::db::Column::Id.eq(area.project_id))
.one(db)
.await
.unwrap()
.unwrap();
// let project = crate::projects::db::Entity::find()
// .filter(crate::projects::db::Column::Id.eq(area.project_id))
// .one(db)
// .await
// .unwrap()
// .unwrap();

let plot = crate::plots::models::PlotBasicWithAreaAndProject {
id: plot_obj.id,
name: plot_obj.name,
area: crate::areas::models::AreaBasicWithProject {
id: area.id,
name: area.name,
project: crate::common::models::GenericNameAndID {
id: project.id,
name: project.name,
},
},
};
// let plot = crate::plots::models::PlotBasicWithAreaAndProject {
// id: plot_obj.id,
// name: plot_obj.name,
// area: crate::areas::models::AreaBasicWithProject {
// id: area.id,
// name: area.name,
// project: crate::common::models::GenericNameAndID {
// id: project.id,
// name: project.name,
// },
// },
// };

Some(PlotSample {
id: sample.id,
name: sample.name,
upper_depth_cm: sample.upper_depth_cm,
lower_depth_cm: sample.lower_depth_cm,
plot_id: sample.plot_id,
sample_weight: sample.sample_weight,
subsample_weight: sample.subsample_weight,
ph: sample.ph,
rh: sample.rh,
loi: sample.loi,
mfc: sample.mfc,
c: sample.c,
n: sample.n,
cn: sample.cn,
clay_percent: sample.clay_percent,
silt_percent: sample.silt_percent,
sand_percent: sample.sand_percent,
fe_ug_per_g: sample.fe_ug_per_g,
na_ug_per_g: sample.na_ug_per_g,
al_ug_per_g: sample.al_ug_per_g,
k_ug_per_g: sample.k_ug_per_g,
ca_ug_per_g: sample.ca_ug_per_g,
mg_ug_per_g: sample.mg_ug_per_g,
mn_ug_per_g: sample.mn_ug_per_g,
s_ug_per_g: sample.s_ug_per_g,
cl_ug_per_g: sample.cl_ug_per_g,
p_ug_per_g: sample.p_ug_per_g,
si_ug_per_g: sample.si_ug_per_g,
subsample_replica_weight: sample.subsample_replica_weight,
fungi_per_g: sample.fungi_per_g,
bacteria_per_g: sample.bacteria_per_g,
archea_per_g: sample.archea_per_g,
methanogens_per_g: sample.methanogens_per_g,
methanotrophs_per_g: sample.methanotrophs_per_g,
replicate: sample.replicate,
plot: plot,
})
}
// Some(PlotSample {
// id: sample.id,
// name: sample.name,
// upper_depth_cm: sample.upper_depth_cm,
// lower_depth_cm: sample.lower_depth_cm,
// plot_id: sample.plot_id,
// sample_weight: sample.sample_weight,
// subsample_weight: sample.subsample_weight,
// ph: sample.ph,
// rh: sample.rh,
// loi: sample.loi,
// mfc: sample.mfc,
// c: sample.c,
// n: sample.n,
// cn: sample.cn,
// clay_percent: sample.clay_percent,
// silt_percent: sample.silt_percent,
// sand_percent: sample.sand_percent,
// fe_ug_per_g: sample.fe_ug_per_g,
// na_ug_per_g: sample.na_ug_per_g,
// al_ug_per_g: sample.al_ug_per_g,
// k_ug_per_g: sample.k_ug_per_g,
// ca_ug_per_g: sample.ca_ug_per_g,
// mg_ug_per_g: sample.mg_ug_per_g,
// mn_ug_per_g: sample.mn_ug_per_g,
// s_ug_per_g: sample.s_ug_per_g,
// cl_ug_per_g: sample.cl_ug_per_g,
// p_ug_per_g: sample.p_ug_per_g,
// si_ug_per_g: sample.si_ug_per_g,
// subsample_replica_weight: sample.subsample_replica_weight,
// fungi_per_g: sample.fungi_per_g,
// bacteria_per_g: sample.bacteria_per_g,
// archea_per_g: sample.archea_per_g,
// methanogens_per_g: sample.methanogens_per_g,
// methanotrophs_per_g: sample.methanotrophs_per_g,
// replicate: sample.replicate,
// plot: plot,
// })
// }
}
1 change: 0 additions & 1 deletion src/samples/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use axum::{
http::header::HeaderMap,
routing, Json, Router,
};
use sea_orm::sqlx::Result;
use sea_orm::Condition;
use sea_orm::EntityTrait;
use sea_orm::{query::*, DatabaseConnection};
Expand Down
22 changes: 11 additions & 11 deletions src/sensors/services.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// use crate::common::models::ClosestFeature;
use crate::common::models::ClosestFeature;
use crate::sensors::data::db::Entity as SensorDataDB;
use crate::sensors::db::Entity as SensorDB;
// use crate::common::models::ClosestFeature;
// use crate::sensors::data::db::Entity as SensorDataDB;
// use crate::sensors::db::Entity as SensorDB;
use lttb::lttb;
use sea_orm::DbBackend;
use sea_orm::{query::*, DatabaseConnection};
use sea_query::Alias;
use sea_query::Expr;
use sea_query::Order;
use serde_json::json;
use std::cmp::min;
use uuid::Uuid;
// use sea_orm::DbBackend;
// use sea_orm::{query::*, DatabaseConnection};
// use sea_query::Alias;
// use sea_query::Expr;
// use sea_query::Order;
// use serde_json::json;
// use std::cmp::min;
// use uuid::Uuid;

// pub async fn fetch_closest_features(
// sensor_id: Uuid,
Expand Down
3 changes: 2 additions & 1 deletion src/soil/types/db.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use chrono::NaiveDateTime;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "soiltype")]
pub struct Model {
pub name: String,
Expand Down
2 changes: 2 additions & 0 deletions src/soil/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pub mod db;
pub mod models;
pub mod views;
20 changes: 20 additions & 0 deletions src/soil/types/models.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use serde::Serialize;
use utoipa::ToSchema;
use uuid::Uuid;

#[derive(ToSchema, Serialize)]
pub struct SoilType {
pub id: Uuid,
pub last_updated: chrono::NaiveDateTime,
pub name: Option<String>,
pub description: String,
pub image: Option<String>,
}

#[derive(ToSchema, Serialize)]
pub struct SoilTypeBasic {
pub id: Uuid,
pub last_updated: chrono::NaiveDateTime,
pub name: Option<String>,
pub description: String,
}
Loading

0 comments on commit b9a27cc

Please sign in to comment.