mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-22 22:08:59 +00:00
refactor: less cloning
This commit is contained in:
parent
b74211aa96
commit
c9cc3607bd
4 changed files with 20 additions and 20 deletions
|
|
@ -13,7 +13,7 @@ impl Query {
|
|||
|
||||
let public_keys = admins
|
||||
.iter()
|
||||
.map(|admin| admin.public_key.clone())
|
||||
.map(|admin| admin.public_key.to_owned())
|
||||
.collect();
|
||||
|
||||
Ok(public_keys)
|
||||
|
|
|
|||
|
|
@ -130,18 +130,18 @@ impl EncryptedCandidateDetails {
|
|||
)
|
||||
}
|
||||
|
||||
pub async fn decrypt(self, priv_key: String) -> Result<CandidateDetails, ServiceError> {
|
||||
pub async fn decrypt(self, priv_key: &String) -> Result<CandidateDetails, ServiceError> {
|
||||
let d = tokio::try_join!(
|
||||
self.name.decrypt(&priv_key), // 0
|
||||
self.surname.decrypt(&priv_key), // 1
|
||||
self.birthplace.decrypt(&priv_key), // 2
|
||||
self.birthdate.decrypt(&priv_key), // 3
|
||||
self.address.decrypt(&priv_key), // 4
|
||||
self.telephone.decrypt(&priv_key), // 5
|
||||
self.citizenship.decrypt(&priv_key), // 6
|
||||
self.email.decrypt(&priv_key), // 7
|
||||
self.sex.decrypt(&priv_key), // 8
|
||||
self.personal_id_number.decrypt(&priv_key),// 9
|
||||
self.name.decrypt(priv_key), // 0
|
||||
self.surname.decrypt(priv_key), // 1
|
||||
self.birthplace.decrypt(priv_key), // 2
|
||||
self.birthdate.decrypt(priv_key), // 3
|
||||
self.address.decrypt(priv_key), // 4
|
||||
self.telephone.decrypt(priv_key), // 5
|
||||
self.citizenship.decrypt(priv_key), // 6
|
||||
self.email.decrypt(priv_key), // 7
|
||||
self.sex.decrypt(priv_key), // 8
|
||||
self.personal_id_number.decrypt(priv_key),// 9
|
||||
)?;
|
||||
|
||||
Ok(CandidateDetails {
|
||||
|
|
@ -206,7 +206,7 @@ impl EncryptedParentDetails {
|
|||
)
|
||||
}
|
||||
|
||||
pub async fn decrypt(&self, priv_key: String) -> Result<ParentDetails, ServiceError> {
|
||||
pub async fn decrypt(&self, priv_key: &String) -> Result<ParentDetails, ServiceError> {
|
||||
let d = tokio::try_join!(
|
||||
self.name.decrypt(&priv_key),
|
||||
self.surname.decrypt(&priv_key),
|
||||
|
|
@ -223,11 +223,11 @@ impl EncryptedParentDetails {
|
|||
)
|
||||
}
|
||||
}
|
||||
impl TryFrom<parent::Model> for EncryptedParentDetails {
|
||||
impl TryFrom<&parent::Model> for EncryptedParentDetails {
|
||||
type Error = ServiceError;
|
||||
|
||||
fn try_from(
|
||||
parent: parent::Model,
|
||||
parent: &parent::Model,
|
||||
) -> Result<Self, Self::Error> {
|
||||
Ok(EncryptedParentDetails {
|
||||
name: EncryptedString::try_from(&parent.name)?,
|
||||
|
|
@ -258,12 +258,12 @@ impl EncryptedApplicationDetails {
|
|||
}
|
||||
|
||||
pub async fn decrypt(self, priv_key: String) -> Result<ApplicationDetails, ServiceError> {
|
||||
let decrypted_candidate = self.candidate.decrypt(priv_key.clone()).await?;
|
||||
let decrypted_candidate = self.candidate.decrypt(&priv_key).await?;
|
||||
|
||||
let decrypted_parents = future::try_join_all(
|
||||
self.parents
|
||||
.iter()
|
||||
.map(|d| d.decrypt(priv_key.clone()))
|
||||
.map(|d| d.decrypt(&priv_key))
|
||||
).await?;
|
||||
|
||||
Ok(ApplicationDetails {
|
||||
|
|
@ -280,7 +280,7 @@ impl TryFrom<(&candidate::Model, Vec<parent::Model>)> for EncryptedApplicationDe
|
|||
(candidate, parents): (&candidate::Model, Vec<parent::Model>),
|
||||
) -> Result<Self, Self::Error> {
|
||||
let enc_parents = parents.iter()
|
||||
.map(|m| EncryptedParentDetails::try_from(m.clone()))
|
||||
.map(|m| EncryptedParentDetails::try_from(m))
|
||||
.collect::<Result<Vec<EncryptedParentDetails>, ServiceError>>()?;
|
||||
|
||||
Ok(EncryptedApplicationDetails {
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ impl AuthenticableTrait for CandidateService {
|
|||
let sessions = Query::find_related_candidate_sessions(db, &candidate)
|
||||
.await?
|
||||
.iter()
|
||||
.map(|s| s.clone().into_active_model())
|
||||
.map(|s| s.to_owned().into_active_model())
|
||||
.collect();
|
||||
|
||||
SessionService::delete_sessions(db, sessions, keep_n_recent).await?;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ impl SessionService {
|
|||
.iter()
|
||||
.take(sessions.len() - min(sessions.len(), keep_n_recent))
|
||||
{
|
||||
Mutation::delete_session(db, session.clone()).await?;
|
||||
Mutation::delete_session(db, session.to_owned()).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in a new issue