author | ymh <ymh.work@gmail.com> |
Tue, 23 Feb 2016 17:57:46 +0100 | |
changeset 128 | bc18286e55b2 |
parent 125 | e550b10fe3ca |
child 130 | fac22d8c2df8 |
permissions | -rw-r--r-- |
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(); |
125 | 29 |
$res = $paginator->toArray(); |
30 |
if(array_key_exists('data', $res)) { |
|
31 |
$documents = $res['data']; |
|
32 |
unset($res['data']); |
|
128
bc18286e55b2
remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents:
125
diff
changeset
|
33 |
//$res['documents'] = $this->documentRepository->resolveLexvo($documents); |
20 | 34 |
} |
35 |
return response()->json($res); |
|
4 | 36 |
} |
37 |
||
38 |
/** |
|
39 |
* Show the form for creating a new resource. |
|
40 |
* |
|
41 |
* @return Response |
|
42 |
*/ |
|
43 |
public function create() |
|
44 |
{ |
|
45 |
// |
|
46 |
} |
|
47 |
||
48 |
/** |
|
49 |
* Store a newly created resource in storage. |
|
50 |
* |
|
51 |
* @param Request $request |
|
52 |
* @return Response |
|
53 |
*/ |
|
54 |
public function store(Request $request) |
|
55 |
{ |
|
56 |
// |
|
57 |
} |
|
58 |
||
59 |
/** |
|
60 |
* Display the specified resource. |
|
61 |
* |
|
62 |
* @param int $id |
|
63 |
* @return Response |
|
64 |
*/ |
|
65 |
public function show($id) |
|
66 |
{ |
|
67 |
$doc = $this->documentRepository->get($id); |
|
68 |
if(is_null($doc)) { |
|
69 |
abort(404); |
|
70 |
} |
|
128
bc18286e55b2
remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents:
125
diff
changeset
|
71 |
//$this->documentRepository->resolveLexvo([$doc,]); |
20 | 72 |
return response()->json(["document" => $doc]); |
4 | 73 |
} |
74 |
||
75 |
/** |
|
76 |
* Show the form for editing the specified resource. |
|
77 |
* |
|
78 |
* @param int $id |
|
79 |
* @return Response |
|
80 |
*/ |
|
81 |
public function edit($id) |
|
82 |
{ |
|
83 |
// |
|
84 |
} |
|
85 |
||
86 |
/** |
|
28 | 87 |
* Update the specified document in storage. |
4 | 88 |
* |
89 |
* @param Request $request |
|
90 |
* @param int $id |
|
91 |
* @return Response |
|
92 |
*/ |
|
93 |
public function update(Request $request, $id) |
|
94 |
{ |
|
28 | 95 |
$data = $request->json(); |
96 |
$document = $data->get('document'); |
|
97 |
$doc = $this->documentRepository->get($id); |
|
98 |
if(is_null($doc)) { |
|
99 |
abort(404); |
|
100 |
} |
|
101 |
||
102 |
//for now, update contributors only |
|
103 |
$doc->setContributors($document['contributors']); |
|
104 |
||
105 |
$this->documentRepository->save($doc); |
|
106 |
||
107 |
return response('', 204); |
|
4 | 108 |
} |
109 |
||
110 |
/** |
|
111 |
* Remove the specified resource from storage. |
|
112 |
* |
|
113 |
* @param int $id |
|
114 |
* @return Response |
|
115 |
*/ |
|
116 |
public function destroy($id) |
|
117 |
{ |
|
118 |
// |
|
119 |
} |
|
120 |
} |