Skip to content

Commit

Permalink
feat: add profile history
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanosdev committed Jan 13, 2024
1 parent 4fb3d97 commit 9a38003
Show file tree
Hide file tree
Showing 33 changed files with 1,115 additions and 130 deletions.
28 changes: 10 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ uuid = "1.6"

mockall = "0.12"
rstest = "0.18"
rstest_reuse = "0.6"
async-std = { version = "1.5", features = ["attributes"] }
25 changes: 25 additions & 0 deletions src/backend/api/backend.did
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ type Err = record {
message : text;
};

type HistoryAction = variant {
create;
update;
delete;
restore;
};

type UserConfig = variant {
admin : record {
bio : text;
Expand All @@ -24,6 +31,23 @@ type GetMyUserProfileResponse = variant {
err : Err;
};

type UserProfileHistoryEntry = record {
username : text;
config : UserConfig;
};

type GetMyUserProfileHistoryResponse = variant {
ok : record {
history : vec record {
action : HistoryAction;
date_time : text;
user : principal;
data : UserProfileHistoryEntry;
};
};
err : Err;
};

type CreateMyUserProfileResponse = variant {
ok : record {
id : text;
Expand All @@ -35,5 +59,6 @@ type CreateMyUserProfileResponse = variant {

service : {
get_my_user_profile : () -> (GetMyUserProfileResponse) query;
get_my_user_profile_history : () -> (GetMyUserProfileHistoryResponse) query;
create_my_user_profile : () -> (CreateMyUserProfileResponse);
};
21 changes: 21 additions & 0 deletions src/backend/api/src/history.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use candid::{CandidType, Deserialize, Principal};

#[derive(Debug, Clone, CandidType, Deserialize, PartialEq, Eq)]
pub enum HistoryAction {
#[serde(rename = "create")]
Create,
#[serde(rename = "update")]
Update,
#[serde(rename = "delete")]
Delete,
#[serde(rename = "restore")]
Restore,
}

#[derive(Debug, Clone, CandidType, Deserialize, PartialEq, Eq)]
pub struct HistoryEntry<T> {
pub action: HistoryAction,
pub date_time: String,
pub user: Principal,
pub data: T,
}
2 changes: 2 additions & 0 deletions src/backend/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod history;
mod result;
mod user_profile;

pub use history::*;
pub use result::*;
pub use user_profile::*;
12 changes: 12 additions & 0 deletions src/backend/api/src/user_profile.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::HistoryEntry;
use candid::{CandidType, Deserialize};

#[derive(Debug, Clone, CandidType, Deserialize, PartialEq, Eq)]
Expand Down Expand Up @@ -29,3 +30,14 @@ pub struct CreateMyUserProfileResponse {
pub username: String,
pub config: UserConfig,
}

#[derive(Debug, Clone, CandidType, PartialEq, Eq)]
pub struct UserProfileHistoryEntry {
pub username: String,
pub config: UserConfig,
}

#[derive(Debug, Clone, CandidType, PartialEq, Eq)]
pub struct GetMyUserProfileHistoryResponse {
pub history: Vec<HistoryEntry<UserProfileHistoryEntry>>,
}
3 changes: 2 additions & 1 deletion src/backend/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ candid_parser.workspace = true
serde.workspace = true

uuid = { workspace = true, features = ["serde"] }
chrono = { version = "0.4", default-features = false, features = ["std"] }

rand = { version = "0.8", default-features = false }
rand_chacha = { version = "0.3", default-features = false }

[dev-dependencies]
mockall.workspace = true
rstest.workspace = true
rstest_reuse.workspace = true
async-std.workspace = true
Loading

0 comments on commit 9a38003

Please sign in to comment.