-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: some quality of life improvements (#73)
* feat: support starting block * feat: better indexers id
- Loading branch information
Showing
10 changed files
with
68 additions
and
160 deletions.
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
4 changes: 4 additions & 0 deletions
4
migrations/2025-01-22-173123_add_indexer_starting_block/down.sql
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,4 @@ | ||
-- This file should undo anything in `up.sql` | ||
|
||
ALTER TABLE indexers DROP COLUMN starting_block; | ||
ALTER TABLE indexers DROP COLUMN indexer_id; |
4 changes: 4 additions & 0 deletions
4
migrations/2025-01-22-173123_add_indexer_starting_block/up.sql
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,4 @@ | ||
-- Your SQL goes here | ||
|
||
ALTER TABLE indexers ADD COLUMN starting_block BIGINT; | ||
ALTER TABLE indexers ADD COLUMN indexer_id VARCHAR; |
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
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
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 |
---|---|---|
@@ -1,130 +1,2 @@ | ||
use std::str::FromStr; | ||
|
||
use axum::async_trait; | ||
use uuid::Uuid; | ||
|
||
use crate::domain::models::indexer::{IndexerModel, IndexerStatus, IndexerType}; | ||
use crate::infra::errors::InfraError; | ||
use crate::infra::repositories::indexer_repository::{ | ||
IndexerFilter, NewIndexerDb, Repository, UpdateIndexerStatusAndProcessIdDb, UpdateIndexerStatusDb, | ||
}; | ||
|
||
pub mod constants; | ||
pub mod utils; | ||
|
||
/// Mock the database | ||
#[derive(Debug)] | ||
pub struct MockRepository { | ||
indexers: Vec<IndexerModel>, | ||
} | ||
|
||
impl MockRepository { | ||
pub fn _new() -> Self { | ||
Self { | ||
indexers: vec![ | ||
IndexerModel { | ||
id: uuid::Uuid::new_v4(), | ||
status: IndexerStatus::Created, | ||
indexer_type: IndexerType::Webhook, | ||
process_id: None, | ||
target_url: Some("https://example.com".to_string()), | ||
table_name: None, | ||
status_server_port: None, | ||
custom_connection_string: None, | ||
}, | ||
IndexerModel { | ||
id: uuid::Uuid::new_v4(), | ||
status: IndexerStatus::Running, | ||
indexer_type: IndexerType::Webhook, | ||
process_id: Some(123), | ||
target_url: Some("https://example.com".to_string()), | ||
table_name: None, | ||
status_server_port: None, | ||
custom_connection_string: None, | ||
}, | ||
IndexerModel { | ||
id: uuid::Uuid::new_v4(), | ||
status: IndexerStatus::FailedRunning, | ||
indexer_type: IndexerType::Webhook, | ||
process_id: None, | ||
target_url: Some("https://example.com".to_string()), | ||
table_name: None, | ||
status_server_port: None, | ||
custom_connection_string: None, | ||
}, | ||
IndexerModel { | ||
id: uuid::Uuid::new_v4(), | ||
status: IndexerStatus::Stopped, | ||
indexer_type: IndexerType::Webhook, | ||
process_id: None, | ||
target_url: Some("https://example.com".to_string()), | ||
table_name: None, | ||
status_server_port: None, | ||
custom_connection_string: None, | ||
}, | ||
IndexerModel { | ||
id: uuid::Uuid::new_v4(), | ||
status: IndexerStatus::FailedStopping, | ||
indexer_type: IndexerType::Webhook, | ||
process_id: Some(123), | ||
target_url: Some("https://example.com".to_string()), | ||
table_name: None, | ||
status_server_port: None, | ||
custom_connection_string: None, | ||
}, | ||
], | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Repository for MockRepository { | ||
async fn insert(&mut self, new_indexer: NewIndexerDb) -> Result<IndexerModel, InfraError> { | ||
let indexer: IndexerModel = new_indexer.try_into().map_err(InfraError::ParseError)?; | ||
// Insert the indexer in the mock database | ||
self.indexers.push(indexer.clone()); | ||
Ok(indexer) | ||
} | ||
async fn delete(&mut self, id: Uuid) -> Result<(), InfraError> { | ||
// Delete the indexer from the mock database | ||
self.indexers.retain(|indexer| indexer.id != id); | ||
Ok(()) | ||
} | ||
async fn get(&self, id: Uuid) -> Result<IndexerModel, InfraError> { | ||
let indexer = self.indexers.iter().find(|indexer| indexer.id == id); | ||
if let Some(indexer) = indexer { Ok(indexer.clone()) } else { Err(InfraError::NotFound) } | ||
} | ||
async fn get_by_table_name(&self, table_name: String) -> Result<IndexerModel, InfraError> { | ||
let indexer = self.indexers.iter().find(|indexer| indexer.table_name == Some(table_name.clone())); | ||
if let Some(indexer) = indexer { Ok(indexer.clone()) } else { Err(InfraError::NotFound) } | ||
} | ||
async fn get_all(&self, filter: IndexerFilter) -> Result<Vec<IndexerModel>, InfraError> { | ||
// Get all indexers with status filter if provided | ||
let indexers = match filter.status { | ||
Some(status) => self | ||
.indexers | ||
.iter() | ||
.filter(|indexer| indexer.status == IndexerStatus::from_str(&status).unwrap()) | ||
.cloned() | ||
.collect(), | ||
None => self.indexers.clone(), | ||
}; | ||
Ok(indexers) | ||
} | ||
async fn update_status(&mut self, indexer: UpdateIndexerStatusDb) -> Result<IndexerModel, InfraError> { | ||
// Update the indexer in the mock database | ||
let i = self.indexers.iter_mut().find(|other| indexer.id.eq(&other.id)).unwrap(); | ||
i.status = IndexerStatus::from_str(&indexer.status).map_err(InfraError::ParseError)?; | ||
Ok(i.clone()) | ||
} | ||
async fn update_status_and_process_id( | ||
&mut self, | ||
indexer: UpdateIndexerStatusAndProcessIdDb, | ||
) -> Result<IndexerModel, InfraError> { | ||
// Update the indexer in the self.indexers vector | ||
let i = self.indexers.iter_mut().find(|other| indexer.id.eq(&other.id)).unwrap(); | ||
i.status = IndexerStatus::from_str(&indexer.status).map_err(InfraError::ParseError)?; | ||
i.process_id = Some(indexer.process_id); | ||
Ok(i.clone()) | ||
} | ||
} |
Oops, something went wrong.