diff --git a/app/Http/Controllers/DeliveryInfoController.php b/app/Http/Controllers/DeliveryInfoController.php index eb3a856..f99f4ef 100644 --- a/app/Http/Controllers/DeliveryInfoController.php +++ b/app/Http/Controllers/DeliveryInfoController.php @@ -4,6 +4,8 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Deliveryinfo; +use App\User; +use App\Company; use Auth; class DeliveryinfoController extends Controller @@ -11,6 +13,11 @@ class DeliveryinfoController extends Controller public function index() { $deliveryinfo = Deliveryinfo::where('com_id', Auth::user()->company())->get(); + + if (!$deliveryinfo) + { + return response()->json(['message'=>'Access Denied!'], 404); + } return response()->json($deliveryinfo, 200); } @@ -23,7 +30,18 @@ class DeliveryinfoController extends Controller */ public function show(Deliveryinfo $id) { - $deliveryinfo = Deliveryinfo::where('com_id', Auth::user()->company())->where('id', $id)->firstOrFail(); + $deliveryinfo = Deliveryinfo::where('com_id', Auth::user()->company())->where('id', $id)->first(); + + if (!$deliveryinfo) + { + return response()->json(['message'=>'Access Denied!'], 404); + } + + $deliveryinfos = DB::table('deliveryinfos') + ->select('id', 'branch', 'deli_info', 'address', 'city', 'postcode', 'state', 'country', 'contact_person', 'contact_person_no', 'com_id') + ->where('com_id', Auth::user()->company()) + ->get(); + return response()->json($deliveryinfo, 200); } diff --git a/app/Http/Controllers/WarehouseController.php b/app/Http/Controllers/WarehouseController.php index 7771771..2cfd5db 100644 --- a/app/Http/Controllers/WarehouseController.php +++ b/app/Http/Controllers/WarehouseController.php @@ -23,7 +23,7 @@ class WarehouseController extends Controller return response()->json(['message'=>'Access Denied!'], 404); } - $warehouse = Warehouse::all(); + //$warehouse = Warehouse::all(); return response()->json($warehouses, 200); @@ -64,14 +64,14 @@ class WarehouseController extends Controller $user = Auth::user(); $warehouse = new Warehouse; - $warehouse->address=$request->input('address'); - $warehouse->city=$request->input('city'); - $warehouse->zip=$request->input('zip'); - $warehouse->state=$request->input('state'); - $warehouse->contact_person=$request->input('contact_person'); - $warehouse->contact_person_no=$request->input('contact_person_no'); - $warehouse->branch=$request->input('branch'); - $warehouse->country=$request->input('country'); + $warehouse->address = $request->input('address'); + $warehouse->city = $request->input('city'); + $warehouse->zip = $request->input('zip'); + $warehouse->state = $request->input('state'); + $warehouse->contact_person = $request->input('contact_person'); + $warehouse->contact_person_no = $request->input('contact_person_no'); + $warehouse->branch = $request->input('branch'); + $warehouse->country = $request->input('country'); $warehouse->com_id = $user->company(); $warehouse->save(); @@ -96,14 +96,14 @@ class WarehouseController extends Controller return response()->json(['message'=>'Access Denied!'], 404); } - $warehouse->address=$request->input('address'); - $warehouse->city=$request->input('city'); - $warehouse->zip=$request->input('zip'); - $warehouse->state=$request->input('state'); - $warehouse->contact_person=$request->input('contact_person'); - $warehouse->contact_person_no=$request->input('contact_person_no'); - $warehouse->branch=$request->input('branch'); - $warehouse->country=$request->input('country'); + $warehouse->address = $request->input('address'); + $warehouse->city = $request->input('city'); + $warehouse->zip = $request->input('zip'); + $warehouse->state = $request->input('state'); + $warehouse->contact_person = $request->input('contact_person'); + $warehouse->contact_person_no = $request->input('contact_person_no'); + $warehouse->branch = $request->input('branch'); + $warehouse->country = $request->input('country'); $warehouse->com_id = $user->company(); $warehouse->save(); diff --git a/app/Warehouse.php b/app/Warehouse.php index 1bfd5f8..8649c3c 100644 --- a/app/Warehouse.php +++ b/app/Warehouse.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; class Warehouse extends Model { - protected $fillable = ['city', 'address','zip','state','contact_person','contact_person_no','branch','country','comp_id']; + protected $fillable = ['city', 'address','zip','state','contact_person','contact_person_no','branch','country','com_id']; public function contact(){ diff --git a/routes/api.php b/routes/api.php index 2ef96aa..63958b9 100644 --- a/routes/api.php +++ b/routes/api.php @@ -56,7 +56,7 @@ Route::group(['middleware' => ['jwt.auth']], function() { }); /*Delivery-Info in profile menu*/ - Route::get('/deliveryinfo','DeliveryinfoController@index'); + Route::get('/deliveryinfo/{com_id}','DeliveryinfoController@index'); Route::get('/deliveryinfo/{com_id}','DeliveryinfoController@show'); Route::post('/deliveryinfo', 'DeliveryinfoController@store'); Route::put('/deliveryinfo/{com_id}', 'DeliveryinfoController@update'); diff --git a/tests/Unit/DeliveryinfoTest.php b/tests/Unit/DeliveryinfoTest.php index f23bb1b..22edcfd 100644 --- a/tests/Unit/DeliveryinfoTest.php +++ b/tests/Unit/DeliveryinfoTest.php @@ -20,6 +20,7 @@ class DeliveryinfoTest extends TestCase { parent::setUp(); Artisan::call('db:seed'); + $this->user = factory(User::class)->create(); $this->company = $this->user->each(function ($u) { factory(Company::class)->create([ @@ -28,57 +29,58 @@ class DeliveryinfoTest extends TestCase }); } - // TODO : those test is wrong, please redo later. + // TODO : those test is wrong, please redo later. + // REDO the test - // public function testCreate() - // { + public function testPost() + { - // $response = $this->actingAs($this->company) - // ->patchJson('/api/deliveryinfo', [ + $response = $this->actingAs($this->user) + ->postJson('/api/deliveryinfo', [ - // 'branch' => 'Test', - // 'deli_info' => 'Testing', - // 'address' => 'Testing', - // 'city' => 'Test', - // 'postcode' => '12345', - // 'state' => 'Testing', - // 'country' => 'Testing', - // 'contact_person' => 'Testing', - // 'contact_person_no' => '12345' - - // ]); + 'branch' => 'Testing', + 'deli_info' => 'Testing', + 'address' => 'Testing', + 'city' => 'Testing', + 'postcode' => '12345', + 'state' => 'Testing', + 'country' => 'Testing', + 'contact_person' => 'Testing', + 'contact_person_no' => '12345' + + ]); - // $response->assertStatus(201); - // } + $response->assertStatus(201); + } - // public function testPUT() - // { + public function testPut() + { - // $response = $this->actingAs($this->company) - // ->patchJson('/api/deliveryinfo', [ + $response = $this->actingAs($this->user) + ->patchJson('/api/deliveryinfo', [ - // 'branch' => 'Test', - // 'deli_info' => 'Testing', - // 'address' => 'Testing', - // 'city' => 'Test', - // 'postcode' => '12345', - // 'state' => 'Testing', - // 'country' => 'Testing', - // 'contact_person' => 'Testing', - // 'contact_person_no' => '12345' + 'branch' => 'ChangedTesting', + 'deli_info' => 'Testing', + 'address' => 'Testing', + 'city' => 'Testing', + 'postcode' => '12345', + 'state' => 'Testing', + 'country' => 'Testing', + 'contact_person' => 'Testing', + 'contact_person_no' => '12345' - // ]); + ]); - // $response->assertStatus(200); - // } + $response->assertStatus(200); + } - // public function testDELETE() - // { - // $response = $this->json('DELETE', '/api/deliveryinfo'); + public function testDELETE() + { + $response = $this->json('DELETE', '/api/deliveryinfo'); - // $response->assertStatus(204); - // } + $response->assertStatus(204); + } }