Merge branch 'asif/contact' of gitlab.com:CIEFWorldwideSdnBhd/izyim-api into asif/contact

This commit is contained in:
Aqeeb Imtiaz Harun
2018-07-07 17:24:36 +08:00
19 changed files with 253 additions and 96 deletions
+19 -2
View File
@@ -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');
+6 -6
View File
@@ -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);
}
}
+5 -1
View File
@@ -27,7 +27,11 @@ class CompanyController extends Controller
return response($output);
}
else{return "error";}
else
{
return response()->json(['error'=>'Company not found'], 404);
}
}
public function update(Request $request)
@@ -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);
}
+16 -3
View File
@@ -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);
}
}
+11
View File
@@ -0,0 +1,11 @@
<?php
use Faker\Generator as Faker;
$factory->define(App\Contact::class, function (Faker $faker) {
return [
'user_id' => '1',
'com_id' => '1',
'status' => '1',
];
});
-9
View File
@@ -1,9 +0,0 @@
<?php
use Faker\Generator as Faker;
$factory->define(App\Warehouse::class, function (Faker $faker) {
return [
//
];
});
@@ -20,6 +20,7 @@ class AddForeignKeyToWarehousesTable extends Migration
->references('id')->on('warehouses')
->onDelete('cascade');
});
}
/**
@@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DropComIdForWarehousesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('warehouses', function (Blueprint $table) {
$table->dropForeign(['com_id']);
$table->dropColumn('com_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('warehouses', function (Blueprint $table) {
//
});
}
}
@@ -0,0 +1,38 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ChangeReferenceIdForWarehousesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('warehouses', function (Blueprint $table) {
$table->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) {
//
});
}
}
+4 -2
View File
@@ -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',
+26
View File
@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Seeder;
use Carbon\Carbon;
class ContactSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('contacts')->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'),
]);
}
}
+3 -1
View File
@@ -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);
}
}
+7 -7
View File
@@ -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'),
+32
View File
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Seeder;
use Carbon\Carbon;
class WarehouseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('warehouses')->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'
]);
}
}
+10 -19
View File
@@ -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 <mahmoud@zalt.me>"
#####################################
# 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
+1 -2
View File
@@ -81,6 +81,5 @@ class DeliveryinfoTest extends TestCase
$response->assertStatus(204);
}
}
@@ -1,6 +1,6 @@
<?php
namespace Tests\API;
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
+38 -33
View File
@@ -1,52 +1,57 @@
<?php
namespace Tests\Unit\contactTest;
namespace Tests\API;
namespace Tests\Unit\ContactTest;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Artisan;
use App\User;
use App\Company;
class contactTest extends TestCase
class ContactTest extends TestCase
{
protected $company;
protected $user;
public function testGet()
{
$response = $this->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);
}
}