diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ae9507f..1c04fb44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,21 @@ file is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased-review-database-0.25] + +### Changed + +- Updated the `ModelIndicator` GraphQL type. Added `name` field as the name of + the model indicator. +- Changed the return type of `indicatorList` GraphQL query to `[ModelIndicator!]!`. + +### Removed + +- Removed the obsoleted `ModelIndicatorOutput` GraphQL type. This type was + previously used as return type of `indicatorList` GraphQL query. With + advancements and improvements in our system, this type is no longer necessary + and has been removed to streamline the codebase and enhance overall maintainability. + ## [Unreleased] ### Added @@ -387,6 +402,7 @@ Versioning](https://semver.org/spec/v2.0.0.html). - An initial version. +[Unreleased-review-database-0.25]: https://github.com/aicers/review-web/compare/main...compat-review-database-0.25 [Unreleased]: https://github.com/aicers/review-web/compare/0.17.0...main [0.17.0]: https://github.com/aicers/review-web/compare/0.16.0...0.17.0 [0.16.0]: https://github.com/aicers/review-web/compare/0.15.0...0.16.0 diff --git a/Cargo.toml b/Cargo.toml index 6aa0461c..25124949 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ oinq = { git = "https://github.com/petabi/oinq.git", tag = "0.9.1" } reqwest = { version = "0.11", default-features = false, features = [ "rustls-tls-native-roots", ] } -review-database = { git = "https://github.com/petabi/review-database.git", rev = "41ebf117" } +review-database = { git = "https://github.com/petabi/review-database.git", rev = "e13263aa" } roxy = { git = "https://github.com/aicers/roxy.git", tag = "0.2.1" } rustls = "0.21" rustls-native-certs = "0.6" diff --git a/src/graphql/indicator.rs b/src/graphql/indicator.rs index 489f6707..bac89869 100644 --- a/src/graphql/indicator.rs +++ b/src/graphql/indicator.rs @@ -1,5 +1,5 @@ use crate::graphql::{Role, RoleGuard}; -use async_graphql::{Context, Object, Result, SimpleObject}; +use async_graphql::{Context, Object, Result}; use chrono::{DateTime, Utc}; use review_database::{self as database}; @@ -12,8 +12,9 @@ impl IndicatorQuery { #[graphql(guard = "RoleGuard::new(Role::SystemAdministrator) .or(RoleGuard::new(Role::SecurityAdministrator))")] async fn indicator(&self, ctx: &Context<'_>, name: String) -> Result> { - let store = super::get_store(ctx).await?; - database::ModelIndicator::get(&store, &name) + let store = crate::graphql::get_store(ctx).await?; + let map = store.model_indicator_map(); + map.get(&name) .map(|indicator| indicator.map(Into::into)) .map_err(Into::into) } @@ -23,18 +24,14 @@ impl IndicatorQuery { .or(RoleGuard::new(Role::SecurityAdministrator)) .or(RoleGuard::new(Role::SecurityManager)) .or(RoleGuard::new(Role::SecurityMonitor))")] - async fn indicator_list(&self, ctx: &Context<'_>) -> Result> { + async fn indicator_list(&self, ctx: &Context<'_>) -> Result> { + use database::Iterable; + let store = super::get_store(ctx).await?; - database::ModelIndicator::get_list(&store) - .map(|list| { - list.into_iter() - .map(|(name, indicator)| ModelIndicatorOutput { - name, - indicator: indicator.into(), - }) - .collect() - }) - .map_err(Into::into) + let map = store.model_indicator_map(); + map.iter(database::Direction::Forward, None) + .map(|res| res.map(Into::into).map_err(Into::into)) + .collect() } } @@ -53,9 +50,10 @@ impl IndicatorMutation { name: String, dbfile: String, ) -> Result { - let indicator = database::ModelIndicator::new(&dbfile)?; + let indicator = database::ModelIndicator::new(&name, &dbfile)?; let store = super::get_store(ctx).await?; - indicator.insert(&store, &name).map_err(Into::into) + let map = store.model_indicator_map(); + map.insert(indicator).map_err(Into::into).map(|()| name) } /// Removes Indicator, returning the db's name and version that no longer exist. @@ -69,7 +67,9 @@ impl IndicatorMutation { #[graphql(validator(min_items = 1))] names: Vec, ) -> Result> { let store = super::get_store(ctx).await?; - database::ModelIndicator::remove(&store, &names).map_err(Into::into) + let map = store.model_indicator_map(); + map.remove(names.iter().map(String::as_str)) + .map_err(Into::into) } /// Updates the given indicator, returning the indicator name that was updated. @@ -84,9 +84,10 @@ impl IndicatorMutation { name: String, new: String, ) -> Result { - let indicator = database::ModelIndicator::new(&new)?; + let indicator = database::ModelIndicator::new(&name, &new)?; let store = super::get_store(ctx).await?; - indicator.update(&store, &name).map_err(Into::into) + let map = store.model_indicator_map(); + map.update(indicator).map_err(Into::into).map(|()| name) } } @@ -96,6 +97,11 @@ struct ModelIndicator { #[Object] impl ModelIndicator { + /// The name of the model indicator. + async fn name(&self) -> &str { + &self.inner.name + } + /// The description of the model indicator. async fn description(&self) -> &str { &self.inner.description @@ -122,10 +128,3 @@ impl From for ModelIndicator { Self { inner } } } - -#[derive(SimpleObject)] -#[allow(clippy::module_name_repetitions)] -pub struct ModelIndicatorOutput { - name: String, - indicator: ModelIndicator, -}