-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1aa56ef
commit fd0c004
Showing
7 changed files
with
107 additions
and
1 deletion.
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
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,42 @@ | ||
use async_graphql::*; | ||
use graphql_core::generic_filters::{EqualFilterInput, StringFilterInput}; | ||
use graphql_core::standard_graphql_error::validate_auth; | ||
use graphql_core::ContextExt; | ||
use graphql_types::types::AbbreviationNode; | ||
use repository::abbreviation::AbbreviationFilter; | ||
use repository::{EqualFilter, StringFilter}; | ||
use service::abbreviation::get_all_abbreviations; | ||
use service::auth::{Resource, ResourceAccessRequest}; | ||
|
||
#[derive(InputObject, Clone)] | ||
pub struct AbbreviationFilterInput { | ||
pub id: Option<EqualFilterInput<String>>, | ||
pub text: Option<StringFilterInput>, | ||
} | ||
|
||
impl AbbreviationFilterInput { | ||
pub fn to_domain(self) -> AbbreviationFilter { | ||
AbbreviationFilter { | ||
id: self.id.map(EqualFilter::from), | ||
text: self.text.map(StringFilter::from), | ||
} | ||
} | ||
} | ||
|
||
pub fn abbreviations( | ||
ctx: &Context<'_>, | ||
filter: AbbreviationFilterInput, | ||
) -> Result<Vec<AbbreviationNode>> { | ||
validate_auth( | ||
ctx, | ||
&ResourceAccessRequest { | ||
resource: Resource::NoPermissionRequired, | ||
store_id: None, | ||
}, | ||
)?; | ||
|
||
let connection_manager = ctx.get_connection_manager(); | ||
let rows = get_all_abbreviations(connection_manager, filter.to_domain())?; | ||
|
||
Ok(AbbreviationNode::from_vec(rows)) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use async_graphql::*; | ||
use repository::abbreviation::Abbreviation; | ||
|
||
pub struct AbbreviationNode { | ||
pub abbreviation: Abbreviation, | ||
} | ||
|
||
#[Object] | ||
impl AbbreviationNode { | ||
pub async fn id(&self) -> &String { | ||
&self.abbreviation.id | ||
} | ||
|
||
pub async fn text(&self) -> &String { | ||
&self.abbreviation.text | ||
} | ||
|
||
pub async fn expansion(&self) -> &String { | ||
&self.abbreviation.expansion | ||
} | ||
} | ||
|
||
impl AbbreviationNode { | ||
pub fn from_domain(row: Abbreviation) -> AbbreviationNode { | ||
AbbreviationNode { abbreviation: row } | ||
} | ||
|
||
pub fn from_vec(abbreviations: Vec<Abbreviation>) -> Vec<AbbreviationNode> { | ||
abbreviations | ||
.into_iter() | ||
.map(AbbreviationNode::from_domain) | ||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use repository::{ | ||
abbreviation::{Abbreviation, AbbreviationFilter, AbbreviationRepository}, | ||
RepositoryError, StorageConnectionManager, | ||
}; | ||
|
||
pub fn get_all_abbreviations( | ||
connection_manager: &StorageConnectionManager, | ||
filter: AbbreviationFilter, | ||
) -> Result<Vec<Abbreviation>, RepositoryError> { | ||
let connection = connection_manager.connection()?; | ||
let repository = AbbreviationRepository::new(&connection); | ||
|
||
let rows = repository.query_by_filter(filter.clone())?; | ||
|
||
Ok(rows) | ||
} |
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