package de.thpeetz.kontor.bookshelf.data;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface AuthorRepository extends JpaRepository<Author, String> {

    @Query("select a from Author a " +
            "where lower(a.firstName) like lower(concat('%', :searchTerm, '%')) " +
            "or lower(a.lastName) like lower(concat('%', :searchTerm, '%'))")
    List<Author> search(@Param("searchTerm") String searchTerm);

    Author findByFirstNameAndLastName(String firstName, String lastName);

}
