From 4e0eb3528d03b015795c0dc2a2a5c9b5b9f6b5ab Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Tue, 26 Jun 2018 16:31:13 +0800 Subject: [PATCH 01/12] fixed warehouses FK relation error --- ...28_add_foreign_key_to_warehouses_table.php | 1 + ...2438_drop_com__id_for_warehouses_table.php | 35 +++++++++++++++++ ...ange_reference_id_for_warehouses_table.php | 38 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 database/migrations/2018_06_26_082438_drop_com__id_for_warehouses_table.php create mode 100644 database/migrations/2018_06_26_083014_change_reference_id_for_warehouses_table.php diff --git a/database/migrations/2018_06_22_072528_add_foreign_key_to_warehouses_table.php b/database/migrations/2018_06_22_072528_add_foreign_key_to_warehouses_table.php index 696304e..5be85d8 100644 --- a/database/migrations/2018_06_22_072528_add_foreign_key_to_warehouses_table.php +++ b/database/migrations/2018_06_22_072528_add_foreign_key_to_warehouses_table.php @@ -21,6 +21,7 @@ class AddForeignKeyToWarehousesTable extends Migration ->onDelete('cascade'); }); + } /** diff --git a/database/migrations/2018_06_26_082438_drop_com__id_for_warehouses_table.php b/database/migrations/2018_06_26_082438_drop_com__id_for_warehouses_table.php new file mode 100644 index 0000000..b727c9f --- /dev/null +++ b/database/migrations/2018_06_26_082438_drop_com__id_for_warehouses_table.php @@ -0,0 +1,35 @@ +dropForeign(['com_id']); + $table->dropColumn('com_id'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('warehouses', function (Blueprint $table) { + // + }); + } +} diff --git a/database/migrations/2018_06_26_083014_change_reference_id_for_warehouses_table.php b/database/migrations/2018_06_26_083014_change_reference_id_for_warehouses_table.php new file mode 100644 index 0000000..7fe766b --- /dev/null +++ b/database/migrations/2018_06_26_083014_change_reference_id_for_warehouses_table.php @@ -0,0 +1,38 @@ +unsignedInteger('com_id');//FK wrn id + $table->foreign('com_id') + ->references('id')->on('companies') + ->onDelete('cascade'); + + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('warehouses', function (Blueprint $table) { + // + }); + } +} From 70cc220337ba4f225560a77c546797abcafe134e Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Fri, 29 Jun 2018 11:04:37 +0800 Subject: [PATCH 02/12] rename test --- app/Http/Controllers/DeliveryInfoController.php | 5 ----- app/Warehouse.php | 5 ----- tests/Unit/DeliveryinfoTest.php | 3 +-- tests/{warehouseTest.php => Unit/WarehouseTest.php} | 2 +- tests/Unit/contactTest.php | 2 +- 5 files changed, 3 insertions(+), 14 deletions(-) rename tests/{warehouseTest.php => Unit/WarehouseTest.php} (98%) diff --git a/app/Http/Controllers/DeliveryInfoController.php b/app/Http/Controllers/DeliveryInfoController.php index f99f4ef..f68ea4c 100644 --- a/app/Http/Controllers/DeliveryInfoController.php +++ b/app/Http/Controllers/DeliveryInfoController.php @@ -32,11 +32,6 @@ class DeliveryinfoController extends Controller { $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()) diff --git a/app/Warehouse.php b/app/Warehouse.php index 8649c3c..a85af99 100644 --- a/app/Warehouse.php +++ b/app/Warehouse.php @@ -8,9 +8,4 @@ class Warehouse extends Model { protected $fillable = ['city', 'address','zip','state','contact_person','contact_person_no','branch','country','com_id']; - public function contact(){ - - return $this->hasMany(App/Contact); - - } } diff --git a/tests/Unit/DeliveryinfoTest.php b/tests/Unit/DeliveryinfoTest.php index 22edcfd..7bfa688 100644 --- a/tests/Unit/DeliveryinfoTest.php +++ b/tests/Unit/DeliveryinfoTest.php @@ -81,6 +81,5 @@ class DeliveryinfoTest extends TestCase $response->assertStatus(204); } - - + } diff --git a/tests/warehouseTest.php b/tests/Unit/WarehouseTest.php similarity index 98% rename from tests/warehouseTest.php rename to tests/Unit/WarehouseTest.php index f6f683d..1001257 100644 --- a/tests/warehouseTest.php +++ b/tests/Unit/WarehouseTest.php @@ -1,6 +1,6 @@ Date: Fri, 29 Jun 2018 14:55:55 +0800 Subject: [PATCH 03/12] remove duplicate line of code --- app/Http/Controllers/DeliveryInfoController.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/Http/Controllers/DeliveryInfoController.php b/app/Http/Controllers/DeliveryInfoController.php index f68ea4c..7f42f8a 100644 --- a/app/Http/Controllers/DeliveryInfoController.php +++ b/app/Http/Controllers/DeliveryInfoController.php @@ -32,11 +32,6 @@ class DeliveryinfoController extends Controller { $deliveryinfo = Deliveryinfo::where('com_id', Auth::user()->company())->where('id', $id)->first(); - $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); } From 26b5c0c9e51db719972f6f78b02d37885c67de06 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Mon, 2 Jul 2018 10:30:53 +0800 Subject: [PATCH 04/12] added dockerfile --- database/seeds/WarehouseSeeder.php | 16 ++++++++++++++++ docker/mysql/Dockerfile | 29 ++++++++++------------------- 2 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 database/seeds/WarehouseSeeder.php diff --git a/database/seeds/WarehouseSeeder.php b/database/seeds/WarehouseSeeder.php new file mode 100644 index 0000000..49cade1 --- /dev/null +++ b/database/seeds/WarehouseSeeder.php @@ -0,0 +1,16 @@ +" - -##################################### -# Set Timezone -##################################### - -ARG TZ=UTC -ENV TZ ${TZ} -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -RUN chown -R mysql:root /var/lib/mysql/ - -COPY my.cnf /etc/mysql/conf.d/my.cnf - -CMD ["mysqld"] - -EXPOSE 3306 From 020c3ce3b71a05659b759a062e9e70e72ecd9aec Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Mon, 2 Jul 2018 10:45:20 +0800 Subject: [PATCH 05/12] rollback dockerfile --- docker/mysql/Dockerfile | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/docker/mysql/Dockerfile b/docker/mysql/Dockerfile index c969a5c..a3de886 100644 --- a/docker/mysql/Dockerfile +++ b/docker/mysql/Dockerfile @@ -1,11 +1,20 @@ -FROM php:7 -RUN apt-get update -y && apt-get install -y openssl zip unzip git netcat libpng-dev -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer -RUN docker-php-ext-install pdo pdo_mysql -RUN docker-php-ext-install gd -WORKDIR /app -COPY . /app -RUN composer update -ADD start.sh /start.sh -CMD ["/start.sh"] +ARG MYSQL_VERSION=latest +FROM mysql:${MYSQL_VERSION} +LABEL maintainer="Mahmoud Zalt " + +##################################### +# Set Timezone +##################################### + +ARG TZ=UTC +ENV TZ ${TZ} +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN chown -R mysql:root /var/lib/mysql/ + +COPY my.cnf /etc/mysql/conf.d/my.cnf + +CMD ["mysqld"] + +EXPOSE 3306 From 426861e807dca9ccd7766d1c471ff3e64d86b4a8 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Mon, 2 Jul 2018 10:48:28 +0800 Subject: [PATCH 06/12] added seeder --- database/seeds/ContactSeeder.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 database/seeds/ContactSeeder.php diff --git a/database/seeds/ContactSeeder.php b/database/seeds/ContactSeeder.php new file mode 100644 index 0000000..f6bfc4a --- /dev/null +++ b/database/seeds/ContactSeeder.php @@ -0,0 +1,16 @@ + Date: Mon, 2 Jul 2018 11:15:02 +0800 Subject: [PATCH 07/12] replaced dockerfile --- docker/mysql/Dockerfile | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/docker/mysql/Dockerfile b/docker/mysql/Dockerfile index a3de886..c969a5c 100644 --- a/docker/mysql/Dockerfile +++ b/docker/mysql/Dockerfile @@ -1,20 +1,11 @@ -ARG MYSQL_VERSION=latest -FROM mysql:${MYSQL_VERSION} +FROM php:7 +RUN apt-get update -y && apt-get install -y openssl zip unzip git netcat libpng-dev +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN docker-php-ext-install pdo pdo_mysql +RUN docker-php-ext-install gd +WORKDIR /app +COPY . /app +RUN composer update +ADD start.sh /start.sh +CMD ["/start.sh"] -LABEL maintainer="Mahmoud Zalt " - -##################################### -# Set Timezone -##################################### - -ARG TZ=UTC -ENV TZ ${TZ} -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - -RUN chown -R mysql:root /var/lib/mysql/ - -COPY my.cnf /etc/mysql/conf.d/my.cnf - -CMD ["mysqld"] - -EXPOSE 3306 From 8eebdcd093e07bc35f5f17dc59b3c53da9704d83 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Mon, 2 Jul 2018 15:24:32 +0800 Subject: [PATCH 08/12] added company, warehouse, contact seeder --- app/Company.php | 19 ++++++++++++++++++- app/DeliveryInfo.php | 12 ++++++------ app/Warehouse.php | 20 +++++++++++++++++++- database/seeds/CompanySeeder.php | 6 ++++-- database/seeds/ContactSeeder.php | 12 +++++++++++- database/seeds/DatabaseSeeder.php | 4 +++- database/seeds/DeliveryInfoSeeder.php | 14 +++++++------- database/seeds/WarehouseSeeder.php | 18 +++++++++++++++++- 8 files changed, 85 insertions(+), 20 deletions(-) diff --git a/app/Company.php b/app/Company.php index 99937c0..3ec8433 100644 --- a/app/Company.php +++ b/app/Company.php @@ -7,8 +7,25 @@ use Illuminate\Database\Eloquent\Model; class Company extends Model { - protected $fillable = ['user_id', 'company_profile', 'reg_cert', 'company_name', 'registration_no', 'tax_no', 'tel_no', 'fax', 'address', 'city', 'postcode', 'state', 'country', 'contact_person']; + protected $fillable = [ + + 'company_profile', + 'reg_cert', + 'company_name', + 'registration_no', + 'tax_no', + 'tel_no', + 'fax', + 'address', + 'city', + 'postcode', + 'state', + 'country', + 'contact_person', + 'user_id', + ]; + public function user() { return $this->belongsTo('App\User'); diff --git a/app/DeliveryInfo.php b/app/DeliveryInfo.php index 8aeacae..b5ef49c 100644 --- a/app/DeliveryInfo.php +++ b/app/DeliveryInfo.php @@ -6,8 +6,8 @@ use Illuminate\Database\Eloquent\Model; class Deliveryinfo extends Model { - protected $fillable = [ - 'id', + protected $fillable = [ + 'branch', 'deli_info', 'address', @@ -20,10 +20,10 @@ class Deliveryinfo extends Model 'com_id' ]; - public function company() { + public function company(){ - return $this->belongsTo('App\Company'); - - } + return $this->belongsTo(App/Company); + + } } diff --git a/app/Warehouse.php b/app/Warehouse.php index a85af99..0609d99 100644 --- a/app/Warehouse.php +++ b/app/Warehouse.php @@ -6,6 +6,24 @@ use Illuminate\Database\Eloquent\Model; class Warehouse extends Model { - protected $fillable = ['city', 'address','zip','state','contact_person','contact_person_no','branch','country','com_id']; + protected $fillable = [ + + 'address', + 'city', + 'zip', + 'state', + 'contact_person', + 'contact_person_no', + 'branch', + 'country', + 'com_id' + + ]; + + public function company(){ + + return $this->belongsTo(App/Company); + + } } diff --git a/database/seeds/CompanySeeder.php b/database/seeds/CompanySeeder.php index b35e062..c4f6c9b 100644 --- a/database/seeds/CompanySeeder.php +++ b/database/seeds/CompanySeeder.php @@ -15,9 +15,11 @@ class CompanySeeder extends Seeder DB::table('companies')->insert([ 'id' => '999', + 'company_profile'=>'testing', + 'reg_cert'=>'12345', 'company_name'=>'testing', - 'registration_no'=>'testing', - 'tax_no'=>'testing', + 'registration_no'=>'12345', + 'tax_no'=>'12345', 'tel_no'=>'12345', 'fax'=>'12345', 'address'=>'testing', diff --git a/database/seeds/ContactSeeder.php b/database/seeds/ContactSeeder.php index f6bfc4a..98e6293 100644 --- a/database/seeds/ContactSeeder.php +++ b/database/seeds/ContactSeeder.php @@ -1,6 +1,7 @@ insert([ + + 'id' => '999', + 'user_id' => '2', + 'com_id' => '999', + 'status' => '1', + 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), + 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), + + ]); } } diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 109c2bc..df697fa 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -13,7 +13,9 @@ class DatabaseSeeder extends Seeder { $this->call(LaratrustSeeder::class); $this->call(UsersTableSeeder::class); - $this->call(DeliveryInfoSeeder::class); $this->call(CompanySeeder::class); + $this->call(DeliveryInfoSeeder::class); + $this->call(WarehouseSeeder::class); + $this->call(ContactSeeder::class); } } diff --git a/database/seeds/DeliveryInfoSeeder.php b/database/seeds/DeliveryInfoSeeder.php index 88638fb..d8f8448 100644 --- a/database/seeds/DeliveryInfoSeeder.php +++ b/database/seeds/DeliveryInfoSeeder.php @@ -15,14 +15,14 @@ class DeliveryInfoSeeder extends Seeder DB::table('deliveryinfos')->insert([ 'id' => '999', - 'branch' => 'Testing', - 'deli_info' => 'Testing', - 'address' => 'Testing', - 'city' => 'Test', + 'branch' => 'testing', + 'deli_info' => 'testing', + 'address' => 'testing', + 'city' => 'testing', 'postcode' => '12345', - 'state' => 'Testing', - 'country' => 'Testing', - 'contact_person' => 'Testing', + 'state' => 'testing', + 'country' => 'testing', + 'contact_person' => 'testing', 'contact_person_no' => '12345', 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), diff --git a/database/seeds/WarehouseSeeder.php b/database/seeds/WarehouseSeeder.php index 49cade1..a2a5f92 100644 --- a/database/seeds/WarehouseSeeder.php +++ b/database/seeds/WarehouseSeeder.php @@ -1,6 +1,7 @@ insert([ + + 'id' => '999', + 'address'=>'testing', + 'city'=>'testing', + 'zip'=>'12345', + 'state'=>'testing', + 'contact_person'=>'testing', + 'contact_person_no'=>'12345', + 'branch'=>'testing', + 'country'=>'testing', + 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), + 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), + 'com_id' => '999' + + ]); } } From 7a7e8fdcfef3fcd78274f97e86aca15abe761157 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Mon, 2 Jul 2018 15:27:26 +0800 Subject: [PATCH 09/12] remove warehouse factory file --- database/factories/WarehouseFactory.php | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 database/factories/WarehouseFactory.php diff --git a/database/factories/WarehouseFactory.php b/database/factories/WarehouseFactory.php deleted file mode 100644 index b5bc778..0000000 --- a/database/factories/WarehouseFactory.php +++ /dev/null @@ -1,9 +0,0 @@ -define(App\Warehouse::class, function (Faker $faker) { - return [ - // - ]; -}); From 03d84570fa612a08e33a8dc44b830ab07ba6fbdb Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Mon, 2 Jul 2018 16:50:18 +0800 Subject: [PATCH 10/12] redo contact test, added contact factory --- database/factories/ContactFactory.php | 11 +++++ tests/Unit/contactTest.php | 69 ++++++++++++++------------- 2 files changed, 48 insertions(+), 32 deletions(-) create mode 100644 database/factories/ContactFactory.php diff --git a/database/factories/ContactFactory.php b/database/factories/ContactFactory.php new file mode 100644 index 0000000..52a211b --- /dev/null +++ b/database/factories/ContactFactory.php @@ -0,0 +1,11 @@ +define(App\Contact::class, function (Faker $faker) { + return [ + 'user_id' => '1', + 'com_id' => '1', + 'status' => '1', + ]; +}); diff --git a/tests/Unit/contactTest.php b/tests/Unit/contactTest.php index 44ded98..1402530 100644 --- a/tests/Unit/contactTest.php +++ b/tests/Unit/contactTest.php @@ -1,52 +1,57 @@ json('GET', '/api/company/search/cief'); - - $response - ->assertStatus(200); - - } - - public function testStoreId() + public function setUp() { - $response = $this->json('POST', '/api/contacts', ['company_id' => '1'], $this->headers()); - $response - ->assertStatus(201); + parent::setUp(); + Artisan::call('db:seed'); + + $this->user = factory(User::class)->create(); + $this->company = $this->user->each(function ($u) { + factory(Company::class)->create([ + 'user_id' => $u->id, + ]); + }); + } + + public function testPost() + { + $response = $this->actingAs($this->user) + ->postJson('/api/contact', [ + + 'com_id' => '1', + ]); + + $response->assertStatus(200); } -// public function testDeleteContacts() -// { -// -// $response = $this->json('DELETE', '/api/contacts/1'); -// -// $response -// ->assertStatus(204); -// -// } + public function testApproved() + { + $response = $this->actingAs($this->user) + ->postJson('/api/contact/1/', [ + 'user_id' => '1', + 'com_id' => '1', + 'status' => '1', + ]); + $response->assertStatus(200); + } - public function testApprove() - { - $response = $this->json('POST', '/api/contacts/1/request', ['action' => 1]); - $response - ->assertStatus(200); - - } } From 87478d1572b5e44bfdf032e4f0c93d5f536fb5d6 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Fri, 6 Jul 2018 10:01:17 +0800 Subject: [PATCH 11/12] return error with json --- app/Http/Controllers/CompanyController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 6678458..5154eda 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -28,7 +28,9 @@ class CompanyController extends Controller return response($output); } - else{return "error";} + else + + return response()->json(['success'=> false, 'error'=>'Company not found'], 404); } public function update(Request $request) From 47b6b70744e7e0b897a3e25e1c10f8d776865884 Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Fri, 6 Jul 2018 10:08:28 +0800 Subject: [PATCH 12/12] remove success --- app/Http/Controllers/CompanyController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 5154eda..adc925f 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -28,9 +28,11 @@ class CompanyController extends Controller return response($output); } + else - - return response()->json(['success'=> false, 'error'=>'Company not found'], 404); + { + return response()->json(['error'=>'Company not found'], 404); + } } public function update(Request $request)