VersionController.php 2.3 KB
<?php

namespace App\Http\Container\AdminSection\Controllers\System;

use App\Helpers\OperationLog;
use App\Http\Container\AdminSection\Requests\System\VersionRequest;
use App\Models\AppVersion;
use Auth;
use Hikoon\LaravelApi\Facades\Response;
use Hikoon\LaravelApi\Support\ApiCode;
use Hikoon\LaravelApi\Support\ApiController;
use Illuminate\Http\Request;

class VersionController extends ApiController
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return \Hikoon\LaravelApi\Facades\Response
     */
    public function index(Request $request): Response
    {
        $pageSize = $request->get('pageSize', 20);
        $filter   = $request->except(['page', 'pageSize']);
        $data     = AppVersion::filter($filter)->paginate($pageSize);
        return $this->successWithData($data);
    }

    /**
     * @param \App\Http\Container\AdminSection\Requests\System\VersionRequest $request
     * @return \Hikoon\LaravelApi\Facades\Response
     */
    public function store(VersionRequest $request): Response
    {
        $version = AppVersion::query()->create($request->safe()->merge(['user_id' => Auth::id()])->toArray());
        OperationLog::admin()->createAction()->subject($version)->content('App版本《%s》', $version->getAttribute('app_ver'));
        return $this->successWithData($version, ApiCode::CREATE_SUCCESS);
    }

    /**
     * @param \App\Http\Container\AdminSection\Requests\System\VersionRequest $request
     * @param \App\Models\AppVersion                                          $version
     * @return \Hikoon\LaravelApi\Facades\Response
     */
    public function update(VersionRequest $request, AppVersion $version): Response
    {
        $version->update($request->safe()->toArray());
        OperationLog::admin()->updateAction()->subject($version)->content('App版本《%s》', $version->getAttribute('app_ver'));

        return $this->successWithData($version, ApiCode::UPDATE_SUCCESS);
    }


    /**
     * @param \App\Models\AppVersion $version
     * @return \Hikoon\LaravelApi\Facades\Response
     */
    public function destroy(AppVersion $version): Response
    {
        $version->delete();
        OperationLog::admin()->deleteAction()->subject($version)->content('App版本《%s》', $version->getAttribute('app_ver'));
        return $this->success(ApiCode::DELETE_SUCCESS);
    }
}