82 lines
2.0 KiB
PHP
82 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller;
|
|
|
|
use Aether\AetherController;
|
|
use Aether\AetherCrudService;
|
|
use Aether\AetherResponse;
|
|
use App\JsonRpc\Service\TeacherService;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Hyperf\HttpServer\Annotation\Controller;
|
|
use Hyperf\HttpServer\Annotation\DeleteMapping;
|
|
use Hyperf\HttpServer\Annotation\GetMapping;
|
|
use Hyperf\HttpServer\Annotation\PostMapping;
|
|
use Hyperf\HttpServer\Annotation\PutMapping;
|
|
use Hyperf\HttpServer\Contract\RequestInterface;
|
|
use Throwable;
|
|
|
|
#[Controller(prefix: '/api/v1')]
|
|
class TeacherController extends AetherController
|
|
{
|
|
#[Inject]
|
|
protected TeacherService $service;
|
|
|
|
#[Inject]
|
|
protected RequestInterface $request;
|
|
|
|
protected function getService(): AetherCrudService
|
|
{
|
|
return $this->service;
|
|
}
|
|
|
|
/**
|
|
* 教师列表.
|
|
*/
|
|
#[GetMapping(path: 'teacher/list')]
|
|
public function list(RequestInterface $request): array
|
|
{
|
|
return AetherResponse::success($this->service->list($request->all()));
|
|
}
|
|
|
|
/**
|
|
* 创建教师.
|
|
* @throws Throwable
|
|
*/
|
|
#[PostMapping(path: 'teacher')]
|
|
public function create(): array
|
|
{
|
|
return AetherResponse::success($this->service->create($this->request->all()), '教师创建成功');
|
|
}
|
|
|
|
/**
|
|
* 获取教师详情.
|
|
*/
|
|
#[GetMapping(path: 'teacher/{id}')]
|
|
public function get(int $id): array
|
|
{
|
|
return AetherResponse::success($this->service->detail($id));
|
|
}
|
|
|
|
/**
|
|
* 更新教师.
|
|
* @throws Throwable
|
|
*/
|
|
#[PutMapping(path: 'teacher/{id}')]
|
|
public function update(int $id): array
|
|
{
|
|
return AetherResponse::success($this->service->update($id, $this->request->all()), '教师更新成功');
|
|
}
|
|
|
|
/**
|
|
* 删除教师.
|
|
* @throws Throwable
|
|
*/
|
|
#[DeleteMapping(path: 'teacher/{id}')]
|
|
public function delete(int $id): array
|
|
{
|
|
return AetherResponse::success($this->service->delete($id), '教师删除成功');
|
|
}
|
|
}
|