From c46b8570f12514e454efcc2bd41b930f5705ec95 Mon Sep 17 00:00:00 2001 From: hazim Date: Tue, 5 Mar 2019 15:23:11 +0800 Subject: [PATCH 1/9] create new contact recode and clean up --- .../DataTransferObjects/ContactObject.php | 98 +++++++++++++++++++ .../CannotCreateContactException.php | 17 ++++ .../Contacts/Services/CreatesContact.php | 48 +++++++++ .../Contacts/CreateContactLogic.php | 42 ++++++++ .../Contacts/CreateContactController.php | 17 ++++ routes/api.php | 4 +- 6 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 app/Classes/Modules/Contacts/DataTransferObjects/ContactObject.php create mode 100644 app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php create mode 100644 app/Classes/Modules/Contacts/Services/CreatesContact.php create mode 100644 app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php create mode 100644 app/Http/Controllers/Contacts/CreateContactController.php diff --git a/app/Classes/Modules/Contacts/DataTransferObjects/ContactObject.php b/app/Classes/Modules/Contacts/DataTransferObjects/ContactObject.php new file mode 100644 index 0000000..aba325d --- /dev/null +++ b/app/Classes/Modules/Contacts/DataTransferObjects/ContactObject.php @@ -0,0 +1,98 @@ +type = $type; + $this->referenceId = $referenceId; + $this->name = $name; + $this->designation = $designation; + $this->contact = $contact; + $this->email = $email; + } + + /** + * @return int + */ + public function getType(): int + { + return $this->type; + } + + /** + * @return int + */ + public function getReferenceId(): int + { + return $this->referenceId; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return string + */ + public function getDesignation(): string + { + return $this->designation; + } + + /** + * @return string + */ + public function getContact(): string + { + return $this->contact; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php b/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php new file mode 100644 index 0000000..90278b0 --- /dev/null +++ b/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php @@ -0,0 +1,17 @@ +repository = $repository; + } + + + public function execute(ContactObject $object){ + + try { + + + $this->repository->type = $object->getType(); + $this->repository->reference_id = $object->getReferenceId(); + $this->repository->name = $object->getName(); + $this->repository->designation = $object->getDesignation(); + $this->repository->contact = $object->getContact(); + $this->repository->email = $object->getEmail(); + + $this->repository->save(); + + return $this->repository; + + + } catch (\Exception $exception){ + throw new CannotCreateContactException($exception->getMessage()); + } + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php b/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php new file mode 100644 index 0000000..165ccb5 --- /dev/null +++ b/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php @@ -0,0 +1,42 @@ +createsContact = $createsContact; + } + + + public function execute(int $type, int $referenceId, Request $request){ + + try { + $object = new ContactObject($type, $referenceId, $request->input('name'), $request->input('designation'), $request->input('contact'), $request->input('email')); + + return $this->createsContact->execute($object); + } catch (CannotCreateContactException $exception){ + throw new InternalServerErrorException("Failed to create contact because {$exception->getMessage()}"); + } + + + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Contacts/CreateContactController.php b/app/Http/Controllers/Contacts/CreateContactController.php new file mode 100644 index 0000000..51b34cb --- /dev/null +++ b/app/Http/Controllers/Contacts/CreateContactController.php @@ -0,0 +1,17 @@ +execute(Constants::MODULE_TYPES[$type], $referenceId, $request); + } + +} \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index b549ffc..0f269d3 100644 --- a/routes/api.php +++ b/routes/api.php @@ -70,7 +70,9 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function Route::get('list/{type}/{reference}', 'ContactController@index')->name('list'); // Create new contact - Route::post('{type}/{reference}', 'ContactController@store')->name('create'); + Route::post('{type}/{reference}', 'CreateContactController@create')->name('create'); + + Route::post('update/{type}/reference/{id}', 'CreateContactController@update')->name('update'); // Update contact Route::put('{type}/{reference}/{id}', 'ContactController@store')->name('update'); From 46fe8430efd69ec5c2e0a670edd316b0a76298cb Mon Sep 17 00:00:00 2001 From: hazim Date: Thu, 7 Mar 2019 15:31:16 +0800 Subject: [PATCH 2/9] update contact recode and clean up --- .../Contacts/UpdateContact.php | 23 +++- .../DataTransferObjects/ContactObject.php | 128 ++++++++++++++++++ .../CannotCreateContactException.php | 21 +++ .../Contacts/Services/CreatesContact.php | 43 ++++++ .../Contacts/Services/ListsContact.php | 40 ++++++ .../Contacts/Services/UpdateContact.php | 44 ++++++ .../Contacts/CreateContactLogic.php | 38 ++++++ .../Contacts/ListContactLogic.php | 42 ++++++ .../Contacts/UpdateContactLogic.php | 37 +++++ .../Contacts/CreateContactController.php | 15 ++ .../Contacts/ListContactController.php | 22 +++ .../Contacts/UpdateContactController.php | 21 +++ app/Http/Resources/Contact.php | 6 +- .../views/pages/Orders/profile.blade.php | 81 +++++++++++ routes/api.php | 13 +- routes/web.php | 4 + 16 files changed, 572 insertions(+), 6 deletions(-) create mode 100644 app/Classes/Modules/Contacts/DataTransferObjects/ContactObject.php create mode 100644 app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php create mode 100644 app/Classes/Modules/Contacts/Services/CreatesContact.php create mode 100644 app/Classes/Modules/Contacts/Services/ListsContact.php create mode 100644 app/Classes/Modules/Contacts/Services/UpdateContact.php create mode 100644 app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php create mode 100644 app/Classes/Modules/ControllersLogic/Contacts/ListContactLogic.php create mode 100644 app/Classes/Modules/ControllersLogic/Contacts/UpdateContactLogic.php create mode 100644 app/Http/Controllers/Contacts/CreateContactController.php create mode 100644 app/Http/Controllers/Contacts/ListContactController.php create mode 100644 app/Http/Controllers/Contacts/UpdateContactController.php create mode 100644 resources/views/pages/Orders/profile.blade.php diff --git a/app/Classes/ControllersLogic/Contacts/UpdateContact.php b/app/Classes/ControllersLogic/Contacts/UpdateContact.php index efc2266..3dfd949 100644 --- a/app/Classes/ControllersLogic/Contacts/UpdateContact.php +++ b/app/Classes/ControllersLogic/Contacts/UpdateContact.php @@ -8,9 +8,23 @@ use Illuminate\Http\Request; class UpdateContact { + + /** @var Contact */ + private $repository; + + /** + * UpdateContact constructor. + * @param Contact $repository + */ + public function __construct(Contact $repository) + { + $this->repository = $repository; + } + + public function execute(Request $request, int $type, string $reference) { - - $contact = $request->method() === 'PUT' ? Contact::findOrFail($request->input('id')) : new Contact; + + $contact = $this->repository->findOrFail($id); $contact->type = $type; $contact->reference_id = $reference; @@ -19,6 +33,11 @@ class UpdateContact $contact->contact = $request->input('contact'); $contact->email = $request->input('email'); + + $contact = $request->method() === 'PUT' ? Contact::findOrFail($request->input('id')) : new Contact; + + + if($contact->save()){ return new ContactResource($contact); } diff --git a/app/Classes/Modules/Contacts/DataTransferObjects/ContactObject.php b/app/Classes/Modules/Contacts/DataTransferObjects/ContactObject.php new file mode 100644 index 0000000..0ff45ae --- /dev/null +++ b/app/Classes/Modules/Contacts/DataTransferObjects/ContactObject.php @@ -0,0 +1,128 @@ +name = $name; + $this->designation = $designation; + $this->email = $email; + $this->contact = $contact; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return string + */ + public function getDesignation(): string + { + return $this->designation; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @return string + */ + public function getContact(): string + { + return $this->contact; + } + + /** + * @return int|null + */ + public function getType(): ?int + { + return $this->type; + } + + /** + * @return int|null + */ + public function getReferenceId(): ?int + { + return $this->referenceId; + } + + /** + * @return int|null + */ + public function getId() + { + return $this->id; + } + + /** + * @param int|null $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * @param int|null $referenceId + */ + public function setReferenceId($referenceId) + { + $this->referenceId = $referenceId; + } + + /** + * @param int|null $id + */ + public function setId($id) + { + $this->id = $id; + } + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php b/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php new file mode 100644 index 0000000..1fbe8cf --- /dev/null +++ b/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php @@ -0,0 +1,21 @@ +repository = $repository; + } + + /** + * @param ContactObject $contact + * @param int $type + * @param int $referenceId + * @return Contact + */ + public function execute(ContactObject $contact, int $type, int $referenceId) + { + $this->repository->type = $type; + $this->repository->reference_id = $referenceId; + $this->repository->name = $contact->getName(); + $this->repository->designation = $contact->getDesignation(); + $this->repository->email = $contact->getEmail(); + $this->repository->contact = $contact->getContact(); + + $this->repository->save(); + + return $this->repository; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Contacts/Services/ListsContact.php b/app/Classes/Modules/Contacts/Services/ListsContact.php new file mode 100644 index 0000000..1b07d48 --- /dev/null +++ b/app/Classes/Modules/Contacts/Services/ListsContact.php @@ -0,0 +1,40 @@ +repository = $repository; + } + + public function execute(int $type, int $referenceId){ + + $contacts = $this->repository->where('type', $type) + ->where('reference_id', $referenceId)->get(); + + // Return collection of contacts as a resource + return ContactResource::collection($contacts); + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Contacts/Services/UpdateContact.php b/app/Classes/Modules/Contacts/Services/UpdateContact.php new file mode 100644 index 0000000..97ba8d2 --- /dev/null +++ b/app/Classes/Modules/Contacts/Services/UpdateContact.php @@ -0,0 +1,44 @@ +repository = $repository; + } + + + /** + * @param int $id + * @param ContactObject $object + * @return Contact + */ + public function execute(int $id, ContactObject $object) + { + /** @var Contact $contact */ + $contact = $this->repository->findOrFail($id); + $contact ->name = $object->getName(); + $contact ->designation = $object->getDesignation(); + $contact ->contact = $object->getContact(); + $contact ->email = $object->getEmail(); + + $contact->save(); + + return $contact; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php b/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php new file mode 100644 index 0000000..24c2c5f --- /dev/null +++ b/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php @@ -0,0 +1,38 @@ +createContact = $createContact; + } + + + public function execute(string $type, int $referenceId, Request $request) + { + try{ + + $object = new ContactObject($request->input('name'), $request->input('designation'), $request->input('contact'), $request->input('email')); + return $this->createContact->execute($object, $type, $referenceId); + + } + catch (){ + + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ControllersLogic/Contacts/ListContactLogic.php b/app/Classes/Modules/ControllersLogic/Contacts/ListContactLogic.php new file mode 100644 index 0000000..3d08c8d --- /dev/null +++ b/app/Classes/Modules/ControllersLogic/Contacts/ListContactLogic.php @@ -0,0 +1,42 @@ +listsContacts = $listsContacts; + } + + + /** + * @param $type + * @param $referenceId + * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection + */ + public function execute($type, $referenceId){ + + return $this->listsContacts->execute(Constants::MODULE_TYPES[$type], $referenceId); + + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/ControllersLogic/Contacts/UpdateContactLogic.php b/app/Classes/Modules/ControllersLogic/Contacts/UpdateContactLogic.php new file mode 100644 index 0000000..45b7e5e --- /dev/null +++ b/app/Classes/Modules/ControllersLogic/Contacts/UpdateContactLogic.php @@ -0,0 +1,37 @@ +updateContact = $updateContact; + } + + + public function execute(int $id, Request $request) + { + $object = new ContactObject($request->input('name'), $request->input('designation'), $request->input('contact'), $request->input('email')); + + return $this->updateContact->execute($id, $object); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Contacts/CreateContactController.php b/app/Http/Controllers/Contacts/CreateContactController.php new file mode 100644 index 0000000..afa06f5 --- /dev/null +++ b/app/Http/Controllers/Contacts/CreateContactController.php @@ -0,0 +1,15 @@ +execute(Constants::MODULE_TYPES[$type], $referencesId, $request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Contacts/ListContactController.php b/app/Http/Controllers/Contacts/ListContactController.php new file mode 100644 index 0000000..50281df --- /dev/null +++ b/app/Http/Controllers/Contacts/ListContactController.php @@ -0,0 +1,22 @@ +execute($type,$referenceId); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Contacts/UpdateContactController.php b/app/Http/Controllers/Contacts/UpdateContactController.php new file mode 100644 index 0000000..5456a76 --- /dev/null +++ b/app/Http/Controllers/Contacts/UpdateContactController.php @@ -0,0 +1,21 @@ +execute($id, $request); + } + +} \ No newline at end of file diff --git a/app/Http/Resources/Contact.php b/app/Http/Resources/Contact.php index 08ee0df..e22a859 100644 --- a/app/Http/Resources/Contact.php +++ b/app/Http/Resources/Contact.php @@ -14,14 +14,16 @@ class Contact extends JsonResource */ public function toArray($request) { + $comapny = \App\Models\Company::findOrFail($this->reference_id); return [ 'id' => $this->id, 'type' => $this->type, 'reference_id' => $this->reference_id, - 'name' => $this->name, + 'name' => $this->first_name.' '. $this->last_name, 'designation' => $this->designation, 'contact' => $this->contact, - 'email' => $this->email + 'email' => $this->email, + 'company' => Company::make($comapny) ]; } } diff --git a/resources/views/pages/Orders/profile.blade.php b/resources/views/pages/Orders/profile.blade.php new file mode 100644 index 0000000..0673c23 --- /dev/null +++ b/resources/views/pages/Orders/profile.blade.php @@ -0,0 +1,81 @@ +@extends('layouts.base_portal') + +@section('inner_content') +
+
+
+
+
+
+
+
+ Order #216718963296916 +
+
+
+
+ Placed on 05 Mar 2019 16:40:08 +
+
+
+
+
+
+ Status: + Complete +
+
+
+
+ Order has been delivered +
+
+
+
+
+
+
+ 05-03-2019 17:05 +
+ Your Order has successfully been delivered +
+ 05-03-2019 17:05 +
+ Your Order is out for delivery +
+ 05-03-2019 17:05 +
+ Your Order has been unpacked and being prepared for delivery +
+ 05-03-2019 17:05 +
+ Your Order has arrived at Malaysia's sorting centre +
+ 05-03-2019 17:05 +
+ Your Order has been shipped successfully +
+ 05-03-2019 17:05 +
+ Your Order is packed and is ready to ship +
+ 05-03-2019 17:05 +
+ Your Order has arrived at China's sorting centre +
+ 05-03-2019 17:04 +
+ Order has been confirmed +
+ 05-03-2019 17:02 +
+ Order created +
+
+
+
+
+
+
+
+@endsection \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index b549ffc..8b4f91c 100644 --- a/routes/api.php +++ b/routes/api.php @@ -67,10 +67,10 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function Route::group(['prefix' => 'contact', 'as' => 'contact.', 'namespace' => 'Contacts'], function () { // List contacts - Route::get('list/{type}/{reference}', 'ContactController@index')->name('list'); + //Route::get('list/{type}/{reference}', 'ContactController@index')->name('list'); // Create new contact - Route::post('{type}/{reference}', 'ContactController@store')->name('create'); + //Route::post('{type}/{reference}', 'ContactController@store')->name('create'); // Update contact Route::put('{type}/{reference}/{id}', 'ContactController@store')->name('update'); @@ -78,6 +78,15 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function // Delete contact Route::delete('{id}', 'ContactController@destroy')->name('delete'); + // Test Create Contact + Route::post('/create/{type}/{reference}','CreateContactController@create')->name('create.contact'); + + // Test Update Contact + Route::post('/update/{id}','UpdateContactController@update')->name('update.contact'); + + // Test List Contact + Route::get('/list/{type}/{reference}','ListContactController@list')->name('list.contact'); + }); // Warehouses Routes diff --git a/routes/web.php b/routes/web.php index 21df1e3..ffcba5a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -40,6 +40,10 @@ Route::group(['middleware' => ['secure', 'clearcache']], function (): void { Route::get('/warehouse/{warehouseId}/profile', function($warehouseId){ return view('pages.warehouses.profile', ['warehouseId' => $warehouseId]); })->name('warehouses.profile'); + + Route::get('/order/profile', function(){ + return view('pages.orders.profile'); + })->name('order.profile'); }); From 6e21b42ef927e8a7fbdd268fdfcaacb36a4ec30f Mon Sep 17 00:00:00 2001 From: hazim Date: Thu, 7 Mar 2019 16:10:10 +0800 Subject: [PATCH 3/9] update contact recode and clean up --- .../Contacts/Exceptions/CannotCreateContactException.php | 7 +++++-- .../ControllersLogic/Contacts/CreateContactLogic.php | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php b/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php index 1fbe8cf..6609024 100644 --- a/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php +++ b/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php @@ -1,13 +1,16 @@ createContact->execute($object, $type, $referenceId); } - catch (){ - + catch (CannotCreateContactException $exception){ + throw new InternalServerErrorException("Failed to create contact because {$exception->getMessage()}"); } } From bfda0d85968995d10f3c20be61dae10439a7eb69 Mon Sep 17 00:00:00 2001 From: hazim Date: Thu, 7 Mar 2019 16:33:28 +0800 Subject: [PATCH 4/9] update contact recode and clean up --- .../Contacts/Services/CreatesContact.php | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/Classes/Modules/Contacts/Services/CreatesContact.php b/app/Classes/Modules/Contacts/Services/CreatesContact.php index 30596d3..95aaab4 100644 --- a/app/Classes/Modules/Contacts/Services/CreatesContact.php +++ b/app/Classes/Modules/Contacts/Services/CreatesContact.php @@ -3,6 +3,7 @@ namespace App\Classes\Modules\Contacts\Services; +use App\Classes\Modules\Contacts\Exceptions\CannotCreateContactException; use App\Models\Contact; use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject; @@ -28,16 +29,22 @@ class CreatesContact */ public function execute(ContactObject $contact, int $type, int $referenceId) { - $this->repository->type = $type; - $this->repository->reference_id = $referenceId; - $this->repository->name = $contact->getName(); - $this->repository->designation = $contact->getDesignation(); - $this->repository->email = $contact->getEmail(); - $this->repository->contact = $contact->getContact(); + try{ - $this->repository->save(); + $this->repository->type = $type; + $this->repository->reference_id = $Id; + $this->repository->name = $contact->getName(); + $this->repository->designation = $contact->getDesignation(); + $this->repository->email = $contact->getEmail(); + $this->repository->contact = $contact->getContact(); + $this->repository->save(); + return $this->repository; + } + catch (\Exception $exception) + { + throw new CannotCreateContactException($exception->getMessage()); + } - return $this->repository; } } \ No newline at end of file From 82fa15b79ed3150bcfbec982aab0cc6e1dfad00e Mon Sep 17 00:00:00 2001 From: hazim Date: Thu, 7 Mar 2019 16:34:28 +0800 Subject: [PATCH 5/9] update contact recode and clean up --- app/Classes/Modules/Contacts/Services/CreatesContact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Classes/Modules/Contacts/Services/CreatesContact.php b/app/Classes/Modules/Contacts/Services/CreatesContact.php index 95aaab4..2989493 100644 --- a/app/Classes/Modules/Contacts/Services/CreatesContact.php +++ b/app/Classes/Modules/Contacts/Services/CreatesContact.php @@ -32,7 +32,7 @@ class CreatesContact try{ $this->repository->type = $type; - $this->repository->reference_id = $Id; + $this->repository->reference_id = $referenceId; $this->repository->name = $contact->getName(); $this->repository->designation = $contact->getDesignation(); $this->repository->email = $contact->getEmail(); From 638dda9c3fb12f8ad53cbe43b8ff9d70a23d22cd Mon Sep 17 00:00:00 2001 From: hazim Date: Thu, 7 Mar 2019 16:59:17 +0800 Subject: [PATCH 6/9] update contact recode and clean up --- .../Contacts/Exceptions/CannotCreateContactException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php b/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php index 6609024..0ab4115 100644 --- a/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php +++ b/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php @@ -19,6 +19,6 @@ final class CannotCreateContactException extends ErrorException */ public function __construct(string $message) { - parent::_construct($message,HttpStatus::BAD_REQUEST); + parent::_construct($message, HttpStatus::BAD_REQUEST); } } \ No newline at end of file From ad27e5bfd121c10b2b07f58dd83ac9184aef9f6a Mon Sep 17 00:00:00 2001 From: hazim Date: Thu, 7 Mar 2019 17:18:31 +0800 Subject: [PATCH 7/9] update contact recode and clean up --- .../Contacts/CreateContactLogic.php | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php b/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php index 165ccb5..2adeda4 100644 --- a/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php +++ b/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php @@ -2,41 +2,38 @@ namespace App\Modules\ControllerLogic\Contacts; - use App\Classes\Constants; +use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject; use App\Classes\Modules\Contacts\Exceptions\CannotCreateContactException; -use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException; -use App\Modules\Contacts\DataTransferObjects\ContactObject; -use App\Modules\Contacts\Services\CreatesContact; +use App\Classes\Modules\Contacts\Services\CreatesContact; use Illuminate\Http\Request; class CreateContactLogic { - - /** @var CreatesContact */ - private $createsContact; + /** @var CreatesContact */ + private $createContact; /** * CreateContactLogic constructor. - * @param CreatesContact $createsContact + * @param CreatesContact $createContact */ - public function __construct(CreatesContact $createsContact) + public function __construct(CreatesContact $createContact) { - $this->createsContact = $createsContact; + $this->createContact = $createContact; } - public function execute(int $type, int $referenceId, Request $request){ + public function execute(string $type, int $referenceId, Request $request) + { + try{ - try { - $object = new ContactObject($type, $referenceId, $request->input('name'), $request->input('designation'), $request->input('contact'), $request->input('email')); + $object = new ContactObject($request->input('name'), $request->input('designation'), $request->input('contact'), $request->input('email')); + return $this->createContact->execute($object, $type, $referenceId); - return $this->createsContact->execute($object); - } catch (CannotCreateContactException $exception){ + } + catch (CannotCreateContactException $exception){ throw new InternalServerErrorException("Failed to create contact because {$exception->getMessage()}"); } - - } } \ No newline at end of file From bee2dad424876fac10472f5bb9e0f9c269a60df3 Mon Sep 17 00:00:00 2001 From: hazim Date: Thu, 7 Mar 2019 18:00:06 +0800 Subject: [PATCH 8/9] update contact recode and clean up --- .../Modules/ControllersLogic/Contacts/CreateContactLogic.php | 2 +- app/Http/Controllers/Contacts/CreateContactController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php b/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php index 2adeda4..d9887bb 100644 --- a/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php +++ b/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php @@ -1,6 +1,6 @@ Date: Mon, 11 Mar 2019 18:34:58 +0800 Subject: [PATCH 9/9] list user account backend --- .../Accounts/Services/ListUserAccount.php | 37 +++++++++++++++++++ .../Accounts/ListUserAccountLogic.php | 33 +++++++++++++++++ .../ValueObjects/Constants/UserRoles.php | 8 ++++ .../Account/ListUserController.php | 21 +++++++++++ app/Http/Resources/User.php | 25 +++++++++++++ routes/api.php | 1 + 6 files changed, 125 insertions(+) create mode 100644 app/Classes/Modules/Accounts/Services/ListUserAccount.php create mode 100644 app/Classes/Modules/ControllersLogic/Accounts/ListUserAccountLogic.php create mode 100644 app/Http/Controllers/Account/ListUserController.php create mode 100644 app/Http/Resources/User.php diff --git a/app/Classes/Modules/Accounts/Services/ListUserAccount.php b/app/Classes/Modules/Accounts/Services/ListUserAccount.php new file mode 100644 index 0000000..5df19b0 --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/ListUserAccount.php @@ -0,0 +1,37 @@ +repository = $repository; + } + + + public function execute() + { + $user = $this->repository->get(); + + return UserResource::collection($user); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ControllersLogic/Accounts/ListUserAccountLogic.php b/app/Classes/Modules/ControllersLogic/Accounts/ListUserAccountLogic.php new file mode 100644 index 0000000..a35f5aa --- /dev/null +++ b/app/Classes/Modules/ControllersLogic/Accounts/ListUserAccountLogic.php @@ -0,0 +1,33 @@ +listUserAccount = $listUserAccount; + } + + + public function execute() + { + return $this->listUserAccount->execute(); + } +} \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/UserRoles.php b/app/Classes/ValueObjects/Constants/UserRoles.php index 760b08c..ae00b5c 100644 --- a/app/Classes/ValueObjects/Constants/UserRoles.php +++ b/app/Classes/ValueObjects/Constants/UserRoles.php @@ -15,6 +15,14 @@ final class UserRoles { public const SUPPLIER = 4; + public const ROLES_ID = [ + 0 => 'Administrator', + 1 => 'Administrator', + 2 => 'Importer', + 3 => 'Warehouse', + 4 => 'Supplier', + ]; + } diff --git a/app/Http/Controllers/Account/ListUserController.php b/app/Http/Controllers/Account/ListUserController.php new file mode 100644 index 0000000..ad2d280 --- /dev/null +++ b/app/Http/Controllers/Account/ListUserController.php @@ -0,0 +1,21 @@ +execute(); + } + +} \ No newline at end of file diff --git a/app/Http/Resources/User.php b/app/Http/Resources/User.php new file mode 100644 index 0000000..82cecbf --- /dev/null +++ b/app/Http/Resources/User.php @@ -0,0 +1,25 @@ + $this->first_name.' '.$this->last_name, + 'role' => UserRoles::ROLES_ID[$this->role_id], + 'created_at' => $this->created_at + ]; + } +} diff --git a/routes/api.php b/routes/api.php index 8b4f91c..f9c156b 100644 --- a/routes/api.php +++ b/routes/api.php @@ -19,6 +19,7 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function Route::group(['prefix' => 'account', 'as' => 'account.', 'namespace' => 'Account'], function () { Route::post('/create', 'RegisterAccountController@register')->name('create'); Route::post('/invite', 'InviteUserController@invite')->name('invite'); + Route::get('/list/active','ListUserController@list')->name('list'); }); // Companies Routes