package com.izouma.dingdong.service.backstage;

import com.izouma.dingdong.domain.merchant.Merchant;
import com.izouma.dingdong.repo.backstage.PromoteRepo;
import com.izouma.dingdong.repo.merchant.MerchantRepo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;


@Service
@AllArgsConstructor
public class PromoteService {

    private PromoteRepo  promoteRepo;
    private MerchantRepo merchantRepo;

    public void all() {
        promoteRepo.findAll().forEach(promote -> {
            Merchant merchant = merchantRepo.findById(promote.getMerchantId()).orElse(null);
            if (merchant == null) {
                promoteRepo.deleteById(promote.getId());
            }
        });
    }
}
