Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 31 |
| TraitProxyApiController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 31 |
| index | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| store | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 9 |
|||
| show | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| update | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 9 |
|||
| destroy | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\ApiGateway\Controllers; |
| 4 | |
| 5 | use \Illuminate\Http\Request; |
| 6 | use \Illuminate\Http\Response; |
| 7 | use Illuminate\Support\Facades\Log; |
| 8 | |
| 9 | trait TraitProxyApiController |
| 10 | { |
| 11 | /** |
| 12 | * Display a listing of the resource. |
| 13 | * |
| 14 | * @return \Illuminate\Http\Response |
| 15 | */ |
| 16 | public function index(Request $request) |
| 17 | { |
| 18 | $response = $this->getResponseFromService( |
| 19 | $this->serviceName, |
| 20 | $this->resourceName, |
| 21 | ['query' => $request->all()] |
| 22 | ); |
| 23 | |
| 24 | return $this->respond($response, Response::HTTP_OK, Response::HTTP_UNPROCESSABLE_ENTITY); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Store a newly created resource in storage. |
| 29 | * |
| 30 | * @param \Illuminate\Http\Request $request |
| 31 | * @return \Illuminate\Http\Response |
| 32 | */ |
| 33 | public function store(Request $request) |
| 34 | { |
| 35 | if ( |
| 36 | preg_match('/multipart\/form-data/', $request->headers->get('Content-Type')) || |
| 37 | preg_match('/multipart\/form-data/', $request->headers->get('content-type')) |
| 38 | ) { |
| 39 | $method = 'multipart'; |
| 40 | } else { |
| 41 | $method = 'body'; |
| 42 | } |
| 43 | |
| 44 | $response = $this->postResponseFromService( |
| 45 | $this->serviceName, |
| 46 | $this->resourceName, |
| 47 | [$method => $request->all()] |
| 48 | ); |
| 49 | |
| 50 | return $this->respond($response, Response::HTTP_CREATED, Response::HTTP_UNPROCESSABLE_ENTITY); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Display the specified resource. |
| 55 | * |
| 56 | * @param $element |
| 57 | * @return Response |
| 58 | */ |
| 59 | public function show($element) |
| 60 | { |
| 61 | $response = $this->getResponseFromService( |
| 62 | $this->serviceName, |
| 63 | "{$this->resourceName}/$element" |
| 64 | ); |
| 65 | |
| 66 | return $this->respond($response, Response::HTTP_OK, Response::HTTP_UNPROCESSABLE_ENTITY); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Update the specified resource in storage. |
| 71 | * |
| 72 | * @param \Illuminate\Http\Request $request |
| 73 | * @param $element |
| 74 | * @return Response |
| 75 | */ |
| 76 | public function update(Request $request, $element = null) |
| 77 | { |
| 78 | if ( |
| 79 | preg_match('/multipart\/form-data/', $request->headers->get('Content-Type')) || |
| 80 | preg_match('/multipart\/form-data/', $request->headers->get('content-type')) |
| 81 | ) { |
| 82 | $method = 'multipart'; |
| 83 | } else { |
| 84 | $method = 'body'; |
| 85 | } |
| 86 | |
| 87 | $resource = $element === null ? $this->resourceName : "{$this->resourceName}/$element"; |
| 88 | |
| 89 | $response = $this->putResponseFromService( |
| 90 | $this->serviceName, |
| 91 | $resource, |
| 92 | [$method => $request->all()] |
| 93 | ); |
| 94 | |
| 95 | return $this->respond($response, Response::HTTP_OK, Response::HTTP_UNPROCESSABLE_ENTITY); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Remove the specified resource from storage. |
| 100 | * |
| 101 | * @param $element |
| 102 | * @return Response |
| 103 | */ |
| 104 | public function destroy($element = null) |
| 105 | { |
| 106 | $resource = $element === null ? $this->resourceName : "{$this->resourceName}/$element"; |
| 107 | $response = $this->deleteResponseFromService( |
| 108 | $this->serviceName, |
| 109 | $resource |
| 110 | ); |
| 111 | |
| 112 | return $this->respond($response, Response::HTTP_OK, Response::HTTP_UNPROCESSABLE_ENTITY); |
| 113 | } |
| 114 | } |