feat: add note module and route fixes
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\note\controller\v1;
|
||||
|
||||
use app\api\common\Response;
|
||||
use app\note\controller\BaseController;
|
||||
use app\note\service\NoteService;
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 笔记控制器
|
||||
*/
|
||||
class Note extends BaseController
|
||||
{
|
||||
/**
|
||||
* @var PlanningService
|
||||
*/
|
||||
protected $noteService;
|
||||
|
||||
public function __construct(App $app)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->noteService = new NoteService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建笔记
|
||||
* POST /note/v1/item/create
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
try {
|
||||
$noteUserId = $this->getCurrentNoteUserId();
|
||||
$data = $this->request->post();
|
||||
|
||||
validate([
|
||||
'source_type' => 'require|in:text,audio,mix',
|
||||
], [
|
||||
'source_type.require' => '笔记来源类型不能为空',
|
||||
'source_type.in' => '笔记来源类型不正确',
|
||||
])->check($data);
|
||||
|
||||
$result = $this->noteService->create($noteUserId, $data);
|
||||
return Response::success($result, '创建成功');
|
||||
} catch (ValidateException $e) {
|
||||
return Response::error($e->getMessage(), 400);
|
||||
} catch (\Throwable $e) {
|
||||
return Response::error($e->getMessage(), $e->getCode() ?: 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 笔记列表
|
||||
* GET /note/v1/item/list
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
$result = $this->noteService->getList($this->getCurrentNoteUserId(), $this->request->get());
|
||||
return Response::success($result);
|
||||
} catch (\Throwable $e) {
|
||||
return Response::error($e->getMessage(), $e->getCode() ?: 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 笔记详情
|
||||
* GET /note/v1/item/:id
|
||||
*/
|
||||
public function read(int $id)
|
||||
{
|
||||
try {
|
||||
$noteUserId = $this->getCurrentNoteUserId();
|
||||
|
||||
if ($id <= 0) {
|
||||
return Response::error('笔记 ID 不正确', 400);
|
||||
}
|
||||
|
||||
$result = $this->noteService->getDetail($noteUserId, $id);
|
||||
return Response::success($result);
|
||||
} catch (\Throwable $e) {
|
||||
return Response::error($e->getMessage(), $e->getCode() ?: 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新笔记
|
||||
* POST /note/v1/item/update/:id
|
||||
*/
|
||||
public function update(int $id)
|
||||
{
|
||||
try {
|
||||
$noteUserId = $this->getCurrentNoteUserId();
|
||||
|
||||
if ($id <= 0) {
|
||||
return Response::error('笔记 ID 不正确', 400);
|
||||
}
|
||||
|
||||
$result = $this->noteService->update($noteUserId, $id, $this->request->post());
|
||||
return Response::success($result, '更新成功');
|
||||
} catch (\Throwable $e) {
|
||||
return Response::error($e->getMessage(), $e->getCode() ?: 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除笔记
|
||||
* POST /note/v1/item/delete/:id
|
||||
*/
|
||||
public function delete(int $id)
|
||||
{
|
||||
try {
|
||||
$noteUserId = $this->getCurrentNoteUserId();
|
||||
|
||||
if ($id <= 0) {
|
||||
return Response::error('笔记 ID 不正确', 400);
|
||||
}
|
||||
|
||||
$result = $this->noteService->delete($noteUserId, $id);
|
||||
return Response::success($result, '删除成功');
|
||||
} catch (\Throwable $e) {
|
||||
return Response::error($e->getMessage(), $e->getCode() ?: 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存实时转写内容
|
||||
* POST /note/v1/item/transcript/:id
|
||||
*/
|
||||
public function transcript(int $id)
|
||||
{
|
||||
try {
|
||||
$noteUserId = $this->getCurrentNoteUserId();
|
||||
$data = $this->request->post();
|
||||
|
||||
if ($id <= 0) {
|
||||
return Response::error('笔记 ID 不正确', 400);
|
||||
}
|
||||
|
||||
validate([
|
||||
'full_text' => 'require',
|
||||
], [
|
||||
'full_text.require' => '转写文本不能为空',
|
||||
])->check($data);
|
||||
|
||||
$result = $this->noteService->saveTranscript($noteUserId, $id, $data);
|
||||
return Response::success($result, '转写保存成功');
|
||||
} catch (ValidateException $e) {
|
||||
return Response::error($e->getMessage(), 400);
|
||||
} catch (\Throwable $e) {
|
||||
return Response::error($e->getMessage(), $e->getCode() ?: 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user