Skip to content

Commit

Permalink
feat(owner): Add new log types in property_log table for application …
Browse files Browse the repository at this point in the history
…creation/deletion (#636)
  • Loading branch information
juliette-derancourt authored Nov 7, 2023
1 parent 015bea4 commit 7e917e7
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
package fr.dossierfacile.api.dossierfacileapiowner.property;

import fr.dossierfacile.api.dossierfacileapiowner.mail.MailService;
import fr.dossierfacile.common.entity.ApartmentSharing;
import fr.dossierfacile.common.entity.Property;
import fr.dossierfacile.common.entity.PropertyApartmentSharing;
import fr.dossierfacile.common.entity.Tenant;
import fr.dossierfacile.common.enums.TenantType;
import fr.dossierfacile.common.repository.PropertyLogRepository;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import static fr.dossierfacile.common.entity.PropertyLog.*;

@Slf4j
@Service
@AllArgsConstructor
public class PropertyApartmentSharingServiceImpl implements PropertyApartmentSharingService {
private final PropertyApartmentSharingRepository propertyApartmentSharingRepository;
private final PropertyLogRepository logRepository;
private final MailService mailService;

@Override
public void deletePropertyApartmentSharing(PropertyApartmentSharing propertyApartmentSharing) {
propertyApartmentSharingRepository.delete(propertyApartmentSharing);
logRepository.save(applicationDeletedByOwner(propertyApartmentSharing));
}

@Override
public void subscribeTenantApartmentSharingToProperty(Tenant tenant, Property property, boolean hasAccess) {
if (tenant.getTenantType() == TenantType.CREATE) {
ApartmentSharing apartmentSharing = tenant.getApartmentSharing();
PropertyApartmentSharing propertyApartmentSharing = propertyApartmentSharingRepository
.findByPropertyAndApartmentSharing(property, tenant.getApartmentSharing())
.findByPropertyAndApartmentSharing(property, apartmentSharing)
.orElse(PropertyApartmentSharing.builder()
.accessFull(hasAccess)
.token(hasAccess ? tenant.getApartmentSharing().getToken() : tenant.getApartmentSharing().getTokenPublic())
.token(hasAccess ? apartmentSharing.getToken() : apartmentSharing.getTokenPublic())
.property(property)
.apartmentSharing(tenant.getApartmentSharing())
.apartmentSharing(apartmentSharing)
.build()
);
propertyApartmentSharingRepository.save(propertyApartmentSharing);
logRepository.save(applicationReceived(property, apartmentSharing));
mailService.sendEmailNewApplicant(tenant, property.getOwner(), property);
} else {
throw new IllegalStateException("Tenant is not the main tenant");

0 comments on commit 7e917e7

Please sign in to comment.