package com.izouma.nineth.service;

import com.izouma.nineth.domain.Invite;
import com.izouma.nineth.dto.PageQuery;
import com.izouma.nineth.repo.InviteRepo;
import com.izouma.nineth.utils.JpaUtils;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

@Service
@AllArgsConstructor
public class InviteService {

    private InviteRepo inviteRepo;

    public Page<Invite> all(PageQuery pageQuery) {
        return inviteRepo.findAll(JpaUtils.toSpecification(pageQuery, Invite.class), JpaUtils.toPageRequest(pageQuery));
    }

    @Transactional(rollbackOn = Exception.class)
    public void cleanInvite() {
        inviteRepo.cleanInvite();
    }
}
