Merge branch 'create-deliver-packing-list-api' into 'master'

create deliver packing list api

See merge request CIEFWorldwideSdnBhd/shipping-portal!74
This commit is contained in:
omair saleh
2021-10-25 05:53:33 +00:00
10 changed files with 199 additions and 4 deletions
@@ -7,7 +7,6 @@ use Illuminate\Database\Eloquent\Relations\MorphMany;
interface Packable
{
public function packingLists(): morphMany;
}
@@ -0,0 +1,88 @@
<?php
namespace App\Classes\Modules\PackingLists\ControllersLogic;
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
use App\Classes\Modules\PackingLists\Processors\CreatePackingListProcessor;
use App\Classes\Modules\PackingLists\Services\GeneratesPackingListReferenceNumber;
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
use App\Classes\ValueObjects\Constants\PackingListType;
use App\Http\Resources\DeliverPackingListResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateDeliverPackingListLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Created Deliver PackingList',
'message' => 'You have successfully created a new Deliver PackingList'
];
}
/** @var CreatePackingListProcessor */
private $createPackingListProcessor;
/** @var FetchesCompanyModule */
private $fetchesCompanyModule;
/** @var GeneratesPackingListReferenceNumber */
private $generatesPackingListReferenceNumber;
/** @var FetchesPackingList */
private $fetchesPackingList;
/**
* CreateDeliverPackingListLogic constructor.
* @param CreatePackingListProcessor $createPackingListProcessor
* @param FetchesCompanyModule $fetchesCompanyModule
*/
public function __construct(CreatePackingListProcessor $createPackingListProcessor, FetchesCompanyModule $fetchesCompanyModule, GeneratesPackingListReferenceNumber $generatesPackingListReferenceNumber, FetchesPackingList $fetchesPackingList)
{
$this->createPackingListProcessor = $createPackingListProcessor;
$this->fetchesCompanyModule = $fetchesCompanyModule;
$this->generatesPackingListReferenceNumber = $generatesPackingListReferenceNumber;
$this->fetchesPackingList = $fetchesPackingList;
}
/**
* @param Request $request
* @return JsonResponse
*/
public function logic(Request $request) : JsonResponse
{
$company_module = $this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]);
$packing_list_id = $request->input('packing_list_id');
$reference_number = $this->generatesPackingListReferenceNumber->execute();
$packingListObject = new PackingListObject(
$reference_number,
null,
PackingListType::DELIVERY_PACKING_LIST,
ApprovalStatus::PENDING_SUBMISSION
);
$deliverPackingList = $this->createPackingListProcessor->execute($packingListObject, $company_module);
foreach ($packing_list_id as $key => $row) {
$this->fetchesPackingList->execute(['id' => $row]);
}
$deliverPackingList->packing_list_owner()->sync($packing_list_id);
return $this->resourceResponse(new DeliverPackingListResource($deliverPackingList));
}
}
@@ -30,7 +30,7 @@ class PackingListObject implements DataTransferObject
* @param int $status
* @param null|string $contractReference
*/
public function __construct(string $reference, int $claimantId, int $type, int $status, ?string $contractReference = null)
public function __construct(string $reference, ?int $claimantId, int $type, int $status, ?string $contractReference = null)
{
$this->reference = $reference;
$this->claimantId = $claimantId;
@@ -50,7 +50,7 @@ class PackingListObject implements DataTransferObject
/**
* @return int
*/
public function getClaimantId(): int
public function getClaimantId(): ?int
{
return $this->claimantId;
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\PackingLists;
use App\Classes\Modules\PackingLists\ControllersLogic\CreateDeliverPackingListLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateDeliverPackingListController
{
/**
* @param Request $request
* @param CreateDeliverPackingListLogic $logic
* @return JsonResponse
*/
public function create(Request $request, CreateDeliverPackingListLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class DeliverPackingListResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'claimant_id' => $this->claimant_id,
'reference' => $this->reference,
'status' => $this->status,
'transport' => new TransportResource($this->transports()->first()),
'packing_list' => PackingListResource::collection($this->packing_list_owner),
'company' => New CompanyModuleResource($this->owner)
];
}
}
+11 -1
View File
@@ -6,6 +6,8 @@ use App\Classes\General\Interfaces\Addressable;
use App\Classes\General\Interfaces\Contactable;
use App\Classes\General\Interfaces\ContainerOwner;
use App\Classes\General\Interfaces\Documentable;
use App\Classes\General\Interfaces\Packable;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\BusinessType;
use Illuminate\Database\Eloquent\Builder;
@@ -28,7 +30,7 @@ use PhpParser\Node\Expr\AssignOp\Mod;
* @property integer type
* @property integer status
*/
class CompanyModule extends AbstractModel implements Addressable, Documentable, Contactable, ContainerOwner
class CompanyModule extends AbstractModel implements Addressable, Documentable, Contactable, ContainerOwner, Packable
{
use SoftDeletes;
@@ -60,6 +62,14 @@ class CompanyModule extends AbstractModel implements Addressable, Documentable,
return $this->morphMany(Address::class, 'owner');
}
/**
* @return MorphMany
*/
public function packingLists(): morphMany
{
return $this->morphMany(PackingList::class, 'owner');
}
/**
* @return belongsToMany
*/
+7
View File
@@ -56,4 +56,11 @@ class PackingList extends AbstractModel implements Transportable, Steppable
return $this->morphMany(Transport::class, 'owner');
}
/**
* @return belongsToMany
*/
public function packing_list_owner()
{
return $this->BelongsToMany(PackingList::class, 'packing_list_owner', 'owner_packing_list_id', 'packing_list_id');
}
}
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PackingListOwner extends Model
{
use HasFactory;
}
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePackingListOwnersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('packing_list_owners', function (Blueprint $table) {
$table->foreignId('owner_packing_list_id');
$table->foreignId('packing_list_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('packing_list_owners');
}
}
+2
View File
@@ -6,6 +6,8 @@ Route::group(['namespace' => 'PackingLists', 'as' => 'packing_list.', 'prefix' =
Route::get('/{id}/show', 'FetchPackingListController@fetch')->name('show');
Route::get('/list', 'ListPackingListsController@list')->name('list');
Route::post('/create', 'CreatePackingListController@create')->name('create');
Route::post('/create/deliver', 'CreateDeliverPackingListController@create')->name('create.deliver');
Route::put('/update/{id}', 'UpdatePackingListController@update')->name('update');
Route::put('/status/{id}/update/{status}', 'UpdatePackingListStatusController@update')->name('status.update');
Route::delete('/delete/{id}', 'DeletePackingListController@delete')->name('delete');