package com.izouma.dingdong.repo;

import com.izouma.dingdong.domain.MoneyRecord;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface MoneyRecordRepo extends JpaRepository<MoneyRecord, Long>, JpaSpecificationExecutor<MoneyRecord> {
    List<MoneyRecord> findAllByUserId(Long userId);

    Page<MoneyRecord> findAllByUserId(Long userId, Pageable pageable);

    @Query("update MoneyRecord t set t.enabled = false where t.id = ?1")
    @Modifying
    @Transactional
    void deleteById(Long id);
}