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); } } /** * 上传笔记录音 * POST /note/v1/item/audio/:id */ public function audio(Request $request, int $id) { try { if ($id <= 0) { return Response::error('笔记 ID 不正确', 400); } $file = $request->file('audio'); if (!$file) { return Response::error('录音文件不能为空', 400); } $durationMs = (int) $request->post('audio_duration_ms', 0); $result = $this->noteService->uploadAudio($this->getCurrentNoteUserId(), $id, $file, $durationMs); return Response::success($result, '上传成功'); } catch (\Throwable $e) { return Response::error($e->getMessage(), $e->getCode() ?: 500); } } }