4
|
1 |
<?php |
|
2 |
|
|
3 |
namespace CorpusParole\Http\Controllers\Api; |
|
4 |
|
|
5 |
use Illuminate\Http\Request; |
28
|
6 |
//use Illuminate\Http\Response; |
4
|
7 |
|
|
8 |
use CorpusParole\Http\Requests; |
|
9 |
use CorpusParole\Http\Controllers\Controller; |
|
10 |
use CorpusParole\Repositories\DocumentRepository; |
|
11 |
|
|
12 |
class DocumentController extends Controller |
|
13 |
{ |
|
14 |
/** |
|
15 |
* Create a new controller instance. |
|
16 |
*/ |
|
17 |
public function __construct(DocumentRepository $documentRepo) { |
|
18 |
$this->documentRepository = $documentRepo; |
|
19 |
} |
|
20 |
|
|
21 |
/** |
|
22 |
* Display a listing of the resource. |
|
23 |
* |
|
24 |
* @return Response |
|
25 |
*/ |
|
26 |
public function index() |
|
27 |
{ |
20
|
28 |
$paginator = $this->documentRepository->paginateAll(); |
|
29 |
$res = []; |
|
30 |
foreach ($paginator->toArray() as $key => $value) { |
|
31 |
$res[($key === 'data')?'documents':$key] = $value; |
|
32 |
} |
|
33 |
return response()->json($res); |
4
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* Show the form for creating a new resource. |
|
38 |
* |
|
39 |
* @return Response |
|
40 |
*/ |
|
41 |
public function create() |
|
42 |
{ |
|
43 |
// |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Store a newly created resource in storage. |
|
48 |
* |
|
49 |
* @param Request $request |
|
50 |
* @return Response |
|
51 |
*/ |
|
52 |
public function store(Request $request) |
|
53 |
{ |
|
54 |
// |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Display the specified resource. |
|
59 |
* |
|
60 |
* @param int $id |
|
61 |
* @return Response |
|
62 |
*/ |
|
63 |
public function show($id) |
|
64 |
{ |
|
65 |
$doc = $this->documentRepository->get($id); |
|
66 |
if(is_null($doc)) { |
|
67 |
abort(404); |
|
68 |
} |
20
|
69 |
return response()->json(["document" => $doc]); |
4
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Show the form for editing the specified resource. |
|
74 |
* |
|
75 |
* @param int $id |
|
76 |
* @return Response |
|
77 |
*/ |
|
78 |
public function edit($id) |
|
79 |
{ |
|
80 |
// |
|
81 |
} |
|
82 |
|
|
83 |
/** |
28
|
84 |
* Update the specified document in storage. |
4
|
85 |
* |
|
86 |
* @param Request $request |
|
87 |
* @param int $id |
|
88 |
* @return Response |
|
89 |
*/ |
|
90 |
public function update(Request $request, $id) |
|
91 |
{ |
28
|
92 |
$data = $request->json(); |
|
93 |
$document = $data->get('document'); |
|
94 |
$doc = $this->documentRepository->get($id); |
|
95 |
if(is_null($doc)) { |
|
96 |
abort(404); |
|
97 |
} |
|
98 |
|
|
99 |
//for now, update contributors only |
|
100 |
$doc->setContributors($document['contributors']); |
|
101 |
|
|
102 |
$this->documentRepository->save($doc); |
|
103 |
|
|
104 |
return response('', 204); |
4
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* Remove the specified resource from storage. |
|
109 |
* |
|
110 |
* @param int $id |
|
111 |
* @return Response |
|
112 |
*/ |
|
113 |
public function destroy($id) |
|
114 |
{ |
|
115 |
// |
|
116 |
} |
|
117 |
} |