From d31258cc82d67bb8680d7eefe50268992c6e2350 Mon Sep 17 00:00:00 2001 From: Asif Date: Mon, 7 May 2018 14:38:40 +0800 Subject: [PATCH] contact controller model table --- app/Http/Controllers/ContactController.php | 11 ++- ...018_04_30_082838_create_contacts_table.php | 2 +- routes/api.php | 3 +- tests/Unit/contactTest.php | 85 +++++++++++++++++-- 4 files changed, 93 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/ContactController.php b/app/Http/Controllers/ContactController.php index bde47a1..a74a792 100644 --- a/app/Http/Controllers/ContactController.php +++ b/app/Http/Controllers/ContactController.php @@ -32,6 +32,15 @@ class ContactController extends Controller { // } + public function searchContact($id) + { + + + + $matchedTerm = Breed::where('ff_id', 'LIKE', $id . '%')->get(); + return response()->json($matchedTerm); + } + /** * Store a newly created resource in storage. @@ -42,7 +51,7 @@ class ContactController extends Controller public function store(Request $request) { $contact = Contact::create($request->all()); - + // $contact->created=true; return response()->json($contact, 201); } diff --git a/database/migrations/2018_04_30_082838_create_contacts_table.php b/database/migrations/2018_04_30_082838_create_contacts_table.php index 8409379..8146118 100644 --- a/database/migrations/2018_04_30_082838_create_contacts_table.php +++ b/database/migrations/2018_04_30_082838_create_contacts_table.php @@ -15,7 +15,7 @@ class CreateContactsTable extends Migration { Schema::create('contacts', function (Blueprint $table) { $table->increments('id'); - $table->string('ff_id'); + $table->integer('ff_id')->unique(); $table->timestamps(); }); } diff --git a/routes/api.php b/routes/api.php index 40aad41..9b8c68a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -36,4 +36,5 @@ Route :: get('/warehouse','WarehouseController@index'); Route :: delete('/contacts/{ff_id}','ContactController@destroy'); Route :: get('/contacts','ContactController@index'); -Route :: post('/contacts','ContactController@store'); \ No newline at end of file +Route :: post('/contacts','ContactController@store'); +Route::get('/company/search/{name}', 'CompanyController@searchContact'); \ No newline at end of file diff --git a/tests/Unit/contactTest.php b/tests/Unit/contactTest.php index cb9e312..a149a58 100644 --- a/tests/Unit/contactTest.php +++ b/tests/Unit/contactTest.php @@ -1,10 +1,12 @@ json('POST', '/api/contacts', ['ff_id' => '10']); + $response = $this->json('POST', '/api/contacts', ['ff_id' => '14']); $response ->assertStatus(201); -// ->assertExactJson([ -// 'created' => true, -// ]); +// ->assertJson( +// [ +// 'success' => true, +// 'message' => 'Success' +// //'response' => [ +// // 'id' => $contacts->ff_id, +// // ] +// ]); } @@ -39,7 +46,75 @@ class contactTest extends TestCase $response->assertStatus(200); } +// public function testUPdate() +// { +// +// $response = $this->json('PUT', '/api/warehouse/{war_id}' . $article->id, $payload, $headers) +// ->assertStatus(200) +// ->assertJson([ +// 'id' => 1, +// 'title' => 'Lorem', +// 'body' => 'Ipsum' +// ]); +// } +// public function testPostWarehouse() +// { +// $response = $this->json('POST', '/api/warehouse', [ +// +// 'address'=> '2d', +// 'city'=>'cj ', +// 'zip'=>' 123', +// 'state' =>' sl', +// 'contact_person' =>'asif ', +// 'contact_person_no' =>'1212122 ', +// 'branch'=>'yap ', +// 'country' =>' ba', +// 'company_id' =>'1212 ' +// +// +// +// +// +// +// ]); +// +// $response +// ->assertStatus(201); +//// ->assertJson([ +//// 'created' => true, +// // ] +// //); +// } + + public function testPutWarehouse() + { + $response = $this->json('PUT', '/api/warehouse/6', [ + + 'address'=> '2g', + 'city'=>'cj ', + 'zip'=>' 123', + 'state' =>' sl', + 'contact_person' =>'tuytguy', + 'contact_person_no' =>'1212122 ', + 'branch'=>'yap ', + 'country' =>' ba', + 'company_id' =>'1212 ' + + + + + + + ]); + + $response + ->assertStatus(200); +// ->assertJson([ +// +// ] +// ); + } }