Merge branch 'Aqeeb/company' into 'master'

Aqeeb/company

See merge request CIEFWorldwideSdnBhd/izyim-api!5
This commit is contained in:
Jack Goh
2018-05-26 01:27:32 +00:00
15 changed files with 526 additions and 17 deletions
+12
View File
@@ -0,0 +1,12 @@
<?php
namespace App;
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'];
//protected $guarded = [];
}
+112
View File
@@ -0,0 +1,112 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Company;
use Illuminate\Support\Facades\Storage;
use Validator;
class CompanyController extends Controller
{
public function store(Request $request)
{
$input = $request->all();
Company::create($input);
return response()->json(['input'=>$input],201);
//return redirect('/');
}
public function update(Request $request, $id)
{
$company = Company::find($id);
if (!$company)
{
return response()->json(['message'=>'company not found'],200);
}
$company->company_name=$request->input('company_name');
$company->registration_no=$request->input('registration_no');
$company->tax_no=$request->input('tax_no');
$company->tel_no=$request->input('tel_no');
$company->fax=$request->input('fax');
$company->address=$request->input('address');
$company->city=$request->input('city');
$company->postcode=$request->input('postcode');
$company->state=$request->input('state');
$company->country=$request->input('country');
$company->contact_person=$request->input('contact_person');
$company->save();
return response()->json(['company'=>$company],200);
}
public function companyProfile(Request $request, $id)
{
$company = Company::find($id);//find the company first
if (!$company)
{
return response()->json(['message'=>'company for company_prof not found'],200);
}
//validaating file types
$validator = Validator::make($request->all(), [
'company_profile' => 'image|mimes:jpg,jpeg,bmp,png'
]);
if($validator->fails())
{
return response()->json(['message'=>'Incorrect format'],200);
}
if($file = $request->file('company_profile')) //company profile picture
{
$company_profile = $request->file('company_profile');
$filename = $company_profile->getClientOriginalName(); //get the original file name
$unique_name = 'comp_prof_' . md5($filename. time()); //generating a random file name
$file = $request->file('company_profile');
$ext = $file->getClientOriginalExtension();
$input['company_profile'] = $filename;
Storage::putFileAs(
'company_profile',/*folder name*/ $file, $unique_name. '.' .$ext
);
$company->company_profile = $unique_name. '.' .$ext; //update database
} //end if
$company->save();
return response()->json(['company'=>$company],200);
}//end of companyProfile()
public function regCert(Request $request, $id)
{
$company = Company::find($id); //find the company first
if (!$company)
{
return response()->json(['message'=>'company for reg_cert not found'],200);
}
//validating file types
$validator = Validator::make($request->all(), [
'reg_cert' => 'mimes:jpg,jpeg,bmp,png,gif,svg,pdf'
]);
if($validator->fails()){
return response()->json(['message'=>'Incorrect format'],200);
}
if($request->hasFile('reg_cert')) //Registration Certificate upload
{
$reg_cert = $request->file('reg_cert');
$filename = $reg_cert->getClientOriginalName(); //original filename
$unique_name = 'reg_cert_' . md5($filename. time()); //generating a random file name
$file = $request->file('reg_cert');
$ext = $file->getClientOriginalExtension();
$input['reg_cert'] = $filename;
Storage::putFileAs(
'reg_cert',/*folder name*/ $file, $unique_name. '.' .$ext
);
$company->reg_cert = $unique_name. '.' .$ext; //this updates database
}//end if
$company->save();
return response()->json(['company'=>$company],200);
}//end regCert()
}//end of class
+1
View File
@@ -9,6 +9,7 @@
"aloha/twilio": "^4.0",
"doctrine/dbal": "~2.3",
"fideloper/proxy": "^4.0",
"intervention/image": "^2.4",
"laravel/framework": "5.6.*",
"laravel/tinker": "^1.0",
"santigarcor/laratrust": "5.0.*",
Generated
+185
View File
@@ -787,6 +787,141 @@
],
"time": "2018-02-07T20:20:57+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "1.4.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Schultze",
"homepage": "https://github.com/Tobion"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"request",
"response",
"stream",
"uri",
"url"
],
"time": "2017-03-20T17:10:46+00:00"
},
{
"name": "intervention/image",
"version": "2.4.1",
"source": {
"type": "git",
"url": "https://github.com/Intervention/image.git",
"reference": "3603dbcc9a17d307533473246a6c58c31cf17919"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Intervention/image/zipball/3603dbcc9a17d307533473246a6c58c31cf17919",
"reference": "3603dbcc9a17d307533473246a6c58c31cf17919",
"shasum": ""
},
"require": {
"ext-fileinfo": "*",
"guzzlehttp/psr7": "~1.1",
"php": ">=5.4.0"
},
"require-dev": {
"mockery/mockery": "~0.9.2",
"phpunit/phpunit": "^4.8 || ^5.7"
},
"suggest": {
"ext-gd": "to use GD library based image processing.",
"ext-imagick": "to use Imagick based image processing.",
"intervention/imagecache": "Caching extension for the Intervention Image library"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
},
"laravel": {
"providers": [
"Intervention\\Image\\ImageServiceProvider"
],
"aliases": {
"Image": "Intervention\\Image\\Facades\\Image"
}
}
},
"autoload": {
"psr-4": {
"Intervention\\Image\\": "src/Intervention/Image"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Oliver Vogel",
"email": "oliver@olivervogel.com",
"homepage": "http://olivervogel.com/"
}
],
"description": "Image handling and manipulation library with support for Laravel integration",
"homepage": "http://image.intervention.io/",
"keywords": [
"gd",
"image",
"imagick",
"laravel",
"thumbnail",
"watermark"
],
"time": "2017-09-21T16:29:17+00:00"
},
{
"name": "jakub-onderka/php-console-color",
"version": "0.1",
@@ -1605,6 +1740,56 @@
],
"time": "2017-02-14T16:28:37+00:00"
},
{
"name": "psr/http-message",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"time": "2016-08-06T14:39:51+00:00"
},
{
"name": "psr/log",
"version": "1.0.2",
+2 -3
View File
@@ -1,7 +1,7 @@
<?php
return [
//'fileDestinationPath' => 'uploads',
/*
|--------------------------------------------------------------------------
| Application Name
@@ -160,8 +160,7 @@ return [
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\RouteServiceProvider::class
],
/*
+1 -1
View File
@@ -43,7 +43,7 @@ return [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'database' => env('DB_DATABASE', 'forgzze'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
@@ -0,0 +1,44 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCompaniesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('companies', function (Blueprint $table) {
$table->increments('id');
$table->string('company_profile');//->default('default.jpg'); //need to check about storage type
$table->string('reg_cert');
$table->string('company-name');
$table->string('registration-no');
$table->string('tax-no');
$table->integer('tel-no');
$table->integer('fax');
$table->string('address');
$table->string('city');
$table->string('postcode');
$table->string('state');
$table->string('country');
$table->string('contact-person');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('companies');
}
}
@@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class RenameColumnInCompany extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('companies', function (Blueprint $table) {
// $table->renameColumn('company-profile', 'company_profile');
$table->renameColumn('"company-name"', 'company_name');
$table->renameColumn('"registration-no"', 'registration_no');
$table->renameColumn('"tax-no"', 'tax_no');
$table->renameColumn('"tel-no"', 'tel_no');
$table->renameColumn('"contact-person"', 'contact_person');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
@@ -0,0 +1,45 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddNullableToCompanies extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('companies', function (Blueprint $table) {
//
$table->string('company_profile')->nullable()->change(); //need to check about storage type
$table->string('reg_cert')->nullable()->change();
$table->string('company_name')->nullable()->change();
$table->string('registration_no')->nullable()->change();
$table->string('tax_no')->nullable()->change();
$table->integer('tel_no')->nullable()->change();
$table->integer('fax')->nullable()->change();
$table->string('address')->nullable()->change();
$table->string('city')->nullable()->change();
$table->string('postcode')->nullable()->change();
$table->string('state')->nullable()->change();
$table->string('country')->nullable()->change();
$table->string('contact_person')->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('companies', function (Blueprint $table) {
//
});
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File
+9 -9
View File
@@ -1,7 +1,7 @@
<?php
use Illuminate\Http\Request;
use App\Company;
/*
|--------------------------------------------------------------------------
| API Routes
@@ -13,16 +13,10 @@ use Illuminate\Http\Request;
|
*/
//Route::middleware('auth:api')->get('/user', function (Request $request) {
// return $request->user();
//});
//Route::post('register', 'AuthController@register');
/* Authentication */
Route::post('login', 'AuthController@login');
Route::post('password/recover', 'AuthController@recover');
Route::post('password/reset', 'AuthController@reset');
Route::post('send-verification', 'AuthController@sendVerification');
Route::post('verify-phone', 'AuthController@verifyPhone');
@@ -32,4 +26,10 @@ Route::group(['middleware' => ['jwt.auth']], function() {
Route::get('test', function(Request $request){
return response()->json(['user'=> $request->user()]);
});
});
});
/* Company */
Route::post('/company', 'CompanyController@store'); //store company information
Route::put('/company/{company}', 'CompanyController@update'); //update company information
Route::post('/company/company_profile/{companyID}', 'CompanyController@companyProfile');//upload company profile picture
Route::post('/company/reg_cert/{companyID}', 'CompanyController@regCert'); //upload registration certificaate
-2
View File
@@ -16,7 +16,5 @@ Route::get('/', function () {
});
//Route::post('login', 'AuthController@login');
Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.request');
Route::post('password/reset', 'Auth\ResetPasswordController@postReset')->name('password.reset');
-2
View File
@@ -1,2 +0,0 @@
*
!.gitignore
+80
View File
@@ -0,0 +1,80 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
class CompanyTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
$this->assertTrue(true);
}
public function testPOST()
{
$response = $this->json('POST', '/api/company', [
'company_name'=>'testing',
'registration_no'=>'testing',
'tax_no'=>'testing',
'tel_no'=>'12345',
'fax'=>'12345',
'address'=>'testing',
'city'=>'testing',
'postcode'=>'testing',
'state'=>'testing',
'country'=>'testing',
'contact_person'=>'testing',
]);
$response->assertStatus(201);
}
public function testPUT()
{
$response = $this->json('PUT', '/api/company/2', [
'company_name'=>'changed testing',
'registration_no'=>'testing',
'tax_no'=>'testing',
'tel_no'=>'12345',
'fax'=>'12345',
'address'=>'testing',
'city'=>'testing',
'postcode'=>'testing',
'state'=>'testing',
'country'=>'testing',
'contact_person'=>'testing',
]);
$response->assertStatus(200);
}
public function testcompanyProfile()
{
Storage::fake('company_profile');
$response = $this->json('POST', '/api/company/company_profile/2', [
'company_profile' => UploadedFile::fake()->image('comp.jpg')
]);
dd($response->getContent());
$response->assertStatus(200);
}
public function testregCert()
{
Storage::fake('reg_cert');
$response = $this->json('POST', '/api/company/reg_cert/2', [
'reg_cert' => UploadedFile::fake()->create('document.pdf')//, $sizeInKilobytes)
]);
dd($response->getContent());
$response->assertStatus(200);
}
}