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') +