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/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/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..0ab4115 --- /dev/null +++ b/app/Classes/Modules/Contacts/Exceptions/CannotCreateContactException.php @@ -0,0 +1,24 @@ +repository = $repository; + } + + /** + * @param ContactObject $contact + * @param int $type + * @param int $referenceId + * @return Contact + */ + public function execute(ContactObject $contact, int $type, int $referenceId) + { + try{ + + $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; + } + catch (\Exception $exception) + { + throw new CannotCreateContactException($exception->getMessage()); + } + + } + +} \ 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/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/Modules/ControllersLogic/Contacts/CreateContactLogic.php b/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php new file mode 100644 index 0000000..d9887bb --- /dev/null +++ b/app/Classes/Modules/ControllersLogic/Contacts/CreateContactLogic.php @@ -0,0 +1,39 @@ +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 (CannotCreateContactException $exception){ + throw new InternalServerErrorException("Failed to create contact because {$exception->getMessage()}"); + } + } + +} \ 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/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/Controllers/Contacts/CreateContactController.php b/app/Http/Controllers/Contacts/CreateContactController.php new file mode 100644 index 0000000..268089c --- /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/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/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') +