Skip to content

Commit

Permalink
Add the rest of the resolvers to all operations
Browse files Browse the repository at this point in the history
  • Loading branch information
jonerickson committed Aug 31, 2024
1 parent 8c8df45 commit e47042c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
32 changes: 21 additions & 11 deletions src/Concerns/HandlesRelationManyToManyOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ trait HandlesRelationManyToManyOperations
* Attach resource to the relation in a transaction-safe way.
*
* @param Request $request
* @param int|string $parentKey
* @param array<int, mixed>$args
* @return JsonResponse
*/
public function attach(Request $request, $parentKey)
public function attach(Request $request, ...$args)
{
$parentKey = $this->keyResolver->resolveRelationOperationParentKey($request, $args);

try {
$this->startTransaction();
$result = $this->attachWithTransaction($request, $parentKey);
Expand Down Expand Up @@ -237,11 +239,13 @@ protected function afterAttach(Request $request, Model $parentEntity, array &$at
* Detach resource to the relation in a transaction-safe way.
*
* @param Request $request
* @param int|string $parentKey
* @param array<int, mixed> $args
* @return JsonResponse
*/
public function detach(Request $request, $parentKey)
public function detach(Request $request, ...$args)
{
$parentKey = $this->keyResolver->resolveRelationOperationParentKey($request, $args);

try {
$this->startTransaction();
$result = $this->detachWithTransaction($request, $parentKey);
Expand Down Expand Up @@ -360,11 +364,13 @@ protected function afterDetach(Request $request, Model $parentEntity, array &$de
* Sync relation resources in a transaction-safe way.
*
* @param Request $request
* @param int|string $parentKey
* @param array<int, mixed> $args
* @return JsonResponse
*/
public function sync(Request $request, $parentKey)
public function sync(Request $request, ...$args)
{
$parentKey = $this->keyResolver->resolveRelationOperationParentKey($request, $args);

try {
$this->startTransaction();
$result = $this->syncWithTransaction($request, $parentKey);
Expand Down Expand Up @@ -486,11 +492,13 @@ protected function afterSync(Request $request, Model $parentEntity, array &$sync
* Toggle relation resources in a transaction-safe way.
*
* @param Request $request
* @param int|string $parentKey
* @param array<int, mixed> $args
* @return JsonResponse
*/
public function toggle(Request $request, $parentKey)
public function toggle(Request $request, ...$args)
{
$parentKey = $this->keyResolver->resolveRelationOperationParentKey($request, $args);

try {
$this->startTransaction();
$result = $this->toggleWithTransaction($request, $parentKey);
Expand Down Expand Up @@ -603,12 +611,14 @@ protected function afterToggle(Request $request, Model $parentEntity, array &$to
* Update relation resource pivot in a transaction-safe wqy.
*
* @param Request $request
* @param int|string $parentKey
* @param int|string $relatedKey
* @param array<int, mixed> $args
* @return JsonResponse
*/
public function updatePivot(Request $request, $parentKey, $relatedKey)
public function updatePivot(Request $request, ...$args)
{
$parentKey = $this->keyResolver->resolveRelationOperationParentKey($request, $args);
$relatedKey = $this->keyResolver->resolveRelationOperationRelatedKey($request, $args);

try {
$this->startTransaction();
$result = $this->updatePivotWithTransaction($request, $parentKey, $relatedKey);
Expand Down
14 changes: 9 additions & 5 deletions src/Concerns/HandlesRelationOneToManyOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ trait HandlesRelationOneToManyOperations
* Associates resource with another resource in a transaction-safe way.
*
* @param Request $request
* @param int|string $parentKey
* @param array<int, mixed> $args
* @return Resource
*/
public function associate(Request $request, $parentKey)
public function associate(Request $request, ...$args)
{
$parentKey = $this->keyResolver->resolveRelationOperationParentKey($request, $args);

try {
$this->startTransaction();
$result = $this->associateWithTransaction($request, $parentKey);
Expand Down Expand Up @@ -164,12 +166,14 @@ protected function afterAssociate(Request $request, Model $parentEntity, Model $
* Disassociates resource from another resource in a transaction-safe way.
*
* @param Request $request
* @param int|string $parentKey
* @param int|string $relatedKey
* @param array<int, mixed> $args
* @return Resource
*/
public function dissociate(Request $request, $parentKey, $relatedKey)
public function dissociate(Request $request, ...$args)
{
$parentKey = $this->keyResolver->resolveRelationOperationParentKey($request, $args);
$relatedKey = $this->keyResolver->resolveRelationOperationRelatedKey($request, $args);

try {
$this->startTransaction();
$result = $this->dissociateWithTransaction($request, $parentKey, $relatedKey);
Expand Down
24 changes: 16 additions & 8 deletions src/Concerns/HandlesRelationStandardBatchOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ trait HandlesRelationStandardBatchOperations
* Create a batch of new relation resources in a transaction-safe way.
*
* @param Request $request
* @param int|string $parentKey
* @param array<int, mixed> $args
* @return CollectionResource
*/
public function batchStore(Request $request, $parentKey)
public function batchStore(Request $request, ...$args)
{
$parentKey = $this->keyResolver->resolveRelationOperationParentKey($request, $args);

try {
$this->startTransaction();
$result = $this->batchStoreWithTransaction($request, $parentKey);
Expand Down Expand Up @@ -161,11 +163,13 @@ protected function afterBatchStore(Request $request, Model $parentEntity, Collec
* Updates a batch of relation resources in a transaction-safe way.
*
* @param Request $request
* @param int|string $parentKey
* @param array<int, mixed> $args
* @return CollectionResource
*/
public function batchUpdate(Request $request, $parentKey)
public function batchUpdate(Request $request, ...$args)
{
$parentKey = $this->keyResolver->resolveRelationOperationParentKey($request, $args);

try {
$this->startTransaction();
$result = $this->batchUpdateWithTransaction($request, $parentKey);
Expand Down Expand Up @@ -355,12 +359,14 @@ protected function afterBatchUpdate(Request $request, Model $parentEntity, Colle
* Deletes a batch of relation resources in a transaction-safe way.
*
* @param Request $request
* @param int|string $parentKey
* @param array<int, mixed> $args
* @return CollectionResource
* @throws Exception
*/
public function batchDestroy(Request $request, $parentKey)
public function batchDestroy(Request $request, ...$args)
{
$parentKey = $this->keyResolver->resolveRelationOperationParentKey($request, $args);

try {
$this->startTransaction();
$result = $this->batchDestroyWithTransaction($request, $parentKey);
Expand Down Expand Up @@ -527,12 +533,14 @@ protected function afterBatchDestroy(Request $request, Model $parentEntity, Coll
* Restores a batch of relation resources in a transaction-safe way.
*
* @param Request $request
* @param int|string $parentKey
* @param array<int, mixed> $args
* @return CollectionResource
* @throws Exception
*/
public function batchRestore(Request $request, $parentKey)
public function batchRestore(Request $request, ...$args)
{
$parentKey = $this->keyResolver->resolveRelationOperationParentKey($request, $args);

try {
$this->startTransaction();
$result = $this->batchRestoreWithTransaction($request, $parentKey);
Expand Down

0 comments on commit e47042c

Please sign in to comment.