diff --git a/app/Http/Controllers/ContactController.php b/app/Http/Controllers/ContactController.php index 72b44a0..ed003d6 100644 --- a/app/Http/Controllers/ContactController.php +++ b/app/Http/Controllers/ContactController.php @@ -125,4 +125,39 @@ class ContactController extends Controller return response()->json($contact, 204); } + + public function postApprove(Request $request, $id) + { + $contact = Contact::where('id', '=', e($id))->first(); + if($contact) + { + + $action=$request->input('action'); + if ($action==1) + { + $contact->status=1; + } + if ($action==0) + { + $contact->status=0; + } + else{ + return response()->json(["message" => "not allowed"], 400); + } + + $saved = $contact->save(); + if ($saved){ + return response()->json($contact, 201); + } + return response()->json($contact, 400); + +// $contact = $request->input('id'); +// $contact->status = 1; +// $contact->save(); + //return redirect()->back()->with('info','Request has been approved '); + + } + + + } } diff --git a/routes/api.php b/routes/api.php index b716fa9..ced2843 100644 --- a/routes/api.php +++ b/routes/api.php @@ -76,3 +76,5 @@ Route::get('/company/search/{company_name}', 'CompanyController@search'); // return $company; // }); +Route::post('/contacts/{contacts_id}/request', 'ContactController@postApprove'); +//Route::post('contacts/reject/{user_id}', 'ContactController@postReject'); \ No newline at end of file diff --git a/tests/Unit/contactTest.php b/tests/Unit/contactTest.php index 35ef645..b34fe47 100644 --- a/tests/Unit/contactTest.php +++ b/tests/Unit/contactTest.php @@ -28,4 +28,25 @@ class contactTest extends TestCase ->assertStatus(201); } + +// public function testDeleteContacts() +// { +// +// $response = $this->json('DELETE', '/api/contacts/1'); +// +// $response +// ->assertStatus(204); +// +// } + + + + public function testApprove() + { + $response = $this->json('POST', '/api/contacts/1/request', ['action' => 1]); + $response + ->assertStatus(200); + + } + }