update: changes on Contacts Module based on changes #6

This commit is contained in:
weichien00
2021-07-08 01:53:14 +08:00
parent 45077c953e
commit dc11a1f8d5
4 changed files with 24 additions and 40 deletions
@@ -22,9 +22,6 @@ class ContactObject implements DataTransferObject
/** @var string|null */ /** @var string|null */
private $wechat_id; private $wechat_id;
/** @var int|null */
private $countryId;
/** /**
* ContactObject constructor. * ContactObject constructor.
* @param int $companyId * @param int $companyId
@@ -34,22 +31,12 @@ class ContactObject implements DataTransferObject
* @param null|string $wechat_id * @param null|string $wechat_id
* @param int|null $countryId * @param int|null $countryId
*/ */
public function __construct(int $companyId, string $reference, ?string $phone, ?string $email, ?string $wechat_id, ?int $countryId = Countries::MALAYSIA) public function __construct(string $reference, ?string $phone, ?string $email, ?string $wechat_id)
{ {
$this->companyId = $companyId;
$this->reference = $reference; $this->reference = $reference;
$this->phone = $phone; $this->phone = $phone;
$this->email = $email; $this->email = $email;
$this->wechat_id = $wechat_id; $this->wechat_id = $wechat_id;
$this->countryId = $countryId;
}
/**
* @return int
*/
public function getCompanyId(): int
{
return $this->companyId;
} }
/** /**
@@ -84,15 +71,19 @@ class ContactObject implements DataTransferObject
return $this->wechat_id; return $this->wechat_id;
} }
/** // /**
* @return int // * @return int
*/ // */
public function getCountryId(): int // public function getOwnerId(): int
{ // {
return $this->countryId; // return $this->owner_id;
} // }
// /**
// * @return string
// */
} // public function getOwnerType(): string
// {
// return $this->owner_type;
// }
}
@@ -15,9 +15,6 @@ class CreateContactProcessor
/** @var CanCreateContact */ /** @var CanCreateContact */
private $canCreateContact; private $canCreateContact;
/** @var CreatesContact */
private $createsContact;
/** /**
* CreateContactProcessor constructor. * CreateContactProcessor constructor.
* @param CanCreateContact $canCreateContact * @param CanCreateContact $canCreateContact
@@ -41,15 +38,14 @@ class CreateContactProcessor
{ {
$contact_object = new ContactObject( $contact_object = new ContactObject(
$company->id,
$request->input('name'), $request->input('name'),
$request->input('phone'), $request->input('phone'),
$request->input('contact_email'), $request->input('contact_email'),
$request->input('wechat_id') $request->input('wechat_id'),
); );
$this->canCreateContact->passes($contact_object); $this->canCreateContact->passes($contact_object);
return $this->createsContact->execute($contact_object); return $this->createsContact->execute($company,$contact_object);
} }
} }
@@ -3,26 +3,27 @@
namespace App\Classes\Modules\Contacts\Services; namespace App\Classes\Modules\Contacts\Services;
use App\Classes\General\Eloquent\AbstractUpdateRecord; use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Interfaces\Contactable;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject; use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
use App\Models\Contact; use App\Models\Contact;
class CreatesContact extends AbstractUpdateRecord class CreatesContact extends AbstractUpdateRelationshipRecord
{ {
/** /**
* @param Contactable $contactable
* @param ContactObject $object * @param ContactObject $object
* @return \Illuminate\Database\Eloquent\Model * @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\MalformedRequestException
*/ */
public function execute(ContactObject $object) public function execute(Contactable $contactable, ContactObject $object)
{ {
$model = new Contact(); $model = new Contact();
$model->country_id = $object->getCountryId();
$model->company_id = $object->getCompanyId();
$model->reference = $object->getReference(); $model->reference = $object->getReference();
$model->phone = $object->getPhone(); $model->phone = $object->getPhone();
$model->email = $object->getEmail(); $model->email = $object->getEmail();
$model->wechat_id = $object->getWechatId(); $model->wechat_id = $object->getWechatId();
return $this->handler($model); return $this->handler($contactable->contacts(), $model);
} }
} }
@@ -14,8 +14,6 @@ class ContactValidation extends AbstractValidation
protected function data($object): array protected function data($object): array
{ {
return [ return [
'country_id' => $object->getCountryId(),
'company_id' => $object->getCompanyId(),
'contact_reference' => $object->getReference(), 'contact_reference' => $object->getReference(),
'phone' => $object->getPhone(), 'phone' => $object->getPhone(),
'contact_email' => $object->getEmail(), 'contact_email' => $object->getEmail(),
@@ -29,8 +27,6 @@ class ContactValidation extends AbstractValidation
protected function rules(): array protected function rules(): array
{ {
return [ return [
'country_id' => 'required',
'company_id' => 'required',
'contact_reference' => '', 'contact_reference' => '',
'phone' => 'required', 'phone' => 'required',
'contact_email' => '', 'contact_email' => '',