PromoteurService.java
package com.sintia.ffl.admin.dentaire.services.services;
import com.sintia.ffl.admin.dentaire.dal.entities.Promoteur;
import com.sintia.ffl.admin.dentaire.dal.repositories.PromoteurRepository;
import com.sintia.ffl.admin.dentaire.services.mappers.PromoteurMapper;
import com.sintia.ffl.adminui.commons.dto.PromoteurDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
@RequiredArgsConstructor
@Slf4j
public class PromoteurService {
private final PromoteurRepository promoteurRepository;
private final PromoteurMapper promoteurMapper;
public Optional<PromoteurDTO> saveLogo(Integer idPromoteur, byte[] logo ){
Optional<Promoteur> optionalPromoteur = promoteurRepository.findById(idPromoteur);
if (optionalPromoteur.isEmpty())
return Optional.empty();
Promoteur promoteur = optionalPromoteur.get();
promoteur.setLogoFile(logo);
promoteur = promoteurRepository.save(promoteur);
log.info("promoteur {}", promoteur);
PromoteurDTO promoteurDTO = promoteurMapper.toDto(promoteur);
return Optional.of(promoteurDTO);
}
public Optional<PromoteurDTO> saveManuel(Integer idPromoteur, byte[] docFile ){
Optional<Promoteur> optionalPromoteur = promoteurRepository.findById(idPromoteur);
if (optionalPromoteur.isEmpty())
return Optional.empty();
Promoteur promoteur = optionalPromoteur.get();
promoteur.setManuelUtilisateurFile(docFile);
promoteur = promoteurRepository.save(promoteur);
PromoteurDTO promoteurDTO = promoteurMapper.toDto(promoteur);
return Optional.of(promoteurDTO);
}
}