diff --git a/app/Http/Controllers/TemplateController.php b/app/Http/Controllers/TemplateController.php index 9b2bad4bdb65..60368249c88f 100644 --- a/app/Http/Controllers/TemplateController.php +++ b/app/Http/Controllers/TemplateController.php @@ -22,57 +22,6 @@ class TemplateController extends BaseController } - /** - * Returns a blank entity template - * - * @return \Illuminate\Http\Response - * - * @OA\Get( - * path="/api/v1/templates/{entity}/create", - * operationId="getCreateTemplate", - * tags={"templates"}, - * summary="Returns a blank entity template", - * description="Returns a blank HTML entity temlpate", - * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), - * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), - * @OA\Parameter( - * name="entity", - * in="path", - * description="The Entity (invoice,quote,recurring_invoice)", - * example="invoice", - * required=true, - * @OA\Schema( - * type="string", - * format="string", - * ), - * ), - * @OA\Response( - * response=200, - * description="The template response", - * @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"), - * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), - * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), - * @OA\JsonContent(ref="#/components/schemas/Template"), - * ), - * @OA\Response( - * response=422, - * description="Validation error", - * @OA\JsonContent(ref="#/components/schemas/ValidationError"), - - * ), - * @OA\Response( - * response="default", - * description="Unexpected Error", - * @OA\JsonContent(ref="#/components/schemas/Error"), - * ), - * ) - */ - public function create($entity) - { - - return response()->json(request()->all(), 200); - } - /** * Returns a template filled with entity variables * @@ -149,12 +98,15 @@ class TemplateController extends BaseController * ), * ) */ - public function show($entity, $entity_id) + public function show() { - $class = 'App\Models\\'.ucfirst($entity); + if(request()->has('entity') && request()->has('entity_id')){ - $entity_obj = $class::find($entity_id)->company(); + $class = 'App\Models\\'.ucfirst($entity); + $entity_obj = $class::find($entity_id)->company(); + + } $subject = request()->input('subject'); $body = request()->input('body'); diff --git a/routes/api.php b/routes/api.php index 0e3662470a20..bca82374d72f 100644 --- a/routes/api.php +++ b/routes/api.php @@ -89,8 +89,7 @@ Route::group(['middleware' => ['api_db','api_secret_check','token_auth'], 'prefi Route::post('refresh', 'Auth\LoginController@refresh'); - Route::get('templates/{entity}/create', 'TemplateController@create')->name('templates.create'); - Route::post('templates/{entity}/{entity_id}', 'TemplateController@show')->name('templates.show'); + Route::post('templates', 'TemplateController@show')->name('templates.show'); /* Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit diff --git a/tests/Feature/TemplateApiTest.php b/tests/Feature/TemplateApiTest.php new file mode 100644 index 000000000000..9e8e2bebebae --- /dev/null +++ b/tests/Feature/TemplateApiTest.php @@ -0,0 +1,66 @@ +makeTestData(); + + Session::start(); + + $this->faker = \Faker\Factory::create(); + + Model::reguard(); + } + + + public function testShowTemplate() + { + + $data = [ + 'body' => $this->faker->firstName, + 'subject' => $this->faker->firstName, + ]; + + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token + ])->post('/api/v1/templates', $data); + + + $response->assertStatus(200); + + + } +} \ No newline at end of file