diff --git a/server/Cargo.toml b/server/Cargo.toml
index 015821f2..a9eb42e1 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -38,6 +38,7 @@ path = "src/lib.rs"
openapi = { path = "../github-mirror" }
anyhow = "1.0.86"
serde = { version = "1.0.203", features = ["derive"] }
+serde-xml-rs = "0.6.0"
serde_json = "1.0.117"
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros", "fs"] }
axum = "0.7.5"
diff --git a/server/src/objects/user.rs b/server/src/objects/user.rs
index 2155498f..e7732ce6 100644
--- a/server/src/objects/user.rs
+++ b/server/src/objects/user.rs
@@ -20,10 +20,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
use anyhow::Result;
-use log::info;
-use serde::Deserialize;
+use log::{debug, info};
+use serde::{Deserialize, Serialize};
+use serde_xml_rs::to_string;
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Serialize, Deserialize)]
pub struct User {
pub(crate) username: String,
}
@@ -34,9 +35,38 @@ impl User {
}
}
+// @todo #17:40min Apply XMLed user to the node in storage.
+// We should apply XMLed user to the XML node in storage. First we
+// need to check that user with provided name does not exist, and only then
+// apply it to the storage. Keep in mind that application function in the
+// storage should be thread-safe (as well as #xml function). Don't forget to
+// create unit tests that prove that.
impl User {
pub async fn save(self) -> Result<()> {
info!("registering user @{}", self.username);
+ let xml = to_string(&self).unwrap();
+ debug!("XMLed user: {}", xml);
+ Ok(())
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use anyhow::Result;
+ use crate::objects::user::User;
+
+ #[test]
+ fn returns_username() -> Result<()> {
+ let expected = "jeff";
+ let jeff = User::new(String::from(expected));
+ assert_eq!(
+ jeff.username,
+ expected,
+ "Username {} from user: {:?} does not match with expected {}",
+ jeff.username,
+ jeff,
+ expected
+ );
Ok(())
}
}