Skip to content

Commit

Permalink
feat: delete & update api template
Browse files Browse the repository at this point in the history
  • Loading branch information
slowlyo committed Mar 25, 2024
1 parent c575690 commit da58ee2
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/AdminServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
use Psr\Container\ContainerExceptionInterface;
use Slowlyo\OwlAdmin\Models\PersonalAccessToken;
use Slowlyo\OwlAdmin\Support\{Apis\DataCreateApi,
Apis\DataDeleteApi,
Apis\DataDetailApi,
Apis\DataListApi,
Apis\DataUpdateApi,
Context,
Cores\Menu,
Cores\Asset,
Expand Down Expand Up @@ -213,6 +215,8 @@ protected function loadApis()
DataListApi::class,
DataCreateApi::class,
DataDetailApi::class,
DataDeleteApi::class,
DataUpdateApi::class,
]);
}
}
42 changes: 42 additions & 0 deletions src/Support/Apis/DataDeleteApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Slowlyo\OwlAdmin\Support\Apis;

/**
* 删除数据
*/
class DataDeleteApi extends AdminBaseApi
{
public string $method = 'delete';

public function getTitle()
{
return __('admin.api_templates.data_delete');
}

public function handle()
{
return $this->service()->delete(request($this->getArgs('primary_key', 'ids')));
}

public function argsSchema()
{
return [
amis()->SelectControl('model', __('admin.relationships.model'))
->required()
->menuTpl('${label} <span class="text-gray-300 pl-2">${table}</span>')
->source('/dev_tools/relation/model_options')
->searchable(),
amis()->TextControl('primary_id', __('admin.code_generators.primary_key'))->value('ids'),
];
}

protected function service()
{
$service = $this->blankService();

$service->setModelName($this->getArgs('model'));

return $service;
}
}
42 changes: 42 additions & 0 deletions src/Support/Apis/DataUpdateApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Slowlyo\OwlAdmin\Support\Apis;

/**
* 数据更新
*/
class DataUpdateApi extends AdminBaseApi
{
public string $method = 'put';

public function getTitle()
{
return __('admin.api_templates.data_update');
}

public function handle()
{
return $this->service()->update(request($this->getArgs('primary_key', 'id')), request()->all());
}

public function argsSchema()
{
return [
amis()->SelectControl('model', __('admin.relationships.model'))
->required()
->menuTpl('${label} <span class="text-gray-300 pl-2">${table}</span>')
->source('/dev_tools/relation/model_options')
->searchable(),
amis()->TextControl('primary_id', __('admin.code_generators.primary_key'))->value('id'),
];
}

protected function service()
{
$service = $this->blankService();

$service->setModelName($this->getArgs('model'));

return $service;
}
}

0 comments on commit da58ee2

Please sign in to comment.