package org.example.seed.repository;

import org.example.seed.catalog.OrderStatus;
import org.example.seed.entity.OrderEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Optional;

/**
 * Created by PINA on 30/06/2017.
 */
@Repository
public interface OrderRepository extends JpaRepository<OrderEntity, String> {

    @Query("SELECT oe FROM ClientEntity ce JOIN ce.orders AS oe WHERE ce.id = ?1 AND oe.id = ?2 AND oe.status = ?3")
    Optional<OrderEntity> findByClientAndOrder(final String idClient, final String idOrder, final OrderStatus status);

    @Query("SELECT oe.id FROM ClientEntity ce JOIN ce.orders AS oe WHERE ce.id = ?1 AND oe.id = ?2 AND oe.status = ?3")
    Optional<String> findIdByClientAndOrder(final String idClient, final String idOrder, final OrderStatus status);
}

@@ -120,16 +120,113 @@
 Entity;%0A
+import org.springframework.data.domain.Page;%0Aimport org.springframework.data.domain.PageRequest;%0A
 import o
@@ -545,18 +545,16 @@
 ing%3E %7B%0A%0A
-  
   @Query
@@ -564,16 +564,19 @@
 ELECT oe
+.id
  FROM Cl
@@ -655,34 +655,32 @@
 e.status = ?3%22)%0A
-  
   Optional%3COrder
@@ -678,25 +678,22 @@
 nal%3C
-OrderEntity
+String
 %3E find
+Id
 ByCl
@@ -778,18 +778,16 @@
 atus);%0A%0A
-  
   @Query
@@ -789,35 +789,32 @@
 Query(%22SELECT oe
-.id
  FROM ClientEnti
@@ -893,18 +893,16 @@
  = ?3%22)%0A
-  
   Option
@@ -900,38 +900,41 @@
 %0A  Optional%3C
-String
+OrderEntity
 %3E find
-Id
 ByClientAndO
@@ -1009,11 +1009,351 @@
 status);
+%0A%0A  @Query(%22SELECT oe FROM ClientEntity ce JOIN ce.orders AS oe WHERE ce.id = ?1%22)%0A  Page%3COrderEntity%3E findAllByClient(final String idClient, final PageRequest pageRequest);%0A%0A  @Query(%22SELECT oe FROM ChefEntity ce JOIN ce.orders AS oe WHERE ce.id = ?1%22)%0A  Page%3COrderEntity%3E findAllByChef(final String idChef, final PageRequest pageRequest);
 %0A%7D%0A

add methods based on client id and chef