99 lines
2.4 KiB
PHP
99 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller;
|
|
|
|
use Aether\AetherController;
|
|
use Aether\AetherCrudService;
|
|
use Aether\AetherResponse;
|
|
use App\JsonRpc\Service\CampusService;
|
|
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 CampusController extends AetherController
|
|
{
|
|
#[Inject]
|
|
protected CampusService $service;
|
|
|
|
#[Inject]
|
|
protected RequestInterface $request;
|
|
/**
|
|
* 校区列表.
|
|
*/
|
|
#[GetMapping(path: 'campus/list')]
|
|
public function list(RequestInterface $request): array
|
|
{
|
|
return AetherResponse::success($this->service->list($request->all()));
|
|
}
|
|
|
|
/**
|
|
* 获取省份列表.
|
|
*/
|
|
#[GetMapping(path: 'campus/provinces')]
|
|
public function provinces(): array
|
|
{
|
|
return AetherResponse::success($this->service->getProvinces());
|
|
}
|
|
|
|
/**
|
|
* 获取城市列表.
|
|
*/
|
|
#[GetMapping(path: 'campus/cities')]
|
|
public function cities(RequestInterface $request): array
|
|
{
|
|
return AetherResponse::success($this->service->getCitiesByProvince($request->input('province_id')));
|
|
}
|
|
|
|
/**
|
|
* 创建校区.
|
|
* @throws Throwable
|
|
*/
|
|
#[PostMapping(path: 'campus')]
|
|
public function create(): array
|
|
{
|
|
return AetherResponse::success($this->service->create($this->request->all()), '校区创建成功');
|
|
}
|
|
|
|
/**
|
|
* 获取校区详情.
|
|
*/
|
|
#[GetMapping(path: 'campus/{id}')]
|
|
public function get(int $id): array
|
|
{
|
|
return AetherResponse::success($this->service->detail($id));
|
|
}
|
|
|
|
/**
|
|
* 更新校区.
|
|
* @throws Throwable
|
|
*/
|
|
#[PutMapping(path: 'campus/{id}')]
|
|
public function update(int $id): array
|
|
{
|
|
return AetherResponse::success($this->service->update($id, $this->request->all()), '校区更新成功');
|
|
}
|
|
|
|
/**
|
|
* 删除校区.
|
|
* @throws Throwable
|
|
*/
|
|
#[DeleteMapping(path: 'campus/{id}')]
|
|
public function delete(int $id): array
|
|
{
|
|
return AetherResponse::success($this->service->delete($id), '校区删除成功');
|
|
}
|
|
|
|
protected function getService(): AetherCrudService
|
|
{
|
|
return $this->service;
|
|
}
|
|
}
|