PushConfigController.php
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace App\Http\Container\AdminSection\Controllers\System\Broker;
use App\Helpers\OperationLog;
use App\Http\Container\AdminSection\Requests\System\BrokerPushConfigRequest;
use App\Models\BrokerPushConfig;
use Auth;
use Hikoon\LaravelApi\Facades\Response;
use Hikoon\LaravelApi\Support\ApiCode;
use Hikoon\LaravelApi\Support\ApiController;
use Illuminate\Http\Request;
use Str;
class PushConfigController extends ApiController
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return \Hikoon\LaravelApi\Facades\Response
     */
    public function index(Request $request): Response
    {
        $pageSize  = $request->get('pageSize', 20);
        $fetchType = $request->get('fetchType', 'page');
        $filter    = $request->except(['page', 'pageSize', 'fetchType']);
        $build     = BrokerPushConfig::query()->filter($filter);
        if ($fetchType === 'all') {
            return $this->successWithData($build->get());
        }
        return $this->successWithData($build->paginate($pageSize));
    }
    /**
     * @param \App\Http\Container\AdminSection\Requests\System\BrokerPushConfigRequest $request
     * @return \Hikoon\LaravelApi\Facades\Response
     */
    public function store(BrokerPushConfigRequest $request): Response
    {
        $config = BrokerPushConfig::query()->create($request->safe()->merge(['user_id' => Auth::id()])->toArray());
        OperationLog::admin()->subject($config)->createAction()->content('推送配置《%s》', Str::limit($config->getAttribute('identifier')));
        return $this->successWithData($config, ApiCode::CREATE_SUCCESS);
    }
    /**
     * @param \App\Http\Container\AdminSection\Requests\System\BrokerPushConfigRequest $request
     * @param \App\Models\BrokerPushConfig                                             $pushConfig
     * @return \Hikoon\LaravelApi\Facades\Response
     */
    public function update(BrokerPushConfigRequest $request, BrokerPushConfig $pushConfig): Response
    {
        $pushConfig->update($request->safe()->toArray());
        OperationLog::admin()->subject($pushConfig)->updateAction()->content('推送配置《%s》', Str::limit($pushConfig->getAttribute('identifier')));
        return $this->successWithData($pushConfig, ApiCode::UPDATE_SUCCESS);
    }
    /**
     * @param \App\Models\BrokerPushConfig $pushConfig
     * @return \Hikoon\LaravelApi\Facades\Response
     */
    public function destroy(BrokerPushConfig $pushConfig): Response
    {
        $pushConfig->delete();
        OperationLog::admin()->subject($pushConfig)->deleteAction()->content('推送配置《%s》', Str::limit($pushConfig->getAttribute('identifier')));
        return $this->success(ApiCode::DELETE_SUCCESS);
    }
}