mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim.git
synced 2026-08-19 04:24:00 +00:00
Cleaned-BackEnd-Contact
This commit is contained in:
@@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Classes\ControllersLogic\Contacts;
|
|
||||||
|
|
||||||
use App\Models\Contact;
|
|
||||||
use App\Http\Resources\Contact as ContactResource;
|
|
||||||
|
|
||||||
class DeleteContact
|
|
||||||
{
|
|
||||||
public function execute(string $id) {
|
|
||||||
|
|
||||||
// Get address
|
|
||||||
$contact= Contact::findOrFail($id);
|
|
||||||
|
|
||||||
|
|
||||||
if($contact->delete()){
|
|
||||||
|
|
||||||
// Return single address as a resource
|
|
||||||
return new ContactResource($contact);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Classes\ControllersLogic\Contacts;
|
|
||||||
|
|
||||||
use App\Models\Contact;
|
|
||||||
use App\Http\Resources\Contact as ContactResource;
|
|
||||||
|
|
||||||
class ListContacts
|
|
||||||
{
|
|
||||||
public function execute(int $type, string $reference) {
|
|
||||||
|
|
||||||
// Get contacts
|
|
||||||
$contacts = Contact::where('type', $type)->where('reference_id', $reference)->orderBy('created_at')->paginate(5);
|
|
||||||
|
|
||||||
// Return collection of contacts as a resource
|
|
||||||
return ContactResource::collection($contacts);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Classes\ControllersLogic\Contacts;
|
|
||||||
|
|
||||||
use App\Models\Contact;
|
|
||||||
use App\Http\Resources\Contact as ContactResource;
|
|
||||||
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 = $this->repository->findOrFail($id);
|
|
||||||
|
|
||||||
$contact->type = $type;
|
|
||||||
$contact->reference_id = $reference;
|
|
||||||
$contact->name = $request->input('name');
|
|
||||||
$contact->designation = $request->input('designation');
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Modules\Contacts\DataTransferObjects;
|
namespace App\Classes\Modules\Contacts\DataTransferObjects;
|
||||||
|
|
||||||
class ContactObject
|
class ContactObject
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: user
|
||||||
|
* Date: 09/05/2019
|
||||||
|
* Time: 11:51 AM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Contacts\Services;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Models\Contact;
|
||||||
|
use App\Http\Resources\Contact as ContactResource;
|
||||||
|
|
||||||
|
class DeletesContact
|
||||||
|
{
|
||||||
|
/** @var Contact */
|
||||||
|
private $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DeletesContact constructor.
|
||||||
|
* @param Contact $repository
|
||||||
|
*/
|
||||||
|
public function __construct(Contact $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function execute(String $id){
|
||||||
|
|
||||||
|
$contact = $this->repository->findOrFail($id);
|
||||||
|
|
||||||
|
if($contact->delete()){
|
||||||
|
|
||||||
|
// Return single address as a resource
|
||||||
|
return new ContactResource($contact);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ class ListsContact
|
|||||||
public function execute(int $type, int $referenceId){
|
public function execute(int $type, int $referenceId){
|
||||||
|
|
||||||
$contacts = $this->repository->where('type', $type)
|
$contacts = $this->repository->where('type', $type)
|
||||||
->where('reference_id', $referenceId)->get();
|
->where('reference_id', $referenceId)->orderBy('created_at')->paginate(5);
|
||||||
|
|
||||||
// Return collection of contacts as a resource
|
// Return collection of contacts as a resource
|
||||||
return ContactResource::collection($contacts);
|
return ContactResource::collection($contacts);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class CreateContactLogic
|
|||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
|
|
||||||
$object = new ContactObject($request->input('name'), $request->input('designation'), $request->input('contact'), $request->input('email'));
|
$object = new ContactObject($type, $referenceId, $request->input('name'), $request->input('designation'), $request->input('contact'), $request->input('email'));
|
||||||
return $this->createContact->execute($object, $type, $referenceId);
|
return $this->createContact->execute($object, $type, $referenceId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: user
|
||||||
|
* Date: 09/05/2019
|
||||||
|
* Time: 11:51 AM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Modules\ControllerLogic\Contacts;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Classes\Modules\Contacts\Services\DeletesContact;
|
||||||
|
|
||||||
|
class DeleteContactLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var DeletesContact */
|
||||||
|
private $DeletesContact;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DeleteContactLogic constructor.
|
||||||
|
* @param DeletesContact $DeletesContact
|
||||||
|
*/
|
||||||
|
public function __construct(DeletesContact $DeletesContact)
|
||||||
|
{
|
||||||
|
$this->DeletesContact = $DeletesContact;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function execute(String $id){
|
||||||
|
return $this->DeletesContact->execute($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -28,10 +28,9 @@ class UpdateContactLogic
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function execute(int $id, Request $request)
|
public function execute(int $id, string $referenceId, int $type, Request $request)
|
||||||
{
|
{
|
||||||
$object = new ContactObject($request->input('name'), $request->input('designation'), $request->input('contact'), $request->input('email'));
|
$object = new ContactObject($type, $referenceId, $request->input('name'), $request->input('designation'), $request->input('contact'), $request->input('email'));
|
||||||
|
|
||||||
return $this->updateContact->execute($id, $object);
|
return $this->updateContact->execute($id, $object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Contacts;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Http\Resources\Contact as ContactResource;
|
|
||||||
use App\Classes\Constants;
|
|
||||||
use App\Classes\ControllersLogic\Contacts\ListContacts;
|
|
||||||
use App\Classes\ControllersLogic\Contacts\UpdateContact;
|
|
||||||
use App\Classes\ControllersLogic\Contacts\DeleteContact;
|
|
||||||
|
|
||||||
class ContactController extends Controller
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
* @param string $type
|
|
||||||
* @param string $reference
|
|
||||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
|
|
||||||
*/
|
|
||||||
public function index(string $type, string $reference) {
|
|
||||||
|
|
||||||
return (new ListContacts())->execute(Constants::MODULE_TYPES[$type], $reference);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created resource in storage.
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Http\Request $request
|
|
||||||
* @param string $type
|
|
||||||
* @param string $reference
|
|
||||||
* @return ContactResource
|
|
||||||
*/
|
|
||||||
public function store(Request $request, string $type, string $reference)
|
|
||||||
{
|
|
||||||
return (new UpdateContact())->execute($request, Constants::MODULE_TYPES[$type], $reference);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the specified resource from storage.
|
|
||||||
*
|
|
||||||
* @param string $id
|
|
||||||
*
|
|
||||||
* @return ContactResource
|
|
||||||
*/
|
|
||||||
public function destroy(string $id): ContactResource {
|
|
||||||
|
|
||||||
return (new DeleteContact())->execute($id);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,6 +9,7 @@ use App\Classes\Modules\ControllerLogic\Contacts\CreateContactLogic;
|
|||||||
class CreateContactController
|
class CreateContactController
|
||||||
{
|
{
|
||||||
public function create(string $type, int $referencesId, Request $request, CreateContactLogic $logic){
|
public function create(string $type, int $referencesId, Request $request, CreateContactLogic $logic){
|
||||||
|
|
||||||
return $logic->execute(Constants::MODULE_TYPES[$type], $referencesId, $request);
|
return $logic->execute(Constants::MODULE_TYPES[$type], $referencesId, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: user
|
||||||
|
* Date: 09/05/2019
|
||||||
|
* Time: 11:51 AM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Contacts;
|
||||||
|
|
||||||
|
use App\Modules\ControllerLogic\Contacts\DeleteContactLogic;
|
||||||
|
|
||||||
|
class DeleteContactController
|
||||||
|
{
|
||||||
|
public function destroy(String $id, DeleteContactLogic $logic ){
|
||||||
|
return $logic->execute($id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Contacts;
|
namespace App\Http\Controllers\Contacts;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
use App\Modules\ControllerLogic\Contacts\ListContactLogic;
|
use App\Modules\ControllerLogic\Contacts\ListContactLogic;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,15 @@
|
|||||||
namespace App\Http\Controllers\Contacts;
|
namespace App\Http\Controllers\Contacts;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Classes\Constants;
|
||||||
use App\Modules\ControllerLogic\Contacts\UpdateContactLogic;
|
use App\Modules\ControllerLogic\Contacts\UpdateContactLogic;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class UpdateContactController
|
class UpdateContactController
|
||||||
{
|
{
|
||||||
public function update(int $id,Request $request, UpdateContactLogic $logic){
|
public function update(string $type, string $referenceId, int $id, Request $request, UpdateContactLogic $logic){
|
||||||
return $logic->execute($id, $request);
|
|
||||||
|
return $logic->execute($id,$referenceId, Constants::MODULE_TYPES[$type], $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ class Contact extends JsonResource
|
|||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
'reference_id' => $this->reference_id,
|
'reference_id' => $this->reference_id,
|
||||||
'name' => $this->first_name.' '. $this->last_name,
|
'name' => $this->name,
|
||||||
'designation' => $this->designation,
|
'designation' => $this->designation,
|
||||||
'contact' => $this->contact,
|
'contact' => $this->contact,
|
||||||
'email' => $this->email,
|
'email' => $this->email,
|
||||||
|
|||||||
+4
-4
@@ -78,16 +78,16 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function
|
|||||||
Route::group(['prefix' => 'contact', 'as' => 'contact.', 'namespace' => 'Contacts'], function () {
|
Route::group(['prefix' => 'contact', 'as' => 'contact.', 'namespace' => 'Contacts'], function () {
|
||||||
|
|
||||||
// List contacts
|
// List contacts
|
||||||
Route::get('list/{type}/{reference}', 'ContactController@index')->name('list');
|
Route::get('list/{type}/{reference}', 'ListContactController@list')->name('list');
|
||||||
|
|
||||||
// Create new contact
|
// Create new contact
|
||||||
Route::post('{type}/{reference}', 'ContactController@store')->name('create');
|
Route::post('{type}/{reference}', 'CreateContactController@create')->name('create');
|
||||||
|
|
||||||
// Update contact
|
// Update contact
|
||||||
Route::put('{type}/{reference}/{id}', 'ContactController@store')->name('update');
|
Route::put('{type}/{reference}/{id}', 'UpdateContactController@update')->name('update');
|
||||||
|
|
||||||
// Delete contact
|
// Delete contact
|
||||||
Route::delete('{id}', 'ContactController@destroy')->name('delete');
|
Route::delete('{id}', 'DeleteContactController@destroy')->name('delete');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user