..
This commit is contained in:
@@ -8,6 +8,7 @@ use Hyperf\Contract\ContainerInterface;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
use Hyperf\HttpServer\Contract\ResponseInterface;
|
||||
use Throwable;
|
||||
|
||||
abstract class AetherController
|
||||
{
|
||||
@@ -41,6 +42,7 @@ abstract class AetherController
|
||||
|
||||
/**
|
||||
* 创建资源 (RESTFul: POST resources).
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function create(): array
|
||||
{
|
||||
@@ -51,6 +53,7 @@ abstract class AetherController
|
||||
|
||||
/**
|
||||
* 更新资源 (RESTFul: PUT resources/{id}).
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function update(int $id): array
|
||||
{
|
||||
@@ -61,6 +64,7 @@ abstract class AetherController
|
||||
|
||||
/**
|
||||
* 删除资源 (RESTFul: DELETE resources/{id}).
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function delete(int $id): array
|
||||
{
|
||||
|
||||
@@ -6,10 +6,6 @@ namespace Aether;
|
||||
|
||||
class AetherResponse
|
||||
{
|
||||
public const SUCCESS = 0;
|
||||
|
||||
public const ERROR = 1;
|
||||
|
||||
/**
|
||||
* 成功响应.
|
||||
* @param null|mixed $data 数据
|
||||
@@ -18,10 +14,9 @@ class AetherResponse
|
||||
public static function success(mixed $data = null, string $message = '操作成功'): array
|
||||
{
|
||||
return [
|
||||
'code' => self::SUCCESS,
|
||||
'message' => $message,
|
||||
'data' => $data,
|
||||
'timestamp' => time(),
|
||||
Config::RESPONSE_FIELD_KEY_DATA => $data,
|
||||
Config::RESPONSE_FIELD_KEY_CODE => Config::RESPONSE_SUCCESS_CODE,
|
||||
Config::RESPONSE_FIELD_KEY_MESSAGE => $message ?: Config::RESPONSE_SUCCESS_MESSAGE,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -31,29 +26,27 @@ class AetherResponse
|
||||
* @param string $message 错误消息
|
||||
* @param null|mixed $data 附加数据
|
||||
*/
|
||||
public static function error(string $message = '', int $code = self::ERROR, mixed $data = null): array
|
||||
public static function error(string $message = '', int $code = Config::RESPONSE_FAIL_CODE, mixed $data = null): array
|
||||
{
|
||||
return [
|
||||
'code' => $code,
|
||||
'message' => $message ?: self::getDefaultMessage($code),
|
||||
'data' => $data,
|
||||
'timestamp' => time(),
|
||||
Config::RESPONSE_FIELD_KEY_CODE => $code,
|
||||
Config::RESPONSE_FIELD_KEY_DATA => $data,
|
||||
Config::RESPONSE_FIELD_KEY_MESSAGE => $message ?: self::getDefaultMessage($code),
|
||||
];
|
||||
}
|
||||
|
||||
public static function page($list, int $total, int $page, int $size): array
|
||||
{
|
||||
return [
|
||||
'code' => self::SUCCESS,
|
||||
'message' => 'success',
|
||||
'data' => [
|
||||
Config::RESPONSE_FIELD_KEY_CODE => Config::RESPONSE_SUCCESS_CODE,
|
||||
Config::RESPONSE_FIELD_KEY_MESSAGE => 'success',
|
||||
Config::RESPONSE_FIELD_KEY_LIST => [
|
||||
'list' => $list,
|
||||
'page' => $page,
|
||||
'size' => $size,
|
||||
'total' => $total,
|
||||
'pages' => (int) ceil($total / $size),
|
||||
],
|
||||
'timestamp' => time(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,14 @@ class Config
|
||||
public const RESPONSE_FIELD_KEY_DATA = 'data';
|
||||
|
||||
public const RESPONSE_FIELD_KEY_MESSAGE = 'message';
|
||||
|
||||
public const RESPONSE_FIELD_KEY_LIST = 'list';
|
||||
|
||||
public const RESPONSE_SUCCESS_CODE = 200;
|
||||
|
||||
public const RESPONSE_SUCCESS_MESSAGE = 'success';
|
||||
|
||||
public const RESPONSE_FAIL_CODE = -1;
|
||||
|
||||
public const RESPONSE_FAIL_MESSAGE = 'fail';
|
||||
}
|
||||
|
||||
@@ -18,24 +18,6 @@ interface DataServiceInterface
|
||||
|
||||
public function deleteCampus(int $id): bool;
|
||||
|
||||
/**
|
||||
* 获取校区详情.
|
||||
* @param int $id 校区ID
|
||||
*/
|
||||
public function getCampusById(int $id): array;
|
||||
|
||||
/**
|
||||
* 批量获取校区信息.
|
||||
* @param array $ids 校区ID列表
|
||||
*/
|
||||
public function getCampusesByIds(array $ids): array;
|
||||
|
||||
/**
|
||||
* 根据父ID获取子校区.
|
||||
* @param int $parentId 父级ID
|
||||
*/
|
||||
public function getCampusesByParentId(int $parentId): array;
|
||||
|
||||
/**
|
||||
* 获取省份列表.
|
||||
*/
|
||||
@@ -49,7 +31,7 @@ interface DataServiceInterface
|
||||
|
||||
// ----------------- 教师服务 -----------------
|
||||
|
||||
public function getTeachers(): array;
|
||||
public function getTeachers(array $data): array;
|
||||
|
||||
public function getTeacherBy(int $id): array;
|
||||
|
||||
@@ -58,40 +40,4 @@ interface DataServiceInterface
|
||||
public function updateTeacher(int $id, array $data): int;
|
||||
|
||||
public function deleteTeacher(int $id): bool;
|
||||
|
||||
/**
|
||||
* 获取教师详情.
|
||||
* @param int $id 教师ID
|
||||
*/
|
||||
public function getTeacherById(int $id): array;
|
||||
|
||||
/**
|
||||
* 批量获取教师信息.
|
||||
* @param array $ids 教师ID列表
|
||||
*/
|
||||
public function getTeachersByIds(array $ids): array;
|
||||
|
||||
/**
|
||||
* 根据校区获取教师列表.
|
||||
* @param int $campusId 校区ID
|
||||
* @param int $page 页码
|
||||
* @param int $size 每页条数
|
||||
*/
|
||||
public function getTeachersByCampusId(int $campusId, int $page = 1, int $size = 20): array;
|
||||
|
||||
/**
|
||||
* 根据科目获取教师列表.
|
||||
* @param string $subject 科目名称
|
||||
* @param int $page 页码
|
||||
* @param int $size 每页条数
|
||||
*/
|
||||
public function getTeachersBySubject(string $subject, int $page = 1, int $size = 20): array;
|
||||
|
||||
/**
|
||||
* 搜索教师.
|
||||
* @param string $keyword 搜索关键词
|
||||
* @param int $page 页码
|
||||
* @param int $size 每页条数
|
||||
*/
|
||||
public function searchTeachers(string $keyword, int $page = 1, int $size = 20): array;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user