PromoteurService.java
package com.sintia.ffl.admin.audio.services.services;
import com.sintia.ffl.admin.audio.dal.entities.Promoteur;
import com.sintia.ffl.admin.audio.dal.repositories.PromoteurRepository;
import com.sintia.ffl.admin.audio.services.mappers.PromoteurMapper;
import com.sintia.ffl.adminui.commons.dto.PromoteurDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Slf4j
@Service
public class PromoteurService {
@Autowired
private PromoteurRepository promoteurRepository;
@Autowired
private PromoteurMapper promoteurMapper;
public PromoteurService(PromoteurRepository promoteurRepository, PromoteurMapper promoteurMapper) {
this.promoteurRepository = promoteurRepository;
this.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.setManuelFile(docFile);
promoteur = promoteurRepository.save(promoteur);
PromoteurDTO promoteurDTO = promoteurMapper.toDto(promoteur);
return Optional.of(promoteurDTO);
}
}