Skip to content

Commit

Permalink
refactor: Simplify models and improve code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rgwood committed Dec 15, 2024
1 parent 6fb0f8c commit 83e14eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
10 changes: 4 additions & 6 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Database {

pub fn upsert_projects(&mut self, projects: &[Project]) -> Result<()> {
let transaction = self.conn.transaction()?;

for project in projects {
let json = serde_json::to_string(project)?;
transaction.execute(
Expand Down Expand Up @@ -159,11 +159,9 @@ impl Database {
}

pub fn is_empty(&self) -> Result<bool> {
let count: i64 = self.conn.query_row(
"SELECT COUNT(*) FROM Projects",
[],
|row| row.get(0),
)?;
let count: i64 = self
.conn
.query_row("SELECT COUNT(*) FROM Projects", [], |row| row.get(0))?;
Ok(count == 0)
}

Expand Down
13 changes: 10 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ fn main() -> Result<()> {
// Check if this is first run
let is_initialization = db.is_empty()?;
if is_initialization {
println!("{}", "First run detected - initializing database...".bold().yellow());
println!(
"{}",
"First run detected - initializing database..."
.bold()
.yellow()
);
}

// Compare against database
Expand Down Expand Up @@ -130,7 +135,6 @@ fn main() -> Result<()> {
} else {
new_projects.push(project.clone());
}

}

compare_spinner.finish_with_message(format!(
Expand Down Expand Up @@ -160,7 +164,10 @@ fn main() -> Result<()> {
if !new_projects.is_empty() && !is_initialization {
post_to_slack(&webhook_url, &new_projects)?;
} else if is_initialization {
println!("{}", "Skipping Slack notification during initialization".yellow());
println!(
"{}",
"Skipping Slack notification during initialization".yellow()
);
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/models.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub enum QueueMessage {
SlackMessage {
json: String,
},
pub struct SlackMessage {
json: String,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down

0 comments on commit 83e14eb

Please sign in to comment.