diff --git a/app/Company.php b/app/Company.php new file mode 100644 index 0000000..af4bf8d --- /dev/null +++ b/app/Company.php @@ -0,0 +1,12 @@ +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 \ No newline at end of file diff --git a/composer.json b/composer.json index ef5a016..3ec4930 100644 --- a/composer.json +++ b/composer.json @@ -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.*", diff --git a/composer.lock b/composer.lock index 7dd9775..128c013 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/config/app.php b/config/app.php index c0d5d25..9a8e5b8 100644 --- a/config/app.php +++ b/config/app.php @@ -1,7 +1,7 @@ '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 ], /* diff --git a/config/database.php b/config/database.php index cab5d06..af32da1 100644 --- a/config/database.php +++ b/config/database.php @@ -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', ''), diff --git a/database/migrations/2018_04_24_034401_create_companies_table.php b/database/migrations/2018_04_24_034401_create_companies_table.php new file mode 100644 index 0000000..2489520 --- /dev/null +++ b/database/migrations/2018_04_24_034401_create_companies_table.php @@ -0,0 +1,44 @@ +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'); + } +} diff --git a/database/migrations/2018_04_25_083636_rename_column_in_company.php b/database/migrations/2018_04_25_083636_rename_column_in_company.php new file mode 100644 index 0000000..b2f3f0d --- /dev/null +++ b/database/migrations/2018_04_25_083636_rename_column_in_company.php @@ -0,0 +1,35 @@ +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() + { + // + } +} diff --git a/database/migrations/2018_05_08_081508_add_nullable_to_companies.php b/database/migrations/2018_05_08_081508_add_nullable_to_companies.php new file mode 100644 index 0000000..28ac581 --- /dev/null +++ b/database/migrations/2018_05_08_081508_add_nullable_to_companies.php @@ -0,0 +1,45 @@ +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) { + // + }); + } +} diff --git a/public/company_profile b/public/company_profile new file mode 100644 index 0000000..470ac4c Binary files /dev/null and b/public/company_profile differ diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/routes/api.php b/routes/api.php index 3dced12..bffebdb 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,7 +1,7 @@ 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()]); }); -}); \ No newline at end of file +}); + +/* 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 \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 927d508..e3497b4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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'); - diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/storage/app/public/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php new file mode 100644 index 0000000..89f4249 --- /dev/null +++ b/tests/Unit/CompanyTest.php @@ -0,0 +1,80 @@ +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); + } +}