Skip to content

Commit

Permalink
Remove default value
Browse files Browse the repository at this point in the history
  • Loading branch information
roxy-dao committed Nov 12, 2024
1 parent ccb240e commit 9567d13
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 91 deletions.
51 changes: 2 additions & 49 deletions server/graphql/types/src/types/program/program_indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use graphql_core::{
generic_filters::EqualFilterStringInput, loader::ProgramByIdLoader, ContextExt,
};
use repository::{
ColumnValue, EqualFilter, IndicatorColumnRow, IndicatorLineRow, IndicatorValueType,
ProgramIndicatorFilter, ProgramIndicatorSort, ProgramIndicatorSortField,
EqualFilter, IndicatorColumnRow, IndicatorLineRow, IndicatorValueType, ProgramIndicatorFilter,
ProgramIndicatorSort, ProgramIndicatorSortField,
};
use service::programs::program_indicator::query::{IndicatorLine, ProgramIndicator};

Expand Down Expand Up @@ -147,11 +147,6 @@ impl IndicatorLineRowNode {
pub async fn name(&self) -> &str {
&self.line.description
}

pub async fn default_value(&self) -> Result<ColumnValueNode, Error> {
let default_value = self.line.get_default_value(&self.line.default_value)?;
Ok(ColumnValueNode::from_domain(default_value))
}
}

impl IndicatorColumnNode {
Expand All @@ -177,11 +172,6 @@ impl IndicatorColumnNode {
pub async fn value_type(&self) -> IndicatorValueTypeNode {
IndicatorValueTypeNode::from_domain(&self.column.value_type)
}

pub async fn default_value(&self) -> Result<ColumnValueNode, Error> {
let default_value = self.column.get_default_value(&self.column.default_value)?;
Ok(ColumnValueNode::from_domain(default_value))
}
}

#[derive(Enum, Copy, Clone, PartialEq, Eq, Debug)]
Expand All @@ -199,40 +189,3 @@ impl IndicatorValueTypeNode {
}
}
}

#[derive(Union)]
pub enum ColumnValueNode {
Text(TextOutput),
Number(NumberOutput),
}

pub struct TextOutput {
value: String,
}

#[Object]
impl TextOutput {
async fn value(&self) -> &str {
&self.value
}
}

pub struct NumberOutput {
value: f64,
}

#[Object]
impl NumberOutput {
async fn value(&self) -> f64 {
self.value
}
}

impl ColumnValueNode {
fn from_domain(value: ColumnValue) -> ColumnValueNode {
match value {
ColumnValue::Text(text) => ColumnValueNode::Text(TextOutput { value: text }),
ColumnValue::Number(number) => ColumnValueNode::Number(NumberOutput { value: number }),
}
}
}
20 changes: 1 addition & 19 deletions server/repository/src/db_diesel/indicator_column_row.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{ColumnValue, IndicatorValueType, StorageConnection};

use super::{IndicatorValueType, StorageConnection};
use crate::{repository_error::RepositoryError, Upsert};

use anyhow::{anyhow, Error};
use diesel::prelude::*;

table! {
Expand Down Expand Up @@ -88,18 +85,3 @@ impl Upsert for IndicatorColumnRow {
)
}
}

impl IndicatorColumnRow {
pub fn get_default_value(&self, value: &str) -> Result<ColumnValue, Error> {
match self.value_type {
Some(IndicatorValueType::Number) => {
let number = value
.parse::<f64>()
.map_err(|_| anyhow!("Failed to parse value as number: {}", value))?;
Ok(ColumnValue::Number(number))
}
Some(IndicatorValueType::String) => Ok(ColumnValue::Text(value.to_string())),
None => Ok(ColumnValue::Text(value.to_string())),
}
}
}
23 changes: 0 additions & 23 deletions server/repository/src/db_diesel/indicator_line_row.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use super::StorageConnection;

use crate::{repository_error::RepositoryError, Upsert};

use anyhow::{anyhow, Error};
use diesel::prelude::*;
use diesel_derive_enum::DbEnum;
use serde::{Deserialize, Serialize};
Expand All @@ -18,12 +16,6 @@ pub enum IndicatorValueType {
Number,
}

#[derive(Clone, Serialize)]
pub enum ColumnValue {
Text(String),
Number(f64),
}

table! {
indicator_line (id) {
id -> Text,
Expand Down Expand Up @@ -107,18 +99,3 @@ impl Upsert for IndicatorLineRow {
)
}
}

impl IndicatorLineRow {
pub fn get_default_value(&self, value: &str) -> Result<ColumnValue, Error> {
match self.value_type {
Some(IndicatorValueType::Number) => {
let number = value
.parse::<f64>()
.map_err(|_| anyhow!("Failed to parse value as number: {}", value))?;
Ok(ColumnValue::Number(number))
}
Some(IndicatorValueType::String) => Ok(ColumnValue::Text(value.to_string())),
None => Ok(ColumnValue::Text(value.to_string())),
}
}
}

0 comments on commit 9567d13

Please sign in to comment.