初始化项目
This commit is contained in:
59
app/Http/Controllers/System/Api/Dictionary.php
Normal file
59
app/Http/Controllers/System/Api/Dictionary.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\System\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\System\DictionaryService;
|
||||
|
||||
class Dictionary extends Controller
|
||||
{
|
||||
protected $dictionaryService;
|
||||
|
||||
public function __construct(DictionaryService $dictionaryService)
|
||||
{
|
||||
$this->dictionaryService = $dictionaryService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$dictionaries = $this->dictionaryService->getAll();
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'message' => 'success',
|
||||
'data' => $dictionaries
|
||||
]);
|
||||
}
|
||||
|
||||
public function getByCode(Request $request)
|
||||
{
|
||||
$code = $request->input('code');
|
||||
$items = $this->dictionaryService->getItemsByCode($code);
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'message' => 'success',
|
||||
'data' => [
|
||||
'code' => $code,
|
||||
'items' => $items,
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(int $id)
|
||||
{
|
||||
$dictionary = $this->dictionaryService->getById($id);
|
||||
if (!$dictionary) {
|
||||
return response()->json([
|
||||
'code' => 404,
|
||||
'message' => '字典不存在',
|
||||
'data' => null
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'message' => 'success',
|
||||
'data' => $dictionary
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user