Hi All,
I am attempting to use DDD principles in my application, currently the app just uses controllers which are fat and i would like to split logic out for maintainability and re-usability.
Can anyone help me on how i should do the following - we have a page for raising credits, each credit consists of base data plus credit lines (of which there can be one or more).
I have created basic DTOs for the SupplierCreditData along with a DTO for SupplierCreditLineData
namespace Domain\Accounting\DataTransferObjects;
use Akaunting\Money\Currency;
use Carbon\Carbon;
use Spatie\LaravelData\Data;
use Akaunting\Money\Money;
use Spatie\LaravelData\DataCollection;
class SupplierCreditData extends Data
{
public function __construct(
public readonly ?int $supplierId,
public readonly Carbon $date,
public readonly ?string $reference,
public readonly ?Currency $currency,
public readonly ?string $currencyId,
public readonly ?int $periodId,
public readonly ?string $comments,
public ?Money $exchangeRate,
/**
* @var SupplierCreditGeneralLedgerData[]|null
*/
public readonly ?DataCollection $generalLedgerEntries,
/**
* @var SupplierCreditLineData[]|null
*/
public readonly ?DataCollection $supplierCreditLines,
/**
* @var TaxAuthorityRateData[]|null
*/
public readonly ?DataCollection $taxAuthorityRates
){
}
}
namespace Domain\Accounting\DataTransferObjects;
use Akaunting\Money\Money;
use Spatie\LaravelData\Data;
class SupplierCreditLineData extends Data
{
public function __construct(
public readonly ?int $grnIndexId,
public readonly ?int $grnBatchId,
public readonly ?string $sku,
public readonly ?string $description,
public readonly ?int $purchaseOrderDetailId,
public readonly ?Money $changedPrice,
public readonly ?float $quantityToCredit,
public readonly ?string $chartmasterAccountCode,
){}
}
My understanding is the request comes in, this is converted to DTOs as above, i am then passing the DTOs into an CreditService class which handles calculations and raising of the credit.
Currently the CreditService class has methods such as getTotalAmount() which it loops through the SupplierCreditData->supplierCreditLines and gets the total.
My question is should i pass the DTOs into the service class and use them as they are, or should i implement methods such as addCreditLine() which creates new objects and stores them seperately in the service class and then use these instead of the DTOs.
Or am i doing what i always do and just overthinking! I get there is no right or wrong answer essentially but what would you guys do?