Refactor host create models

This commit is contained in:
Nicholas Rempel 2021-11-26 10:30:07 -08:00 committed by masalachai
parent fa032804a6
commit 63c5aae4a9
8 changed files with 49 additions and 51 deletions

View File

@ -5,14 +5,12 @@ pub mod request;
pub mod response;
pub mod xml;
pub use request::host::create::*;
pub use request::host::delete::*;
pub use request::host::info::*;
pub use request::host::update::*;
pub use request::message::ack::*;
pub use request::message::poll::*;
pub use response::host::create::*;
pub use response::host::delete::*;
pub use response::host::info::*;
pub use response::host::update::*;

View File

@ -1,6 +1,5 @@
//! Types for EPP host requests
pub mod create;
pub mod delete;
pub mod info;
pub mod update;

View File

@ -1,6 +1,5 @@
//! Types for EPP host responses
pub mod create;
pub mod delete;
pub mod info;
pub mod update;

View File

@ -1,30 +0,0 @@
//! Types for EPP host create response
use serde::{Deserialize, Serialize};
use crate::epp::object::{EppObject, StringValue};
use crate::epp::response::CommandResponse;
/// Type that represents the <epp> tag for the EPP XML host create response
pub type EppHostCreateResponse = EppObject<CommandResponse<HostCreateResult>>;
/// Type that represents the &lt;creData&gt; tag for host create response
#[derive(Serialize, Deserialize, Debug)]
pub struct HostCreateData {
/// XML namespace for host response data
#[serde(rename = "xmlns:host")]
xmlns: String,
/// The host name
pub name: StringValue,
/// The host creation date
#[serde(rename = "crDate")]
pub created_at: StringValue,
}
/// Type that represents the &lt;resData&gt; tag for host check response
#[derive(Serialize, Deserialize, Debug)]
pub struct HostCreateResult {
/// Data under the &lt;creData&gt; tag
#[serde(rename = "creData")]
pub create_data: HostCreateData,
}

View File

@ -1 +1,2 @@
pub mod check;
pub mod create;

View File

@ -5,6 +5,7 @@ use epp_client_macros::*;
use crate::epp::object::data::HostAddr;
use crate::epp::object::{ElementName, EppObject, StringValue};
use crate::epp::request::Command;
use crate::epp::response::CommandResponse;
use crate::epp::xml::EPP_HOST_XMLNS;
use serde::{Deserialize, Serialize};
@ -18,7 +19,7 @@ use serde::{Deserialize, Serialize};
/// use epp_client::config::{EppClientConfig, EppClientConnection};
/// use epp_client::EppClient;
/// use epp_client::epp::object::data::HostAddr;
/// use epp_client::epp::{EppHostCreate, EppHostCreateResponse};
/// use epp_client::host::create::{EppHostCreate, EppHostCreateResponse};
/// use epp_client::epp::generate_client_tr_id;
///
/// #[tokio::main]
@ -61,11 +62,31 @@ use serde::{Deserialize, Serialize};
/// client.logout().await.unwrap();
/// }
/// ```
pub type EppHostCreate = EppObject<Command<HostCreate>>;
pub type EppHostCreate = EppObject<Command<HostCreateRequest>>;
impl EppHostCreate {
/// Creates a new EppObject for host create corresponding to the &lt;epp&gt; tag in EPP XML
pub fn new(host: &str, addresses: Vec<HostAddr>, client_tr_id: &str) -> EppHostCreate {
let host_create = HostCreateRequest {
host: HostCreateRequestData {
xmlns: EPP_HOST_XMLNS.to_string(),
name: host.into(),
addresses: Some(addresses),
},
};
EppObject::build(Command::<HostCreateRequest>::new(host_create, client_tr_id))
}
}
/// Type that represents the &lt;epp&gt; tag for the EPP XML host create response
pub type EppHostCreateResponse = EppObject<CommandResponse<HostCreateResponse>>;
// Request
/// Type for data under the host &lt;create&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct HostCreateData {
pub struct HostCreateRequestData {
/// XML namespace for host commands
#[serde(rename = "xmlns:host", alias = "xmlns")]
xmlns: String,
@ -80,23 +101,31 @@ pub struct HostCreateData {
#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "create")]
/// Type for EPP XML &lt;create&gt; command for hosts
pub struct HostCreate {
pub struct HostCreateRequest {
/// The instance holding the data for the host to be created
#[serde(rename = "host:create", alias = "create")]
host: HostCreateData,
host: HostCreateRequestData,
}
impl EppHostCreate {
/// Creates a new EppObject for host create corresponding to the &lt;epp&gt; tag in EPP XML
pub fn new(host: &str, addresses: Vec<HostAddr>, client_tr_id: &str) -> EppHostCreate {
let host_create = HostCreate {
host: HostCreateData {
xmlns: EPP_HOST_XMLNS.to_string(),
name: host.into(),
addresses: Some(addresses),
},
};
// Response
EppObject::build(Command::<HostCreate>::new(host_create, client_tr_id))
}
/// Type that represents the &lt;creData&gt; tag for host create response
#[derive(Serialize, Deserialize, Debug)]
pub struct HostCreateData {
/// XML namespace for host response data
#[serde(rename = "xmlns:host")]
xmlns: String,
/// The host name
pub name: StringValue,
/// The host creation date
#[serde(rename = "crDate")]
pub created_at: StringValue,
}
/// Type that represents the &lt;resData&gt; tag for host check response
#[derive(Serialize, Deserialize, Debug)]
pub struct HostCreateResponse {
/// Data under the &lt;creData&gt; tag
#[serde(rename = "creData")]
pub create_data: HostCreateData,
}

View File

@ -28,6 +28,7 @@ mod response {
use crate::epp::xml::EppXml;
use crate::epp::*;
use crate::host::check::EppHostCheckResponse;
use crate::host::create::EppHostCreateResponse;
const SVTRID: &str = "RO-6879-1627224678242975";
const SUCCESS_MSG: &str = "Command completed successfully";

View File

@ -31,6 +31,7 @@ mod request {
use crate::epp::xml::EppXml;
use crate::epp::*;
use crate::host::check::EppHostCheck;
use crate::host::create::EppHostCreate;
use chrono::{DateTime, NaiveDate};
use std::str::FromStr;