Skip to content

Commit

Permalink
feat: update contact takes an update parameter
Browse files Browse the repository at this point in the history
- models::UpdateContact is a parameter for update_contact
- next we make sure the database actually get updated...
  • Loading branch information
jasonribble committed Jul 10, 2024
1 parent 74b194b commit 9688b61
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sqlx::postgres::PgPool;
pub trait ContactRepo {
async fn save_contact(&self, contact: models::Contact) -> anyhow::Result<i64>;
async fn get_all(&self) -> anyhow::Result<Vec<models::IndexedContact>>;
async fn update_contact(&self) -> anyhow::Result<()>;
async fn update_contact(&self, update: models::UpdateContact) -> anyhow::Result<()>;
}

pub struct PostgresContactRepo {
Expand Down Expand Up @@ -58,7 +58,8 @@ impl ContactRepo for PostgresContactRepo {
Ok(contacts_with_id)
}

async fn update_contact(&self) -> anyhow::Result<()> {
async fn update_contact(&self, update: models::UpdateContact) -> anyhow::Result<()> {
println!("{update:?}");
Ok(())
}
}
Expand Down Expand Up @@ -112,12 +113,15 @@ mod tests {
async fn test_update_contact() {
let mut mock_contact_repo = MockContactRepo::new();

let edits = models::UpdateContact::new(1).email("[email protected]");

mock_contact_repo
.expect_update_contact()
.times(1)
.return_once(move || Ok(()));
.with(eq(edits.clone()))
.return_once(|_| Ok(()));

let result = mock_contact_repo.update_contact().await;
let result = mock_contact_repo.update_contact(edits).await;

assert!(result.is_ok());
}
Expand Down
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ async fn main() -> anyhow::Result<()> {

println!("{most_recent_contact:?}");

let edits = models::UpdateContact::new(id)
.first_name("New Name")
.last_name("Yep")
.email("[email protected]")
.phone_number("1233211233")
.display_name("Nickname")
.build();

let _ = contact_repo.update_contact(edits).await;

Ok(())
}

Expand Down

0 comments on commit 9688b61

Please sign in to comment.