mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-30 20:43:52 -04:00 
			
		
		
		
	Adjustments for template controller to make entity and entity_id optional (#3108)
This commit is contained in:
		
							parent
							
								
									32aedf26dd
								
							
						
					
					
						commit
						cbe4dc072b
					
				| @ -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'); | ||||
|  | ||||
| @ -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
 | ||||
|  | ||||
							
								
								
									
										66
									
								
								tests/Feature/TemplateApiTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								tests/Feature/TemplateApiTest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,66 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Tests\Feature; | ||||
| 
 | ||||
| use App\DataMapper\DefaultSettings; | ||||
| use App\Models\Account; | ||||
| use App\Models\Client; | ||||
| use App\Models\ClientContact; | ||||
| use App\Models\Company; | ||||
| use App\Models\User; | ||||
| use App\Utils\Traits\MakesHash; | ||||
| use Faker\Factory; | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
| use Illuminate\Foundation\Testing\DatabaseTransactions; | ||||
| use Illuminate\Foundation\Testing\RefreshDatabase; | ||||
| use Illuminate\Foundation\Testing\WithFaker; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\Log; | ||||
| use Illuminate\Support\Facades\Session; | ||||
| use Tests\MockAccountData; | ||||
| use Tests\TestCase; | ||||
| 
 | ||||
| /** | ||||
|  * @test | ||||
|  * @covers App\Http\Controllers\TemplateController | ||||
|  */ | ||||
| class TemplateApiTest extends TestCase | ||||
| { | ||||
|     use MakesHash; | ||||
|     use DatabaseTransactions; | ||||
|     use MockAccountData; | ||||
| 
 | ||||
|     public function setUp() :void | ||||
|     { | ||||
|         parent::setUp(); | ||||
| 
 | ||||
|         $this->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); | ||||
|      | ||||
| 
 | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user