-
Notifications
You must be signed in to change notification settings - Fork 3
Feature Items #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature Items #53
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| <?php | ||
|
|
||
| namespace CodebarAg\Bexio\Dto\Items; | ||
|
|
||
| use Exception; | ||
| use Illuminate\Support\Arr; | ||
| use Saloon\Http\Response; | ||
| use Spatie\LaravelData\Data; | ||
|
|
||
| class CreateEditItemDTO extends Data | ||
| { | ||
| public function __construct( | ||
| public ?int $user_id, | ||
| public int $article_type_id, | ||
| public ?int $contact_id, | ||
| public ?string $deliverer_code, | ||
| public ?string $deliverer_name, | ||
| public ?string $deliverer_description, | ||
| public string $intern_code, | ||
| public string $intern_name, | ||
| public ?string $intern_description = null, | ||
| public ?string $purchase_price = null, | ||
| public ?string $sale_price = null, | ||
| public ?float $purchase_total = null, | ||
| public ?float $sale_total = null, | ||
| public ?int $currency_id = null, | ||
| public ?int $tax_income_id = null, | ||
| public ?int $tax_expense_id = null, | ||
| public ?int $unit_id = null, | ||
| public bool $is_stock = false, | ||
| public ?int $stock_id = null, | ||
| public ?int $stock_place_id = null, | ||
| public int $stock_nr = 0, | ||
| public int $stock_min_nr = 0, | ||
| public ?int $width = null, | ||
| public ?int $height = null, | ||
| public ?int $weight = null, | ||
| public ?int $volume = null, | ||
| public ?string $html_text = null, // Deprecated | ||
| public ?string $remarks = null, | ||
| public ?float $delivery_price = null, | ||
| public ?int $article_group_id = null, | ||
| public ?int $account_id = null, | ||
| public ?int $expense_account_id = null, | ||
| ) {} | ||
|
|
||
| public static function fromResponse(Response $response): self | ||
| { | ||
| if ($response->failed()) { | ||
| throw new \Exception('Failed to create DTO from Response'); | ||
| } | ||
|
|
||
| $data = $response->json(); | ||
|
|
||
| return self::fromArray($data); | ||
| } | ||
|
|
||
| public static function fromArray(array $data): self | ||
| { | ||
| if (! $data) { | ||
| throw new Exception('Unable to create DTO. Data missing from response.'); | ||
| } | ||
|
|
||
| return new self( | ||
| user_id: Arr::get($data, 'user_id'), | ||
| article_type_id: Arr::get($data, 'article_type_id'), | ||
| contact_id: Arr::get($data, 'contact_id'), | ||
| deliverer_code: Arr::get($data, 'deliverer_code'), | ||
| deliverer_name: Arr::get($data, 'deliverer_name'), | ||
| deliverer_description: Arr::get($data, 'deliverer_description'), | ||
| intern_code: Arr::get($data, 'intern_code'), | ||
| intern_name: Arr::get($data, 'intern_name'), | ||
| intern_description: Arr::get($data, 'intern_description'), | ||
| purchase_price: Arr::get($data, 'purchase_price'), | ||
| sale_price: Arr::get($data, 'sale_price'), | ||
| purchase_total: Arr::get($data, 'purchase_total'), | ||
| sale_total: Arr::get($data, 'sale_total'), | ||
| currency_id: Arr::get($data, 'currency_id'), | ||
| tax_income_id: Arr::get($data, 'tax_income_id'), | ||
| tax_expense_id: Arr::get($data, 'tax_expense_id'), | ||
| unit_id: Arr::get($data, 'unit_id'), | ||
| is_stock: Arr::get($data, 'is_stock', false), | ||
| stock_id: Arr::get($data, 'stock_id'), | ||
| stock_place_id: Arr::get($data, 'stock_place_id'), | ||
| stock_nr: Arr::get($data, 'stock_nr', 0), | ||
| stock_min_nr: Arr::get($data, 'stock_min_nr', 0), | ||
| width: Arr::get($data, 'width'), | ||
| height: Arr::get($data, 'height'), | ||
| weight: Arr::get($data, 'weight'), | ||
| volume: Arr::get($data, 'volume'), | ||
| html_text: Arr::get($data, 'html_text'), | ||
| remarks: Arr::get($data, 'remarks'), | ||
| delivery_price: Arr::get($data, 'delivery_price'), | ||
| article_group_id: Arr::get($data, 'article_group_id'), | ||
| account_id: Arr::get($data, 'account_id'), | ||
| expense_account_id: Arr::get($data, 'expense_account_id'), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| <?php | ||
|
|
||
| namespace CodebarAg\Bexio\Dto\Items; | ||
|
|
||
| use Exception; | ||
| use Illuminate\Support\Arr; | ||
| use Saloon\Http\Response; | ||
| use Spatie\LaravelData\Data; | ||
|
|
||
| class ItemDTO extends Data | ||
| { | ||
| public function __construct( | ||
| public int $id, | ||
| public int $user_id, | ||
| public int $article_type_id, | ||
| public ?int $contact_id, | ||
| public ?int $master_id, | ||
| public ?string $deliverer_code, | ||
| public ?string $deliverer_name, | ||
| public ?string $deliverer_description, | ||
| public string $intern_code, | ||
| public string $intern_name, | ||
| public ?string $intern_description, | ||
| public ?string $purchase_price, | ||
| public ?string $sale_price, | ||
| public ?float $purchase_total, | ||
| public ?float $sale_total, | ||
| public ?int $currency_id, | ||
| public ?int $tax_income_id, | ||
| public ?int $tax_id, | ||
| public ?int $tax_expense_id, | ||
| public ?int $unit_id, | ||
| public bool $is_stock, | ||
| public ?int $stock_id, | ||
| public ?int $stock_place_id, | ||
| public int $stock_nr, | ||
| public int $stock_min_nr, | ||
| public int $stock_reserved_nr, | ||
| public int $stock_available_nr, | ||
| public int $stock_picked_nr, | ||
| public int $stock_disposed_nr, | ||
| public int $stock_ordered_nr, | ||
| public ?int $width, | ||
| public ?int $height, | ||
| public ?int $weight, | ||
| public ?int $volume, | ||
| public ?string $html_text, // Deprecated | ||
| public ?string $remarks, | ||
| public ?float $delivery_price, | ||
| public ?int $article_group_id, | ||
| public ?int $account_id, | ||
| public ?int $expense_account_id, | ||
| ) {} | ||
|
|
||
| public static function fromResponse(Response $response): self | ||
| { | ||
| if ($response->failed()) { | ||
| throw new \Exception('Failed to create DTO from Response'); | ||
| } | ||
|
|
||
| $data = $response->json(); | ||
|
|
||
| return self::fromArray($data); | ||
| } | ||
|
|
||
| public static function fromArray(array $data): self | ||
| { | ||
| if (! $data) { | ||
| throw new Exception('Unable to create DTO. Data missing from response.'); | ||
| } | ||
|
|
||
| return new self( | ||
| id: Arr::get($data, 'id'), | ||
| user_id: Arr::get($data, 'user_id'), | ||
| article_type_id: Arr::get($data, 'article_type_id'), | ||
| contact_id: Arr::get($data, 'contact_id'), | ||
| master_id: Arr::get($data, 'master_id'), | ||
| deliverer_code: Arr::get($data, 'deliverer_code'), | ||
| deliverer_name: Arr::get($data, 'deliverer_name'), | ||
| deliverer_description: Arr::get($data, 'deliverer_description'), | ||
| intern_code: Arr::get($data, 'intern_code'), | ||
| intern_name: Arr::get($data, 'intern_name'), | ||
| intern_description: Arr::get($data, 'intern_description'), | ||
| purchase_price: Arr::get($data, 'purchase_price'), | ||
| sale_price: Arr::get($data, 'sale_price'), | ||
| purchase_total: Arr::get($data, 'purchase_total'), | ||
| sale_total: Arr::get($data, 'sale_total'), | ||
| currency_id: Arr::get($data, 'currency_id'), | ||
| tax_income_id: Arr::get($data, 'tax_income_id'), | ||
| tax_id: Arr::get($data, 'tax_id'), | ||
| tax_expense_id: Arr::get($data, 'tax_expense_id'), | ||
| unit_id: Arr::get($data, 'unit_id'), | ||
| is_stock: Arr::get($data, 'is_stock', false), | ||
| stock_id: Arr::get($data, 'stock_id'), | ||
| stock_place_id: Arr::get($data, 'stock_place_id'), | ||
| stock_nr: Arr::get($data, 'stock_nr', 0), | ||
| stock_min_nr: Arr::get($data, 'stock_min_nr', 0), | ||
| stock_reserved_nr: Arr::get($data, 'stock_reserved_nr', 0), | ||
| stock_available_nr: Arr::get($data, 'stock_available_nr', 0), | ||
| stock_picked_nr: Arr::get($data, 'stock_picked_nr', 0), | ||
| stock_disposed_nr: Arr::get($data, 'stock_disposed_nr', 0), | ||
| stock_ordered_nr: Arr::get($data, 'stock_ordered_nr', 0), | ||
| width: Arr::get($data, 'width'), | ||
| height: Arr::get($data, 'height'), | ||
| weight: Arr::get($data, 'weight'), | ||
| volume: Arr::get($data, 'volume'), | ||
| html_text: Arr::get($data, 'html_text'), | ||
| remarks: Arr::get($data, 'remarks'), | ||
| delivery_price: Arr::get($data, 'delivery_price'), | ||
| article_group_id: Arr::get($data, 'article_group_id'), | ||
| account_id: Arr::get($data, 'account_id'), | ||
| expense_account_id: Arr::get($data, 'expense_account_id'), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php | ||
|
|
||
| namespace CodebarAg\Bexio\Enums\Items; | ||
|
|
||
| use Spatie\Enum\Laravel\Enum; | ||
|
|
||
| /** | ||
| * @method static self ID() | ||
| * @method static self ID_ASC() | ||
| * @method static self ID_DESC() | ||
| * @method static self INTERN_NAME() | ||
| * @method static self INTERN_NAME_ASC() | ||
| * @method static self INTERN_NAME_DESC() | ||
| */ | ||
| final class OrderByEnum extends Enum | ||
| { | ||
| protected static function values(): array | ||
| { | ||
| return [ | ||
| 'ID' => 'id', | ||
| 'ID_ASC' => 'id_asc', | ||
| 'ID_DESC' => 'id_desc', | ||
| 'INTERN_NAME' => 'intern_name', | ||
| 'INTERN_NAME_ASC' => 'intern_name_asc', | ||
| 'INTERN_NAME_DESC' => 'intern_name_desc', | ||
| ]; | ||
| } | ||
|
|
||
| protected static function labels(): array | ||
| { | ||
| return [ | ||
| 'ID' => 'Id', | ||
| 'ID_ASC' => 'Id Ascending', | ||
| 'ID_DESC' => 'Id Descending', | ||
| 'INTERN_NAME' => 'Intern Name', | ||
| 'INTERN_NAME_ASC' => 'Intern Name Ascending', | ||
| 'INTERN_NAME_DESC' => 'Intern Name Descending', | ||
| ]; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nullable parameters without default values (
$user_id,$contact_id,$deliverer_code,$deliverer_name,$deliverer_description) must be provided when instantiating this DTO, making them effectively required. This is confusing for API consumers. These parameters should either have= nulldefaults to make them truly optional, or be marked as non-nullable if they're required. The current signature creates ambiguity about which parameters are actually optional.