mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-24 12:35:31 +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
|
let public_keys = admins
|
||||||
.iter()
|
.iter()
|
||||||
.map(|admin| admin.public_key.clone())
|
.map(|admin| admin.public_key.to_owned())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(public_keys)
|
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!(
|
let d = tokio::try_join!(
|
||||||
self.name.decrypt(&priv_key), // 0
|
self.name.decrypt(priv_key), // 0
|
||||||
self.surname.decrypt(&priv_key), // 1
|
self.surname.decrypt(priv_key), // 1
|
||||||
self.birthplace.decrypt(&priv_key), // 2
|
self.birthplace.decrypt(priv_key), // 2
|
||||||
self.birthdate.decrypt(&priv_key), // 3
|
self.birthdate.decrypt(priv_key), // 3
|
||||||
self.address.decrypt(&priv_key), // 4
|
self.address.decrypt(priv_key), // 4
|
||||||
self.telephone.decrypt(&priv_key), // 5
|
self.telephone.decrypt(priv_key), // 5
|
||||||
self.citizenship.decrypt(&priv_key), // 6
|
self.citizenship.decrypt(priv_key), // 6
|
||||||
self.email.decrypt(&priv_key), // 7
|
self.email.decrypt(priv_key), // 7
|
||||||
self.sex.decrypt(&priv_key), // 8
|
self.sex.decrypt(priv_key), // 8
|
||||||
self.personal_id_number.decrypt(&priv_key),// 9
|
self.personal_id_number.decrypt(priv_key),// 9
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(CandidateDetails {
|
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!(
|
let d = tokio::try_join!(
|
||||||
self.name.decrypt(&priv_key),
|
self.name.decrypt(&priv_key),
|
||||||
self.surname.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;
|
type Error = ServiceError;
|
||||||
|
|
||||||
fn try_from(
|
fn try_from(
|
||||||
parent: parent::Model,
|
parent: &parent::Model,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
Ok(EncryptedParentDetails {
|
Ok(EncryptedParentDetails {
|
||||||
name: EncryptedString::try_from(&parent.name)?,
|
name: EncryptedString::try_from(&parent.name)?,
|
||||||
|
|
@ -258,12 +258,12 @@ impl EncryptedApplicationDetails {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn decrypt(self, priv_key: String) -> Result<ApplicationDetails, ServiceError> {
|
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(
|
let decrypted_parents = future::try_join_all(
|
||||||
self.parents
|
self.parents
|
||||||
.iter()
|
.iter()
|
||||||
.map(|d| d.decrypt(priv_key.clone()))
|
.map(|d| d.decrypt(&priv_key))
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
Ok(ApplicationDetails {
|
Ok(ApplicationDetails {
|
||||||
|
|
@ -280,7 +280,7 @@ impl TryFrom<(&candidate::Model, Vec<parent::Model>)> for EncryptedApplicationDe
|
||||||
(candidate, parents): (&candidate::Model, Vec<parent::Model>),
|
(candidate, parents): (&candidate::Model, Vec<parent::Model>),
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
let enc_parents = parents.iter()
|
let enc_parents = parents.iter()
|
||||||
.map(|m| EncryptedParentDetails::try_from(m.clone()))
|
.map(|m| EncryptedParentDetails::try_from(m))
|
||||||
.collect::<Result<Vec<EncryptedParentDetails>, ServiceError>>()?;
|
.collect::<Result<Vec<EncryptedParentDetails>, ServiceError>>()?;
|
||||||
|
|
||||||
Ok(EncryptedApplicationDetails {
|
Ok(EncryptedApplicationDetails {
|
||||||
|
|
|
||||||
|
|
@ -308,7 +308,7 @@ impl AuthenticableTrait for CandidateService {
|
||||||
let sessions = Query::find_related_candidate_sessions(db, &candidate)
|
let sessions = Query::find_related_candidate_sessions(db, &candidate)
|
||||||
.await?
|
.await?
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.clone().into_active_model())
|
.map(|s| s.to_owned().into_active_model())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
SessionService::delete_sessions(db, sessions, keep_n_recent).await?;
|
SessionService::delete_sessions(db, sessions, keep_n_recent).await?;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ impl SessionService {
|
||||||
.iter()
|
.iter()
|
||||||
.take(sessions.len() - min(sessions.len(), keep_n_recent))
|
.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(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue