-
Notifications
You must be signed in to change notification settings - Fork 12
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
Feature branch update for berlinger integration #2421
Closed
andreievg
wants to merge
15
commits into
feature/cold-chain-temperature-sensors
from
Feature-branch-update-for-berlinger-integration
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9c3a99a
Add in external temperature_sensor crate, and Berlinger sensor type
adrianwb 45e9a5c
Add sensor berlinger module (WIP - lots of println!'s), and filter fo…
adrianwb 481a85d
Add in breach configs
adrianwb 8d6bb3b
Add missing description filter for breach config; updated temperature…
adrianwb 70df6ae
Add breaches, but disable filtering for now
adrianwb 718aaa2
After cargo fmt and removing some println!'s
adrianwb 59caf6b
Add a few comments; update sensor breach end time
adrianwb 9b6301c
Only update sensor last connected time and breach end time if they've…
adrianwb cfbf370
Fix bug when adding a new sensor - don't set the last connected time …
adrianwb 927c969
Remove debugging function calls
adrianwb 0c81180
Use is_empty()
adrianwb 149d668
Add missing migrations for BERLINGER sensor type
adrianwb 501b864
Merge branch 'feature/cold-chain-temperature-sensors' into Feature-br…
andreievg 322188e
Post merge changes
andreievg efd640f
Reinstate temperature breach config
andreievg 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
use repository::EqualFilter; | ||
use repository::{ | ||
temperature_breach::{TemperatureBreach, TemperatureBreachFilter, TemperatureBreachRepository}, | ||
RepositoryError, StorageConnectionManager, | ||
}; | ||
|
||
use async_graphql::dataloader::*; | ||
use async_graphql::*; | ||
use std::collections::HashMap; | ||
|
||
pub struct TemperatureBreachByIdLoader { | ||
pub connection_manager: StorageConnectionManager, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Loader<String> for TemperatureBreachByIdLoader { | ||
type Value = TemperatureBreach; | ||
type Error = RepositoryError; | ||
|
||
async fn load(&self, ids: &[String]) -> Result<HashMap<String, Self::Value>, Self::Error> { | ||
let connection = self.connection_manager.connection()?; | ||
let repo = TemperatureBreachRepository::new(&connection); | ||
|
||
let result = | ||
repo.query_by_filter(TemperatureBreachFilter::new().id(EqualFilter::equal_any(ids.to_owned())))?; | ||
|
||
Ok(result | ||
.into_iter() | ||
.map(|temperature_breach| (temperature_breach.temperature_breach_row.id.clone(), temperature_breach)) | ||
.collect()) | ||
} | ||
} | ||
use repository::EqualFilter; | ||
use repository::{ | ||
temperature_breach::{TemperatureBreach, TemperatureBreachFilter, TemperatureBreachRepository}, | ||
RepositoryError, StorageConnectionManager, | ||
}; | ||
|
||
use async_graphql::dataloader::*; | ||
use async_graphql::*; | ||
use std::collections::HashMap; | ||
|
||
pub struct TemperatureBreachByIdLoader { | ||
pub connection_manager: StorageConnectionManager, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Loader<String> for TemperatureBreachByIdLoader { | ||
type Value = TemperatureBreach; | ||
type Error = RepositoryError; | ||
|
||
async fn load(&self, ids: &[String]) -> Result<HashMap<String, Self::Value>, Self::Error> { | ||
let connection = self.connection_manager.connection()?; | ||
let repo = TemperatureBreachRepository::new(&connection); | ||
|
||
let result = repo.query_by_filter( | ||
TemperatureBreachFilter::new().id(EqualFilter::equal_any(ids.to_owned())), | ||
)?; | ||
|
||
Ok(result | ||
.into_iter() | ||
.map(|temperature_breach| { | ||
( | ||
temperature_breach.temperature_breach_row.id.clone(), | ||
temperature_breach, | ||
) | ||
}) | ||
.collect()) | ||
} | ||
} |
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
166 changes: 166 additions & 0 deletions
166
server/repository/src/db_diesel/temperature_breach_config.rs
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 |
---|---|---|
@@ -0,0 +1,166 @@ | ||
use super::{ | ||
temperature_breach_config_row::{ | ||
temperature_breach_config, temperature_breach_config::dsl as temperature_breach_config_dsl, | ||
}, | ||
DBType, StorageConnection, TemperatureBreachConfigRow, TemperatureBreachRowType, | ||
}; | ||
use diesel::prelude::*; | ||
|
||
use crate::{ | ||
diesel_macros::{apply_equal_filter, apply_sort_no_case}, | ||
repository_error::RepositoryError, | ||
}; | ||
|
||
use crate::{EqualFilter, Pagination, Sort}; | ||
|
||
#[derive(PartialEq, Debug, Clone)] | ||
pub struct TemperatureBreachConfig { | ||
pub temperature_breach_config_row: TemperatureBreachConfigRow, | ||
} | ||
|
||
#[derive(Clone, PartialEq, Debug)] | ||
pub struct TemperatureBreachConfigFilter { | ||
pub id: Option<EqualFilter<String>>, | ||
pub r#type: Option<EqualFilter<TemperatureBreachRowType>>, | ||
pub is_active: Option<bool>, | ||
pub store_id: Option<EqualFilter<String>>, | ||
pub description: Option<EqualFilter<String>>, | ||
} | ||
|
||
#[derive(PartialEq, Debug)] | ||
pub enum TemperatureBreachConfigSortField { | ||
Id, | ||
Description, | ||
} | ||
|
||
pub type TemperatureBreachConfigSort = Sort<TemperatureBreachConfigSortField>; | ||
|
||
pub struct TemperatureBreachConfigRepository<'a> { | ||
connection: &'a StorageConnection, | ||
} | ||
|
||
impl<'a> TemperatureBreachConfigRepository<'a> { | ||
pub fn new(connection: &'a StorageConnection) -> Self { | ||
TemperatureBreachConfigRepository { connection } | ||
} | ||
|
||
pub fn count( | ||
&self, | ||
filter: Option<TemperatureBreachConfigFilter>, | ||
) -> Result<i64, RepositoryError> { | ||
let query = create_filtered_query(filter); | ||
Ok(query.count().get_result(&self.connection.connection)?) | ||
} | ||
|
||
pub fn query_by_filter( | ||
&self, | ||
filter: TemperatureBreachConfigFilter, | ||
) -> Result<Vec<TemperatureBreachConfig>, RepositoryError> { | ||
self.query(Pagination::all(), Some(filter), None) | ||
} | ||
|
||
pub fn query( | ||
&self, | ||
pagination: Pagination, | ||
filter: Option<TemperatureBreachConfigFilter>, | ||
sort: Option<TemperatureBreachConfigSort>, | ||
) -> Result<Vec<TemperatureBreachConfig>, RepositoryError> { | ||
let mut query = create_filtered_query(filter); | ||
if let Some(sort) = sort { | ||
match sort.key { | ||
TemperatureBreachConfigSortField::Id => { | ||
apply_sort_no_case!(query, sort, temperature_breach_config_dsl::id) | ||
} | ||
TemperatureBreachConfigSortField::Description => { | ||
apply_sort_no_case!(query, sort, temperature_breach_config_dsl::description) | ||
} | ||
} | ||
} else { | ||
let sort = TemperatureBreachConfigSort { | ||
key: TemperatureBreachConfigSortField::Description, | ||
desc: Some(false), | ||
}; | ||
apply_sort_no_case!(query, sort, temperature_breach_config_dsl::description) | ||
} | ||
|
||
let result = query | ||
.offset(pagination.offset as i64) | ||
.limit(pagination.limit as i64) | ||
.load::<TemperatureBreachConfigRow>(&self.connection.connection)?; | ||
|
||
Ok(result.into_iter().map(to_domain).collect()) | ||
} | ||
} | ||
|
||
type BoxedLogQuery = temperature_breach_config::BoxedQuery<'static, DBType>; | ||
|
||
fn create_filtered_query(filter: Option<TemperatureBreachConfigFilter>) -> BoxedLogQuery { | ||
let mut query = temperature_breach_config::table.into_boxed(); | ||
|
||
if let Some(filter) = filter { | ||
apply_equal_filter!(query, filter.id, temperature_breach_config_dsl::id); | ||
apply_equal_filter!(query, filter.r#type, temperature_breach_config_dsl::type_); | ||
apply_equal_filter!( | ||
query, | ||
filter.description, | ||
temperature_breach_config_dsl::description | ||
); | ||
|
||
if let Some(value) = filter.is_active { | ||
query = query.filter(temperature_breach_config_dsl::is_active.eq(value)); | ||
} | ||
|
||
apply_equal_filter!( | ||
query, | ||
filter.store_id, | ||
temperature_breach_config_dsl::store_id | ||
); | ||
} | ||
|
||
query | ||
} | ||
|
||
pub fn to_domain( | ||
temperature_breach_config_row: TemperatureBreachConfigRow, | ||
) -> TemperatureBreachConfig { | ||
TemperatureBreachConfig { | ||
temperature_breach_config_row, | ||
} | ||
} | ||
|
||
impl TemperatureBreachConfigFilter { | ||
pub fn new() -> TemperatureBreachConfigFilter { | ||
TemperatureBreachConfigFilter { | ||
id: None, | ||
is_active: None, | ||
r#type: None, | ||
store_id: None, | ||
description: None, | ||
} | ||
} | ||
|
||
pub fn id(mut self, filter: EqualFilter<String>) -> Self { | ||
self.id = Some(filter); | ||
self | ||
} | ||
|
||
pub fn is_active(mut self, filter: bool) -> Self { | ||
self.is_active = Some(filter); | ||
self | ||
} | ||
|
||
pub fn r#type(mut self, filter: EqualFilter<TemperatureBreachRowType>) -> Self { | ||
self.r#type = Some(filter); | ||
self | ||
} | ||
|
||
pub fn store_id(mut self, filter: EqualFilter<String>) -> Self { | ||
self.store_id = Some(filter); | ||
self | ||
} | ||
|
||
pub fn description(mut self, filter: EqualFilter<String>) -> Self { | ||
self.description = Some(filter); | ||
self | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄 I added this in another PR and then removed it! ( taking the minimalist approach.. don't add code that we aren't using and I didn't need it anymore! )
Glad to see that it's back