diff --git a/app/Company.php b/app/Company.php index 9f119af..2a1fde2 100644 --- a/app/Company.php +++ b/app/Company.php @@ -6,9 +6,26 @@ use Illuminate\Database\Eloquent\Model; class Company extends Model { + + protected $fillable = [ + + 'company_profile', + 'reg_cert', + 'company_name', + 'registration_no', + 'tax_no', + 'tel_no', + 'fax', + 'address', + 'city', + 'postcode', + 'state', + 'country', + 'contact_person', + 'user_id', - protected $fillable = ['user_id', 'company_profile', 'reg_cert', 'company_name', 'registration_no', 'tax_no', 'tel_no', 'fax', 'address', 'city', 'postcode', 'state', 'country', 'contact_person']; - + ]; + 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/Http/Controllers/DeliveryInfoController.php b/app/Http/Controllers/DeliveryInfoController.php index f99f4ef..7f42f8a 100644 --- a/app/Http/Controllers/DeliveryInfoController.php +++ b/app/Http/Controllers/DeliveryInfoController.php @@ -32,16 +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()) - ->get(); - return response()->json($deliveryinfo, 200); } diff --git a/app/Warehouse.php b/app/Warehouse.php index 8649c3c..0609d99 100644 --- a/app/Warehouse.php +++ b/app/Warehouse.php @@ -6,11 +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 = [ - public function contact(){ + 'address', + 'city', + 'zip', + 'state', + 'contact_person', + 'contact_person_no', + 'branch', + 'country', + 'com_id' - return $this->hasMany(App/Contact); + ]; + + public function company(){ + + return $this->belongsTo(App/Company); } + } 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/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 [ - // - ]; -}); 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 f005400..f616313 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 @@ -20,6 +20,7 @@ class AddForeignKeyToWarehousesTable extends Migration ->references('id')->on('warehouses') ->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) { + // + }); + } +} 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 new file mode 100644 index 0000000..98e6293 --- /dev/null +++ b/database/seeds/ContactSeeder.php @@ -0,0 +1,26 @@ +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 new file mode 100644 index 0000000..a2a5f92 --- /dev/null +++ b/database/seeds/WarehouseSeeder.php @@ -0,0 +1,32 @@ +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' + + ]); + } +} 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 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 @@ 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); - - } }