author | ymh <ymh.work@gmail.com> |
Fri, 04 Mar 2016 10:08:52 +0100 | |
changeset 138 | 3079cbf80006 |
parent 130 | fac22d8c2df8 |
child 163 | 59c68fc4848e |
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']); |
|
130
fac22d8c2df8
add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents:
128
diff
changeset
|
33 |
$res['documents'] = $documents; |
128
bc18286e55b2
remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents:
125
diff
changeset
|
34 |
//$res['documents'] = $this->documentRepository->resolveLexvo($documents); |
20 | 35 |
} |
36 |
return response()->json($res); |
|
4 | 37 |
} |
38 |
||
39 |
/** |
|
40 |
* Show the form for creating a new resource. |
|
41 |
* |
|
42 |
* @return Response |
|
43 |
*/ |
|
44 |
public function create() |
|
45 |
{ |
|
46 |
// |
|
47 |
} |
|
48 |
||
49 |
/** |
|
50 |
* Store a newly created resource in storage. |
|
51 |
* |
|
52 |
* @param Request $request |
|
53 |
* @return Response |
|
54 |
*/ |
|
55 |
public function store(Request $request) |
|
56 |
{ |
|
57 |
// |
|
58 |
} |
|
59 |
||
60 |
/** |
|
61 |
* Display the specified resource. |
|
62 |
* |
|
63 |
* @param int $id |
|
64 |
* @return Response |
|
65 |
*/ |
|
66 |
public function show($id) |
|
67 |
{ |
|
68 |
$doc = $this->documentRepository->get($id); |
|
69 |
if(is_null($doc)) { |
|
70 |
abort(404); |
|
71 |
} |
|
128
bc18286e55b2
remove resolve lexvo on server in the api
ymh <ymh.work@gmail.com>
parents:
125
diff
changeset
|
72 |
//$this->documentRepository->resolveLexvo([$doc,]); |
20 | 73 |
return response()->json(["document" => $doc]); |
4 | 74 |
} |
75 |
||
76 |
/** |
|
77 |
* Show the form for editing the specified resource. |
|
78 |
* |
|
79 |
* @param int $id |
|
80 |
* @return Response |
|
81 |
*/ |
|
82 |
public function edit($id) |
|
83 |
{ |
|
84 |
// |
|
85 |
} |
|
86 |
||
87 |
/** |
|
28 | 88 |
* Update the specified document in storage. |
4 | 89 |
* |
90 |
* @param Request $request |
|
91 |
* @param int $id |
|
92 |
* @return Response |
|
93 |
*/ |
|
94 |
public function update(Request $request, $id) |
|
95 |
{ |
|
28 | 96 |
$data = $request->json(); |
97 |
$document = $data->get('document'); |
|
98 |
$doc = $this->documentRepository->get($id); |
|
99 |
if(is_null($doc)) { |
|
100 |
abort(404); |
|
101 |
} |
|
102 |
||
138
3079cbf80006
add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents:
130
diff
changeset
|
103 |
//for now, update contributors and subjects only |
28 | 104 |
$doc->setContributors($document['contributors']); |
138
3079cbf80006
add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents:
130
diff
changeset
|
105 |
$doc->setSubjects($document['subjects']); |
3079cbf80006
add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents:
130
diff
changeset
|
106 |
|
3079cbf80006
add subjects save + set modified date when saing document in rest api
ymh <ymh.work@gmail.com>
parents:
130
diff
changeset
|
107 |
$doc->setModified(); |
28 | 108 |
|
109 |
$this->documentRepository->save($doc); |
|
110 |
||
111 |
return response('', 204); |
|
4 | 112 |
} |
113 |
||
114 |
/** |
|
115 |
* Remove the specified resource from storage. |
|
116 |
* |
|
117 |
* @param int $id |
|
118 |
* @return Response |
|
119 |
*/ |
|
120 |
public function destroy($id) |
|
121 |
{ |
|
122 |
// |
|
123 |
} |
|
124 |
} |