Skip to content

Commit

Permalink
restructured init
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMimir committed Oct 1, 2023
1 parent ef40e98 commit e221dc5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 34 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ sea generate entity --lib -o libs/store/src
* Create api for coingecko
* fetch all assets
* fetch all assets info
* Create cron to add repository data.
* Create table to hold issue data.
* Create cron to scan over repositores for issues.
* Create cron to check if issue has been closed.
Expand Down
2 changes: 1 addition & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ path = "src/main.rs"
name = "api"

[[bin]]
path = "src/jobs/info/main.rs"
path = "src/init.rs"
name = "init"
42 changes: 42 additions & 0 deletions api/src/init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::sync::Arc;

use api::jobs::{github_repositories::GithubRepositoriesCron, info::Info};
use config::dotenv_init;
use sdks::{coingecko::CoinGecko, github::Github};
use sea_orm::{Database, DatabaseConnection};

#[tokio::main]
async fn main() {
env_logger::builder()
.filter_level(log::LevelFilter::Warn)
.init();

dotenv_init();
let db_url = config::get("DATABASE_URL").unwrap();
let pool = Database::connect(db_url).await.unwrap();
let sea_pool = Arc::new(pool);

info_init(sea_pool.clone()).await;
repo_init(sea_pool).await;
}

async fn info_init(sea_pool: Arc<DatabaseConnection>) {
let repository = api::jobs::info::infrastructure::PgRepository::new(sea_pool.clone());
let service = api::jobs::info::infrastructure::PgService::new(sea_pool);
let coingecko = CoinGecko::default();

let init = Info::new(repository, service, coingecko);

init.preform_init().await.unwrap();
}

async fn repo_init(sea_pool: Arc<DatabaseConnection>) {
let repository =
api::jobs::github_repositories::infrastructure::PgRepository::new(sea_pool.clone());
let service = api::jobs::github_repositories::infrastructure::PgService::new(sea_pool);
let github = Github::default();

let init = GithubRepositoriesCron::new(repository, service, github);

init.cron_job().await.unwrap();
}
2 changes: 1 addition & 1 deletion api/src/jobs/github_repositories/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<
///
/// Cron job that runs once a week
///
async fn cron_job(&self) -> Result<()> {
pub async fn cron_job(&self) -> Result<()> {
let projects = self.repository.get_projects().await?;

for project in projects {
Expand Down
4 changes: 2 additions & 2 deletions api/src/jobs/github_repositories/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod contract;
mod domain;
mod infrastructure;
pub mod infrastructure;

use domain::GithubRepositoriesCron;
pub use domain::GithubRepositoriesCron;
use infrastructure::{PgRepository, PgService};
use sdks::github::Github;
use sea_orm::DatabaseConnection;
Expand Down
29 changes: 0 additions & 29 deletions api/src/jobs/info/main.rs

This file was deleted.

0 comments on commit e221dc5

Please sign in to comment.