Remove useless check
This commit is contained in:
		@@ -37,14 +37,9 @@ pub struct CoupleRequest {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl CoupleRequest {
 | 
					impl CoupleRequest {
 | 
				
			||||||
    pub async fn to_couple(
 | 
					    pub async fn to_couple(self, couple: &mut Couple) -> anyhow::Result<()> {
 | 
				
			||||||
        self,
 | 
					 | 
				
			||||||
        couple: &mut Couple,
 | 
					 | 
				
			||||||
        check_members_existence: bool,
 | 
					 | 
				
			||||||
    ) -> anyhow::Result<()> {
 | 
					 | 
				
			||||||
        if let Some(wife) = self.wife {
 | 
					        if let Some(wife) = self.wife {
 | 
				
			||||||
            if check_members_existence && !members_service::exists(couple.family_id(), wife).await?
 | 
					            if !members_service::exists(couple.family_id(), wife).await? {
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                return Err(CoupleControllerErr::WifeNotExisting.into());
 | 
					                return Err(CoupleControllerErr::WifeNotExisting.into());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -54,9 +49,7 @@ impl CoupleRequest {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if let Some(husband) = self.husband {
 | 
					        if let Some(husband) = self.husband {
 | 
				
			||||||
            if check_members_existence
 | 
					            if !members_service::exists(couple.family_id(), husband).await? {
 | 
				
			||||||
                && !members_service::exists(couple.family_id(), husband).await?
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                return Err(CoupleControllerErr::HusbandNotExisting.into());
 | 
					                return Err(CoupleControllerErr::HusbandNotExisting.into());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -109,7 +102,7 @@ impl CoupleAPI {
 | 
				
			|||||||
pub async fn create(m: FamilyInPath, req: web::Json<CoupleRequest>) -> HttpResult {
 | 
					pub async fn create(m: FamilyInPath, req: web::Json<CoupleRequest>) -> HttpResult {
 | 
				
			||||||
    let mut couple = couples_service::create(m.family_id()).await?;
 | 
					    let mut couple = couples_service::create(m.family_id()).await?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if let Err(e) = req.0.to_couple(&mut couple, true).await {
 | 
					    if let Err(e) = req.0.to_couple(&mut couple).await {
 | 
				
			||||||
        log::error!("Failed to apply couple information! {e}");
 | 
					        log::error!("Failed to apply couple information! {e}");
 | 
				
			||||||
        couples_service::delete(&mut couple).await?;
 | 
					        couples_service::delete(&mut couple).await?;
 | 
				
			||||||
        return Ok(HttpResponse::BadRequest().body(e.to_string()));
 | 
					        return Ok(HttpResponse::BadRequest().body(e.to_string()));
 | 
				
			||||||
@@ -144,7 +137,7 @@ pub async fn get_single(m: FamilyAndCoupleInPath) -> HttpResult {
 | 
				
			|||||||
pub async fn update(m: FamilyAndCoupleInPath, req: web::Json<CoupleRequest>) -> HttpResult {
 | 
					pub async fn update(m: FamilyAndCoupleInPath, req: web::Json<CoupleRequest>) -> HttpResult {
 | 
				
			||||||
    let mut couple = m.to_couple();
 | 
					    let mut couple = m.to_couple();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if let Err(e) = req.0.to_couple(&mut couple, true).await {
 | 
					    if let Err(e) = req.0.to_couple(&mut couple).await {
 | 
				
			||||||
        log::error!("Failed to parse couple information {e}!");
 | 
					        log::error!("Failed to parse couple information {e}!");
 | 
				
			||||||
        return Ok(HttpResponse::BadRequest().body(e.to_string()));
 | 
					        return Ok(HttpResponse::BadRequest().body(e.to_string()));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -104,11 +104,7 @@ fn check_opt_str_val(
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl MemberRequest {
 | 
					impl MemberRequest {
 | 
				
			||||||
    pub async fn to_member(
 | 
					    pub async fn to_member(self, member: &mut Member) -> anyhow::Result<()> {
 | 
				
			||||||
        self,
 | 
					 | 
				
			||||||
        member: &mut Member,
 | 
					 | 
				
			||||||
        check_members_existence: bool, /* TODO: remove this field */
 | 
					 | 
				
			||||||
    ) -> anyhow::Result<()> {
 | 
					 | 
				
			||||||
        let c = StaticConstraints::default();
 | 
					        let c = StaticConstraints::default();
 | 
				
			||||||
        check_opt_str_val(
 | 
					        check_opt_str_val(
 | 
				
			||||||
            &self.first_name,
 | 
					            &self.first_name,
 | 
				
			||||||
@@ -195,9 +191,7 @@ impl MemberRequest {
 | 
				
			|||||||
        )?;
 | 
					        )?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if let Some(mother) = self.mother {
 | 
					        if let Some(mother) = self.mother {
 | 
				
			||||||
            if check_members_existence
 | 
					            if !members_service::exists(member.family_id(), mother).await? {
 | 
				
			||||||
                && !members_service::exists(member.family_id(), mother).await?
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                return Err(MemberControllerErr::MotherNotExisting.into());
 | 
					                return Err(MemberControllerErr::MotherNotExisting.into());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -207,9 +201,7 @@ impl MemberRequest {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if let Some(father) = self.father {
 | 
					        if let Some(father) = self.father {
 | 
				
			||||||
            if check_members_existence
 | 
					            if !members_service::exists(member.family_id(), father).await? {
 | 
				
			||||||
                && !members_service::exists(member.family_id(), father).await?
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                return Err(MemberControllerErr::FatherNotExisting.into());
 | 
					                return Err(MemberControllerErr::FatherNotExisting.into());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -262,7 +254,7 @@ impl MemberAPI {
 | 
				
			|||||||
pub async fn create(f: FamilyInPath, req: web::Json<MemberRequest>) -> HttpResult {
 | 
					pub async fn create(f: FamilyInPath, req: web::Json<MemberRequest>) -> HttpResult {
 | 
				
			||||||
    let mut member = members_service::create(f.family_id()).await?;
 | 
					    let mut member = members_service::create(f.family_id()).await?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if let Err(e) = req.0.to_member(&mut member, true).await {
 | 
					    if let Err(e) = req.0.to_member(&mut member).await {
 | 
				
			||||||
        log::error!("Failed to apply member information! {e}");
 | 
					        log::error!("Failed to apply member information! {e}");
 | 
				
			||||||
        members_service::delete(&mut member).await?;
 | 
					        members_service::delete(&mut member).await?;
 | 
				
			||||||
        return Ok(HttpResponse::BadRequest().body(e.to_string()));
 | 
					        return Ok(HttpResponse::BadRequest().body(e.to_string()));
 | 
				
			||||||
@@ -292,7 +284,7 @@ pub async fn get_single(m: FamilyAndMemberInPath) -> HttpResult {
 | 
				
			|||||||
pub async fn update(m: FamilyAndMemberInPath, req: web::Json<MemberRequest>) -> HttpResult {
 | 
					pub async fn update(m: FamilyAndMemberInPath, req: web::Json<MemberRequest>) -> HttpResult {
 | 
				
			||||||
    let mut member = m.to_member();
 | 
					    let mut member = m.to_member();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if let Err(e) = req.0.to_member(&mut member, true).await {
 | 
					    if let Err(e) = req.0.to_member(&mut member).await {
 | 
				
			||||||
        log::error!("Failed to parse member information {e}!");
 | 
					        log::error!("Failed to parse member information {e}!");
 | 
				
			||||||
        return Ok(HttpResponse::BadRequest().body(e.to_string()));
 | 
					        return Ok(HttpResponse::BadRequest().body(e.to_string()));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user