| 
									
										
										
										
											2018-04-11 19:49:35 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Grocy\Controllers; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BaseApiController extends BaseController | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-22 14:25:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 17:42:03 +01:00
										 |  |  | 	public function __construct(\DI\Container $container) | 
					
						
							| 
									
										
										
										
											2018-04-22 14:25:08 +02:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		parent::__construct($container); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-01 23:47:47 +07:00
										 |  |  | 	protected $OpenApiSpec = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	protected function getOpenApispec() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if($this->OpenApiSpec == null) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			$this->OpenApiSpec = json_decode(file_get_contents(__DIR__ . '/../grocy.openapi.json')); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return $this->OpenApiSpec; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-22 14:25:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 17:42:03 +01:00
										 |  |  | 	protected function ApiResponse(\Psr\Http\Message\ResponseInterface $response, $data) | 
					
						
							| 
									
										
										
										
											2018-04-22 14:25:08 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-02-11 17:42:03 +01:00
										 |  |  | 		$response->getBody()->write(json_encode($data)); | 
					
						
							|  |  |  | 		return $response; | 
					
						
							| 
									
										
										
										
											2018-04-22 14:25:08 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 17:42:03 +01:00
										 |  |  | 	protected function EmptyApiResponse(\Psr\Http\Message\ResponseInterface $response, $status = 204) | 
					
						
							| 
									
										
										
										
											2019-01-19 14:51:51 +01:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		return $response->withStatus($status); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 17:42:03 +01:00
										 |  |  | 	protected function GenericErrorResponse(\Psr\Http\Message\ResponseInterface $response, $errorMessage, $status = 400) | 
					
						
							| 
									
										
										
										
											2018-04-11 19:49:35 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-04-22 14:25:08 +02:00
										 |  |  | 		return $response->withStatus($status)->withJson(array( | 
					
						
							|  |  |  | 			'error_message' => $errorMessage | 
					
						
							|  |  |  | 		)); | 
					
						
							| 
									
										
										
										
											2018-04-11 19:49:35 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |