Tag syncing is now done within the Component commands

This commit is contained in:
James Brooks
2019-07-12 10:29:23 +01:00
parent 06af61b8c5
commit 6810af48f7
10 changed files with 197 additions and 64 deletions

View File

@@ -84,25 +84,13 @@ class ComponentController extends AbstractApiController
Binput::get('order'),
Binput::get('group_id'),
(bool) Binput::get('enabled', true),
Binput::get('meta', null)
Binput::get('meta'),
Binput::get('tags'),
));
} catch (QueryException $e) {
throw new BadRequestHttpException();
}
if (Binput::has('tags')) {
$component->tags()->delete();
// The component was added successfully, so now let's deal with the tags.
Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
return trim($tag);
})->map(function ($tag) {
return execute(new CreateTagCommand($tag));
})->each(function ($tag) use ($component) {
execute(new ApplyTagCommand($component, $tag));
});
}
return $this->item($component);
}
@@ -125,26 +113,14 @@ class ComponentController extends AbstractApiController
Binput::get('order'),
Binput::get('group_id'),
Binput::get('enabled', $component->enabled),
Binput::get('meta', null),
Binput::get('meta'),
Binput::get('tags'),
(bool) Binput::get('silent', false)
));
} catch (QueryException $e) {
throw new BadRequestHttpException();
}
if (Binput::has('tags')) {
$component->tags()->delete();
// The component was added successfully, so now let's deal with the tags.
Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
return trim($tag);
})->map(function ($tag) {
return execute(new CreateTagCommand($tag));
})->each(function ($tag) use ($component) {
execute(new ApplyTagCommand($component, $tag));
});
}
return $this->item($component);
}