From 66c9e63e260ab926dad550a9f985910c02ab5b7c Mon Sep 17 00:00:00 2001 From: Jean-Marie Poissonnier Date: Tue, 21 Jan 2025 09:40:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix(owner):=20don't=20count=20ar?= =?UTF-8?q?chived=20applications=20(#935)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In dashboard, the application number was counting all applications, including the archived ones. Whereas in the consult property page, only non-archived applications were listed. --- .../dossierfacileapiowner/user/OwnerMapper.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/dossierfacile-api-owner/src/main/java/fr/dossierfacile/api/dossierfacileapiowner/user/OwnerMapper.java b/dossierfacile-api-owner/src/main/java/fr/dossierfacile/api/dossierfacileapiowner/user/OwnerMapper.java index 1b6365dfe..ba2ee22f1 100644 --- a/dossierfacile-api-owner/src/main/java/fr/dossierfacile/api/dossierfacileapiowner/user/OwnerMapper.java +++ b/dossierfacile-api-owner/src/main/java/fr/dossierfacile/api/dossierfacileapiowner/user/OwnerMapper.java @@ -5,8 +5,11 @@ import fr.dossierfacile.common.entity.ApartmentSharing; import fr.dossierfacile.common.entity.Owner; import fr.dossierfacile.common.entity.Property; +import fr.dossierfacile.common.enums.TenantFileStatus; + import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.Named; import org.springframework.stereotype.Component; @Component @@ -20,7 +23,15 @@ public abstract class OwnerMapper { @Mapping( target="totalGuarantorSalary", expression="java(apartmentSharing.totalGuarantorSalary())" ) public abstract ApartmentSharingModel apartmentSharingToApartmentSharingModel(ApartmentSharing apartmentSharing); - @Mapping( target="propertyApartmentSharingCount", expression="java(property.getPropertiesApartmentSharing().size())" ) - @Mapping( source="dpeDate", target="dpeDate", dateFormat="yyyy-MM-dd") + @Mapping( source="property", target="propertyApartmentSharingCount", qualifiedByName="validApplicationsCount" ) + @Mapping( source="dpeDate", target="dpeDate", dateFormat="yyyy-MM-dd" ) public abstract LightPropertyModel toLightPropertyModel(Property property); + + @Named("validApplicationsCount") + public static int getValidApplicationsCount(Property property) { + long count = property.getPropertiesApartmentSharing().stream() + .filter(p -> !p.getApartmentSharing().getStatus().equals(TenantFileStatus.ARCHIVED)) + .count(); + return (int) count; + } }