1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/app/Http/Controllers/DocumentAPIController.php

71 lines
1.5 KiB
PHP
Raw Normal View History

2016-05-21 10:44:53 +02:00
<?php namespace App\Http\Controllers;
use App\Models\Document;
use App\Ninja\Repositories\DocumentRepository;
use App\Http\Requests\DocumentRequest;
use App\Http\Requests\CreateDocumentRequest;
/**
* Class DocumentAPIController
*/
2016-05-21 10:44:53 +02:00
class DocumentAPIController extends BaseAPIController
{
/**
* @var DocumentRepository
*/
protected $documentRepo;
/**
* @var string
*/
protected $entityType = ENTITY_DOCUMENT;
2016-05-21 10:44:53 +02:00
/**
* DocumentAPIController constructor.
*
* @param DocumentRepository $documentRepo
*/
public function __construct(DocumentRepository $documentRepo)
2016-05-21 10:44:53 +02:00
{
parent::__construct();
$this->documentRepo = $documentRepo;
2016-05-21 10:44:53 +02:00
}
/**
* @return \Illuminate\Http\Response
*/
2016-05-21 10:44:53 +02:00
public function index()
{
2016-06-05 12:15:49 +02:00
$documents = Document::scope();
2016-06-05 12:00:21 +02:00
2016-06-05 12:13:38 +02:00
return $this->listResponse($documents);
2016-06-05 12:00:21 +02:00
2016-05-21 10:44:53 +02:00
}
/**
* @param DocumentRequest $request
*
* @return \Illuminate\Http\Response|\Redirect|\Symfony\Component\HttpFoundation\StreamedResponse
*/
public function show(DocumentRequest $request)
2016-05-21 10:44:53 +02:00
{
$document = $request->entity();
2016-05-21 10:44:53 +02:00
return DocumentController::getDownloadResponse($document);
}
/**
* @param CreateDocumentRequest $request
*
* @return \Illuminate\Http\Response
*/
public function store(CreateDocumentRequest $request)
2016-05-21 10:44:53 +02:00
{
2016-06-01 12:15:31 +02:00
$document = $this->documentRepo->upload($request->all());
return $this->itemResponse($document);
2016-05-21 10:44:53 +02:00
}
}