aboutsummaryrefslogtreecommitdiffstats
path: root/lib/api-config
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2026-03-30 17:46:25 +0200
committerrtkay123 <dev@kanjala.com>2026-03-30 17:46:25 +0200
commitcec58d78e968250e4c589899eab460d1132f6d01 (patch)
tree53fcd3e1781ebf337a6ce56ca726cd91457e258c /lib/api-config
parent4071482f983d66b16cc8a5519f5665990dc7bc02 (diff)
downloadwarden-cec58d78e968250e4c589899eab460d1132f6d01.tar.bz2
warden-cec58d78e968250e4c589899eab460d1132f6d01.zip
refactor: generic svcs
Diffstat (limited to 'lib/api-config')
-rw-r--r--lib/api-config/src/schema/mod.rs66
1 files changed, 33 insertions, 33 deletions
diff --git a/lib/api-config/src/schema/mod.rs b/lib/api-config/src/schema/mod.rs
index 7c65d49..f626e87 100644
--- a/lib/api-config/src/schema/mod.rs
+++ b/lib/api-config/src/schema/mod.rs
@@ -1,12 +1,12 @@
mod create;
pub use create::CreateSchema;
+use sqlx::PgPool;
use tracing::debug;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use time::OffsetDateTime;
-use warden_core::state::AppState;
use crate::ConfigurationError;
@@ -60,31 +60,31 @@ pub struct TransactionSchema {
pub updated_at: OffsetDateTime,
}
+pub struct SchemaService {
+ pub database: PgPool,
+}
+
#[async_trait]
-pub trait SchemaDriver {
+pub trait SchemaDriver: Send + Sync {
async fn create_schema(
&self,
- kind: impl AsRef<str> + Send + Sync + Debug,
- version: impl AsRef<str> + Send + Sync + Debug,
+ kind: &str,
+ version: &str,
schema: &serde_json::Value,
) -> Result<TransactionSchema, ConfigurationError>;
- async fn delete_schema(
- &self,
- kind: impl AsRef<str> + Send + Sync + Debug,
- version: impl AsRef<str> + Send + Sync + Debug,
- ) -> Result<(), ConfigurationError>;
+ async fn delete_schema(&self, kind: &str, version: &str) -> Result<(), ConfigurationError>;
async fn get_schema(
&self,
- kind: impl AsRef<str> + Send + Sync + Debug,
- version: impl AsRef<str> + Send + Sync + Debug,
+ kind: &str,
+ version: &str,
) -> Result<Option<TransactionSchema>, ConfigurationError>;
async fn update_schema(
&self,
- kind: impl AsRef<str> + Send + Sync + Debug,
- version: impl AsRef<str> + Send + Sync + Debug,
+ kind: &str,
+ version: &str,
schema: &serde_json::Value,
) -> Result<Option<TransactionSchema>, ConfigurationError>;
@@ -92,17 +92,17 @@ pub trait SchemaDriver {
&self,
limit: i64,
first: Option<i64>,
- after: Option<impl AsRef<str> + Send + Sync + Debug>,
+ after: Option<&str>,
) -> Result<Vec<TransactionSchema>, ConfigurationError>;
}
#[async_trait]
-impl SchemaDriver for AppState {
+impl SchemaDriver for SchemaService {
#[tracing::instrument(skip(self, schema))]
async fn create_schema(
&self,
- kind: impl AsRef<str> + Send + Sync + Debug,
- version: impl AsRef<str> + Send + Sync + Debug,
+ kind: &str,
+ version: &str,
schema: &serde_json::Value,
) -> Result<TransactionSchema, crate::ConfigurationError> {
debug!("creating transaction schema");
@@ -111,8 +111,8 @@ impl SchemaDriver for AppState {
"insert into transaction_schema (schema_type, schema_version, schema) values ($1, $2, $3)
returning *
",
- kind.as_ref(),
- version.as_ref(),
+ kind,
+ version,
sqlx::types::Json(&schema) as _
)
.fetch_one(&self.database)
@@ -123,14 +123,14 @@ impl SchemaDriver for AppState {
#[tracing::instrument(skip(self))]
async fn delete_schema(
&self,
- kind: impl AsRef<str> + Send + Sync + Debug,
- version: impl AsRef<str> + Send + Sync + Debug,
+ kind: &str,
+ version: &str,
) -> Result<(), crate::ConfigurationError> {
debug!("deleting transaction schema");
sqlx::query!(
"delete from transaction_schema where schema_type = $1 and schema_version = $2",
- kind.as_ref(),
- version.as_ref(),
+ kind,
+ version,
)
.execute(&self.database)
.await?;
@@ -140,8 +140,8 @@ impl SchemaDriver for AppState {
#[tracing::instrument(skip(self))]
async fn get_schema(
&self,
- kind: impl AsRef<str> + Send + Sync + Debug,
- version: impl AsRef<str> + Send + Sync + Debug,
+ kind: &str,
+ version: &str,
) -> Result<Option<TransactionSchema>, crate::ConfigurationError> {
debug!("getting transaction schema");
let result = sqlx::query_as!(
@@ -149,8 +149,8 @@ impl SchemaDriver for AppState {
"select
*
from transaction_schema where schema_type = $1 and schema_version = $2",
- kind.as_ref(),
- version.as_ref(),
+ kind,
+ version,
)
.fetch_optional(&self.database)
.await?;
@@ -161,8 +161,8 @@ impl SchemaDriver for AppState {
#[tracing::instrument(skip(self, schema))]
async fn update_schema(
&self,
- kind: impl AsRef<str> + Send + Sync + Debug,
- version: impl AsRef<str> + Send + Sync + Debug,
+ kind: &str,
+ version: &str,
schema: &serde_json::Value,
) -> Result<Option<TransactionSchema>, crate::ConfigurationError> {
debug!("updating transaction schema");
@@ -178,8 +178,8 @@ impl SchemaDriver for AppState {
and schema_version = $2
returning *
",
- kind.as_ref(),
- version.as_ref(),
+ kind,
+ version,
sqlx::types::Json(&schema) as _
)
.fetch_optional(&self.database)
@@ -192,7 +192,7 @@ impl SchemaDriver for AppState {
&self,
limit: i64,
first: Option<i64>,
- after: Option<impl AsRef<str> + Send + Sync + Debug>,
+ after: Option<&str>,
) -> Result<Vec<TransactionSchema>, ConfigurationError> {
debug!("getting transaction schemas");
let limit = first.unwrap_or(limit);
@@ -200,7 +200,7 @@ impl SchemaDriver for AppState {
let mut last_version = String::default();
if let Some(s) = after {
- let parts: Vec<&str> = s.as_ref().split(',').collect();
+ let parts: Vec<&str> = s.split(',').collect();
if parts.len() == 2 {
last_type = parts[0].to_string();
last_version = parts[1].to_string();