34 lines
1.3 KiB
Java
34 lines
1.3 KiB
Java
package org.hso.ecommerce.repos.shop;
|
|
|
|
import org.hso.ecommerce.entities.shop.Article;
|
|
import org.springframework.data.jpa.repository.JpaRepository;
|
|
import org.springframework.data.jpa.repository.Query;
|
|
import org.springframework.data.repository.query.Param;
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
import java.util.List;
|
|
|
|
@Repository
|
|
public interface ArticleRepository extends JpaRepository<Article, Long> {
|
|
|
|
@Query("SELECT a FROM Article a WHERE a.id = :articleId")
|
|
Article findArticleById(@Param("articleId") long articleId);
|
|
|
|
@Query("SELECT a FROM Article a")
|
|
List<Article> findAll();
|
|
|
|
@Query("SELECT a FROM Article a JOIN a.related ao WHERE ao.shouldBeAdvertised = true")
|
|
List<Article> getAdvertisedArticles();
|
|
|
|
@Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a ORDER BY co.id DESC")
|
|
List<Article> getOrderedArticles();
|
|
|
|
@Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a WHERE c.id = :customerId ORDER BY co.id DESC")
|
|
List<Article> getOrderedArticles(long customerId);
|
|
|
|
@Query("SELECT a FROM Article a WHERE a.title LIKE %:term%")
|
|
List<Article> getArticlesByTerm(String term);
|
|
|
|
@Query("SELECT a FROM Article a JOIN a.categories c WHERE :category = c.name")
|
|
List<Article> getArticlesByCategory(String category);
|
|
} |