diff --git a/src/api/schemas.rs b/src/api/schemas.rs index 1fdc9ab..b188e2c 100644 --- a/src/api/schemas.rs +++ b/src/api/schemas.rs @@ -32,12 +32,28 @@ pub mod schemas { } } + /** + A struct that represents a well-formed username. + ## Arguments + Please use new() to create a new instance of this struct. + ## Errors + You will receive a [`FieldFormatError`], if: + - The username is not between 2 and 32 characters. + */ #[derive(Clone)] pub struct AuthUsername { pub username: String, } impl AuthUsername { + /** + Returns a new [`Result`]. + ## Arguments + The username you want to validate. + ## Errors + You will receive a [`FieldFormatError`], if: + - The username is not between 2 and 32 characters. + */ pub fn new(username: String) -> Result { if username.len() < 2 || username.len() > 32 { return Err(FieldFormatError::UsernameError); @@ -47,12 +63,28 @@ pub mod schemas { } } + /** + A struct that represents a well-formed password. + ## Arguments + Please use new() to create a new instance of this struct. + ## Errors + You will receive a [`FieldFormatError`], if: + - The password is not between 1 and 72 characters. + */ #[derive(Clone)] pub struct AuthPassword { pub password: String, } impl AuthPassword { + /** + Returns a new [`Result`]. + ## Arguments + The password you want to validate. + ## Errors + You will receive a [`FieldFormatError`], if: + - The password is not between 1 and 72 characters. + */ pub fn new(password: String) -> Result { if password.len() < 1 || password.len() > 72 { return Err(FieldFormatError::PasswordError); @@ -62,6 +94,16 @@ pub mod schemas { } } + /** + A struct that represents a well-formed register request. + ## Arguments + Please use new() to create a new instance of this struct. + ## Errors + You will receive a [`FieldFormatError`], if: + - The username is not between 2 and 32 characters. + - The password is not between 1 and 72 characters. + */ + #[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub struct RegisterSchema { @@ -137,6 +179,15 @@ pub mod schemas { } } + /** + A struct that represents a well-formed login request. + ## Arguments + Please use new() to create a new instance of this struct. + ## Errors + You will receive a [`FieldFormatError`], if: + - The username is not between 2 and 32 characters. + - The password is not between 1 and 72 characters. + */ #[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub struct LoginSchema { @@ -148,6 +199,40 @@ pub mod schemas { gift_code_sku_id: Option, } + impl LoginSchema { + /** + Returns a new [`Result`]. + ## Arguments + login: The username you want to login with. + password: The password you want to login with. + undelete: Honestly no idea what this is for. + captcha_key: The captcha key you want to login with. + login_source: The login source. + gift_code_sku_id: The gift code sku id. + ## Errors + You will receive a [`FieldFormatError`], if: + - The username is less than 2 or more than 32 characters in length + */ + pub fn new( + login: AuthUsername, + password: String, + undelete: Option, + captcha_key: Option, + login_source: Option, + gift_code_sku_id: Option, + ) -> Result { + let login = login.username; + return Ok(LoginSchema { + login, + password, + undelete, + captcha_key, + login_source, + gift_code_sku_id, + }); + } + } + #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub struct TotpSchema { @@ -157,6 +242,9 @@ pub mod schemas { login_source: Option, } + /** + Represents the result you get from GET: /api/instance/policies/. + */ #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct InstancePoliciesSchema {