Skip to content
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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/packages/common/src/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4426,6 +4426,7 @@ export type SensorNode = {
};

export enum SensorNodeType {
Berlinger = 'BERLINGER',
Copy link
Collaborator

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

BlueMaestro = 'BLUE_MAESTRO',
Laird = 'LAIRD'
}
Expand Down
43 changes: 43 additions & 0 deletions server/Cargo.lock

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

70 changes: 38 additions & 32 deletions server/graphql/core/src/loader/temperature_breach.rs
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())
}
}
3 changes: 3 additions & 0 deletions server/graphql/types/src/types/sensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub struct SensorConnector {
pub enum SensorNodeType {
BlueMaestro,
Laird,
Berlinger,
}

#[Object]
Expand Down Expand Up @@ -231,6 +232,7 @@ impl SensorNodeType {
match from {
from::BlueMaestro => to::BlueMaestro,
from::Laird => to::Laird,
from::Berlinger => to::Berlinger,
}
}

Expand All @@ -241,6 +243,7 @@ impl SensorNodeType {
match self {
from::BlueMaestro => to::BlueMaestro,
from::Laird => to::Laird,
from::Berlinger => to::Berlinger,
}
}
}
4 changes: 4 additions & 0 deletions server/repository/src/db_diesel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ mod sync_buffer;
mod sync_log;
mod sync_log_row;
pub mod temperature_breach;
mod temperature_breach_config;
mod temperature_breach_config_row;
mod temperature_breach_row;
pub mod temperature_log;
mod temperature_log_row;
Expand Down Expand Up @@ -155,6 +157,8 @@ pub use sync_buffer::*;
pub use sync_log::*;
pub use sync_log_row::*;
pub use temperature_breach::*;
pub use temperature_breach_config::*;
pub use temperature_breach_config_row::*;
pub use temperature_breach_row::*;
pub use temperature_log::*;
pub use temperature_log_row::*;
Expand Down
2 changes: 2 additions & 0 deletions server/repository/src/db_diesel/sensor_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ joinable!(sensor -> location (location_id));
pub enum SensorType {
BlueMaestro,
Laird,
Berlinger,
}

// TODO put this somewhere more sensible
Expand All @@ -49,6 +50,7 @@ pub fn get_sensor_type(serial: &String) -> SensorType {
match serial.split('|').nth(1) {
Some("BLUE_MAESTRO") => SensorType::BlueMaestro,
Some("LAIRD") => SensorType::Laird,
Some("BERLINGER") => SensorType::Berlinger,
_ => SensorType::BlueMaestro,
}
}
Expand Down
6 changes: 6 additions & 0 deletions server/repository/src/db_diesel/temperature_breach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ pub struct TemperatureBreachFilter {
pub location: Option<LocationFilter>,
}

impl EqualFilter<TemperatureBreachRowType> {
pub fn equal_to_breach_type(value: &TemperatureBreachRowType) -> Self {
inline_init(|r: &mut Self| r.equal_to = Some(value.to_owned()))
}
}

#[derive(PartialEq, Debug)]
pub enum TemperatureBreachSortField {
Id,
Expand Down
166 changes: 166 additions & 0 deletions server/repository/src/db_diesel/temperature_breach_config.rs
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
}
}
Loading
Loading