-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update contact takes an update parameter
- models::UpdateContact is a parameter for update_contact - next we make sure the database actually get updated...
- Loading branch information
1 parent
74b194b
commit 9688b61
Showing
2 changed files
with
18 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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(()) | ||
} | ||
} | ||
|
@@ -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()); | ||
} | ||
|
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 |
---|---|---|
|
@@ -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(()) | ||
} | ||
|
||
|