Created
June 15, 2016 04:11
-
-
Save NiltonMorais/27b546ac91a2718167259a82931ef62f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace DeliveryUrbano\Http\Controllers\Api\Client; | |
| use \DeliveryUrbano\Http\Controllers\Controller; | |
| use DeliveryUrbano\Http\Requests\CheckoutRequest; | |
| use DeliveryUrbano\Repositories\OrderRepository; | |
| use DeliveryUrbano\Repositories\UserRepository; | |
| use DeliveryUrbano\Services\OrderService; | |
| use \LucaDegasperi\OAuth2Server\Facades\Authorizer; | |
| class ClientCheckoutController extends Controller { | |
| /** | |
| * @var OrderRepository | |
| */ | |
| private $orderRepository; | |
| /** | |
| * @var UserRepository | |
| */ | |
| private $userRepository; | |
| /** | |
| * @var OrderService | |
| */ | |
| private $orderService; | |
| private $with = ['client', 'cupom', 'items']; | |
| public function __construct(OrderRepository $orderRepository, UserRepository $userRepository, OrderService $orderService) { | |
| $this->orderRepository = $orderRepository; | |
| $this->userRepository = $userRepository; | |
| $this->orderService = $orderService; | |
| } | |
| public function index(CheckoutRequest $request) { | |
| dd("passou"); | |
| $id = Authorizer::getResourceOwnerId(); | |
| $userId = $id; | |
| $orders = $this->orderRepository | |
| ->skipPresenter(false) | |
| ->with($this->with) | |
| ->scopeQuery(function($query) use ($userId){ | |
| return $query->where('user_client_id','=',$userId); | |
| })->paginate(); | |
| return $orders; | |
| } | |
| public function store(CheckoutRequest $request) { | |
| $data = $request->all(); | |
| $data['user_client_id'] = Authorizer::getResourceOwnerId(); | |
| $order = $this->orderService->create($data); | |
| return $this->orderRepository | |
| ->skipPresenter(false) | |
| ->with($this->with) | |
| ->find($order->id); | |
| } | |
| public function show($id) { | |
| return $this->orderRepository | |
| ->skipPresenter(false) | |
| ->with($this->with)->find($id); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment