diff options
Diffstat (limited to 'lib/api-config/src/schema/mod.rs')
| -rw-r--r-- | lib/api-config/src/schema/mod.rs | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/lib/api-config/src/schema/mod.rs b/lib/api-config/src/schema/mod.rs index d16ee9f..54bc015 100644 --- a/lib/api-config/src/schema/mod.rs +++ b/lib/api-config/src/schema/mod.rs @@ -2,6 +2,8 @@ mod create_schema; mod delete_schema; mod get_schema; mod implementation; +mod list_schemas; +mod pagination; mod update_schema; pub use create_schema::CreateSchema; use sqlx::PgPool; @@ -10,11 +12,13 @@ use async_trait::async_trait; use serde::{Deserialize, Serialize}; use std::fmt::Debug; use time::OffsetDateTime; +use warden_core::pagination::Connection; +use warden_core::pagination::PaginationArgs; use crate::ConfigurationError; -/// Transaction to monitor -#[derive(Deserialize, Debug, Serialize)] +/// Transaction's schema +#[derive(Clone, Deserialize, Debug, Serialize)] #[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] #[cfg_attr(feature = "utoipa", schema(example = json!({ "schemaType": "custom.schema", @@ -49,6 +53,9 @@ use crate::ConfigurationError; })))] #[serde(rename_all = "camelCase")] pub struct TransactionSchema { + /// Transaction schema id + #[serde(skip)] + pub id: i64, /// Transaction schema type pub schema_type: String, /// The schema's version @@ -63,8 +70,16 @@ pub struct TransactionSchema { pub updated_at: OffsetDateTime, } +/// The type implementing [SchemaDriver] +#[derive(Debug)] pub struct SchemaService { - pub database: PgPool, + pub(crate) database: PgPool, +} + +impl SchemaService { + pub fn new(database: PgPool) -> Self { + Self { database } + } } #[async_trait] @@ -91,12 +106,11 @@ pub trait SchemaDriver: Send + Sync { schema: &serde_json::Value, ) -> Result<Option<TransactionSchema>, ConfigurationError>; - async fn get_schemas( + async fn list_schemas( &self, + input: &PaginationArgs, limit: i64, - first: Option<i64>, - after: Option<&str>, - ) -> Result<Vec<TransactionSchema>, ConfigurationError>; + ) -> Result<Connection<TransactionSchema>, ConfigurationError>; } #[cfg(test)] @@ -110,7 +124,7 @@ mod tests { fixtures(path = "../../tests/fixtures", scripts("schema")) )] async fn schema(pool: PgPool) -> anyhow::Result<()> { - let driver = SchemaService { database: pool }; + let driver = SchemaService::new(pool); // 2. Define Fixtures let kind = "fin_tx_v1"; @@ -131,6 +145,10 @@ mod tests { .expect("Create failed"); assert_eq!(created.schema_type, kind); + // CREATE AGAIN SHOULD FAIL (CONFLICTING IDs) + let created = driver.create_schema(kind, version, &min_schema).await; + assert!(created.is_err()); + // GET let found = driver .get_schema("payment", "1.0.0") |
