cyrtophora

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit ac14a2a9e65ccac0030aa667826ddc11f69f29a3
parent 050349634ee1917642db92aa0f3056ed51bd81de
Author: Jackson G. Kaindume <seestem@merely.tech>
Date:   Mon, 29 Aug 2022 13:00:01 +0200

[phora] add account public data

Diffstat:
Mphora/src/account.rs | 26++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/phora/src/account.rs b/phora/src/account.rs @@ -1,7 +1,9 @@ -use crate::data::AccountRegistrationData; +use crate::data::AccountRegistration; use crate::validate::ValidationError; +use serde::{Deserialize, Serialize}; /// An account +#[derive(Deserialize, Serialize)] pub struct Account { /// The username of the user, also used as an unique identifier pub username: String, @@ -13,16 +15,32 @@ pub struct Account { impl Account { /// Create new account - pub fn create(payload: AccountRegistrationData) -> Result<Self, ValidationError> { + pub fn create(payload: AccountRegistration) -> Result<PublicAccount, ValidationError> { payload.is_valid()?; // TODO: email verification // TODO: database registration - Ok(Account { + let account = Account { username: payload.username, email: payload.email, password: payload.password, - }) + }; + + Ok(account.into()) + } +} + +/// Account Public Data +pub struct PublicAccount { + /// The username of the user, also used as an unique identifier + pub username: String, +} + +impl From<Account> for PublicAccount { + fn from(account: Account) -> Self { + PublicAccount { + username: account.username, + } } }