From 18097c14f0f08ea85696d36f9a0565b3e4971d84 Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Fri, 26 Nov 2021 10:23:51 -0800 Subject: [PATCH] Refactor contact update models --- epp-client/src/contact.rs | 1 + .../src/{epp/request => }/contact/update.rs | 109 ++++++++++-------- epp-client/src/epp.rs | 2 - epp-client/src/epp/request.rs | 1 - epp-client/src/epp/request/contact.rs | 3 - epp-client/src/epp/response.rs | 1 - epp-client/src/epp/response/contact.rs | 3 - epp-client/src/epp/response/contact/update.rs | 6 - epp-client/src/tests/de.rs | 1 + epp-client/src/tests/se.rs | 1 + 10 files changed, 61 insertions(+), 67 deletions(-) rename epp-client/src/{epp/request => }/contact/update.rs (90%) delete mode 100644 epp-client/src/epp/request/contact.rs delete mode 100644 epp-client/src/epp/response/contact.rs delete mode 100644 epp-client/src/epp/response/contact/update.rs diff --git a/epp-client/src/contact.rs b/epp-client/src/contact.rs index 770e8c7..035f812 100644 --- a/epp-client/src/contact.rs +++ b/epp-client/src/contact.rs @@ -2,3 +2,4 @@ pub mod check; pub mod create; pub mod delete; pub mod info; +pub mod update; diff --git a/epp-client/src/epp/request/contact/update.rs b/epp-client/src/contact/update.rs similarity index 90% rename from epp-client/src/epp/request/contact/update.rs rename to epp-client/src/contact/update.rs index 8d5ded8..0f4cbd6 100644 --- a/epp-client/src/epp/request/contact/update.rs +++ b/epp-client/src/contact/update.rs @@ -6,6 +6,7 @@ use crate::contact::info::EppContactInfoResponse; use crate::epp::object::data::{ContactAuthInfo, ContactStatus, Phone, PostalInfo}; use crate::epp::object::{ElementName, EppObject, StringValue}; use crate::epp::request::Command; +use crate::epp::response::EppCommandResponse; use crate::epp::xml::EPP_CONTACT_XMLNS; use crate::error; use serde::{Deserialize, Serialize}; @@ -19,7 +20,7 @@ use serde::{Deserialize, Serialize}; /// /// use epp_client::config::{EppClientConfig, EppClientConnection}; /// use epp_client::EppClient; -/// use epp_client::epp::{EppContactUpdate, EppContactUpdateResponse}; +/// use epp_client::contact::update::{EppContactUpdate, EppContactUpdateResponse}; /// use epp_client::epp::generate_client_tr_id; /// use epp_client::epp::object::data::ContactStatus; /// @@ -68,59 +69,13 @@ use serde::{Deserialize, Serialize}; /// client.logout().await.unwrap(); /// } /// ``` -pub type EppContactUpdate = EppObject>; - -/// Type for elements under the <chg> tag for contact update request -#[derive(Serialize, Deserialize, Debug)] -pub struct ContactChangeInfo { - #[serde(rename = "contact:postalInfo", alias = "postalInfo")] - postal_info: Option, - #[serde(rename = "contact:voice", alias = "voice")] - voice: Option, - #[serde(rename = "contact:fax", alias = "fax")] - fax: Option, - #[serde(rename = "contact:email", alias = "email")] - email: Option, - #[serde(rename = "contact:authInfo", alias = "authInfo")] - auth_info: Option, -} - -/// Type for list of elements of the <status> tag for contact update request -#[derive(Serialize, Deserialize, Debug)] -pub struct StatusList { - #[serde(rename = "contact:status", alias = "status")] - status: Vec, -} - -/// Type for elements under the contact <update> tag -#[derive(Serialize, Deserialize, Debug)] -pub struct ContactUpdateData { - #[serde(rename = "xmlns:contact", alias = "xmlns")] - xmlns: String, - #[serde(rename = "contact:id", alias = "id")] - id: StringValue, - #[serde(rename = "contact:add", alias = "add")] - add_statuses: Option, - #[serde(rename = "contact:rem", alias = "rem")] - remove_statuses: Option, - #[serde(rename = "contact:chg", alias = "chg")] - change_info: Option, -} - -#[derive(Serialize, Deserialize, Debug, ElementName)] -#[element_name(name = "update")] -/// Type for EPP XML <update> command for contacts -pub struct ContactUpdate { - /// The data under the <update> tag for the contact update - #[serde(rename = "contact:update", alias = "update")] - contact: ContactUpdateData, -} +pub type EppContactUpdate = EppObject>; impl EppContactUpdate { /// Creates a new EppObject for contact update corresponding to the <epp> tag in EPP XML pub fn new(id: &str, client_tr_id: &str) -> EppContactUpdate { - let contact_update = ContactUpdate { - contact: ContactUpdateData { + let contact_update = ContactUpdateRequest { + contact: ContactUpdateRequestData { xmlns: EPP_CONTACT_XMLNS.to_string(), id: id.into(), add_statuses: None, @@ -128,7 +83,10 @@ impl EppContactUpdate { change_info: None, }, }; - EppObject::build(Command::::new(contact_update, client_tr_id)) + EppObject::build(Command::::new( + contact_update, + client_tr_id, + )) } /// Sets the data for the <chg> tag for the contact update request @@ -187,3 +145,52 @@ impl EppContactUpdate { } } } + +/// Type that represents the <epp> tag for the EPP XML contact update response +pub type EppContactUpdateResponse = EppCommandResponse; + +/// Type for elements under the <chg> tag for contact update request +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactChangeInfo { + #[serde(rename = "contact:postalInfo", alias = "postalInfo")] + postal_info: Option, + #[serde(rename = "contact:voice", alias = "voice")] + voice: Option, + #[serde(rename = "contact:fax", alias = "fax")] + fax: Option, + #[serde(rename = "contact:email", alias = "email")] + email: Option, + #[serde(rename = "contact:authInfo", alias = "authInfo")] + auth_info: Option, +} + +/// Type for list of elements of the <status> tag for contact update request +#[derive(Serialize, Deserialize, Debug)] +pub struct StatusList { + #[serde(rename = "contact:status", alias = "status")] + status: Vec, +} + +/// Type for elements under the contact <update> tag +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactUpdateRequestData { + #[serde(rename = "xmlns:contact", alias = "xmlns")] + xmlns: String, + #[serde(rename = "contact:id", alias = "id")] + id: StringValue, + #[serde(rename = "contact:add", alias = "add")] + add_statuses: Option, + #[serde(rename = "contact:rem", alias = "rem")] + remove_statuses: Option, + #[serde(rename = "contact:chg", alias = "chg")] + change_info: Option, +} + +#[derive(Serialize, Deserialize, Debug, ElementName)] +#[element_name(name = "update")] +/// Type for EPP XML <update> command for contacts +pub struct ContactUpdateRequest { + /// The data under the <update> tag for the contact update + #[serde(rename = "contact:update", alias = "update")] + contact: ContactUpdateRequestData, +} diff --git a/epp-client/src/epp.rs b/epp-client/src/epp.rs index 5625e9d..cd6f265 100644 --- a/epp-client/src/epp.rs +++ b/epp-client/src/epp.rs @@ -5,7 +5,6 @@ pub mod request; pub mod response; pub mod xml; -pub use request::contact::update::*; pub use request::host::check::*; pub use request::host::create::*; pub use request::host::delete::*; @@ -14,7 +13,6 @@ pub use request::host::update::*; pub use request::message::ack::*; pub use request::message::poll::*; -pub use response::contact::update::*; pub use response::host::check::*; pub use response::host::create::*; pub use response::host::delete::*; diff --git a/epp-client/src/epp/request.rs b/epp-client/src/epp/request.rs index e5c4f9c..ef442b7 100644 --- a/epp-client/src/epp/request.rs +++ b/epp-client/src/epp/request.rs @@ -1,6 +1,5 @@ //! Types for EPP requests -pub mod contact; pub mod host; pub mod message; diff --git a/epp-client/src/epp/request/contact.rs b/epp-client/src/epp/request/contact.rs deleted file mode 100644 index d36a0f9..0000000 --- a/epp-client/src/epp/request/contact.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Types for EPP contact requests - -pub mod update; diff --git a/epp-client/src/epp/response.rs b/epp-client/src/epp/response.rs index 0d06a0b..8796b21 100644 --- a/epp-client/src/epp/response.rs +++ b/epp-client/src/epp/response.rs @@ -1,6 +1,5 @@ //! Types for EPP responses -pub mod contact; pub mod host; pub mod message; diff --git a/epp-client/src/epp/response/contact.rs b/epp-client/src/epp/response/contact.rs deleted file mode 100644 index 50c9a4a..0000000 --- a/epp-client/src/epp/response/contact.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Types for EPP contact responses - -pub mod update; diff --git a/epp-client/src/epp/response/contact/update.rs b/epp-client/src/epp/response/contact/update.rs deleted file mode 100644 index a85c812..0000000 --- a/epp-client/src/epp/response/contact/update.rs +++ /dev/null @@ -1,6 +0,0 @@ -//! Types for EPP contact update response - -use crate::epp::response::EppCommandResponse; - -/// Type that represents the <epp> tag for the EPP XML contact update response -pub type EppContactUpdateResponse = EppCommandResponse; diff --git a/epp-client/src/tests/de.rs b/epp-client/src/tests/de.rs index 127dd84..4794a78 100644 --- a/epp-client/src/tests/de.rs +++ b/epp-client/src/tests/de.rs @@ -7,6 +7,7 @@ mod response { use crate::contact::create::EppContactCreateResponse; use crate::contact::delete::EppContactDeleteResponse; use crate::contact::info::EppContactInfoResponse; + use crate::contact::update::EppContactUpdateResponse; use crate::domain::check::EppDomainCheckResponse; use crate::domain::create::EppDomainCreateResponse; use crate::domain::delete::EppDomainDeleteResponse; diff --git a/epp-client/src/tests/se.rs b/epp-client/src/tests/se.rs index dce52e8..f66a803 100644 --- a/epp-client/src/tests/se.rs +++ b/epp-client/src/tests/se.rs @@ -7,6 +7,7 @@ mod request { use crate::contact::create::EppContactCreate; use crate::contact::delete::EppContactDelete; use crate::contact::info::EppContactInfo; + use crate::contact::update::EppContactUpdate; use crate::domain::check::EppDomainCheck; use crate::domain::create::EppDomainCreate; use crate::domain::delete::EppDomainDelete;