// src/main/ipc/memo-handlers.ts // Phase 10.3: 음성 메모 태그 IPC 핸들러 import { ipcMain } from 'electron' import { IPC_CHANNELS } from '@shared/ipc-channels' import { ipcSuccess, ipcError, ErrorCode, D3ROError } from '@shared/errors' import { getMemoService } from '../services/MemoService' import type { GetTagsParams, AddTagParams, RemoveTagParams, SearchByTagParams, ExportMemoParams } from '@shared/types' export function registerMemoHandlers(): void { ipcMain.handle(IPC_CHANNELS.MEMO.GET_TAGS, async (_event, params: GetTagsParams) => { try { return ipcSuccess(getMemoService().getTagsForEntry(params.historyId)) } catch { return ipcError(ErrorCode.DBQueryFailed, 'Failed to get tags for history entry') } }) ipcMain.handle(IPC_CHANNELS.MEMO.ADD_TAG, async (_event, params: AddTagParams) => { try { return ipcSuccess(getMemoService().addTag(params.historyId, params.tag)) } catch (err) { if (err instanceof D3ROError && err.code === ErrorCode.MemoTagDuplicate) { return ipcError(ErrorCode.MemoTagDuplicate, err.message) } return ipcError(ErrorCode.DBWriteFailed, 'Failed to add tag') } }) ipcMain.handle(IPC_CHANNELS.MEMO.REMOVE_TAG, async (_event, params: RemoveTagParams) => { try { getMemoService().removeTag(params.historyId, params.tag) return ipcSuccess(undefined) } catch (err) { if (err instanceof D3ROError && err.code === ErrorCode.MemoTagNotFound) { return ipcError(ErrorCode.MemoTagNotFound, err.message) } return ipcError(ErrorCode.DBWriteFailed, 'Failed to remove tag') } }) ipcMain.handle(IPC_CHANNELS.MEMO.GET_ALL_TAGS, async () => { try { return ipcSuccess(getMemoService().getAllTags()) } catch { return ipcError(ErrorCode.DBQueryFailed, 'Failed to get all tags') } }) ipcMain.handle(IPC_CHANNELS.MEMO.SEARCH_BY_TAG, async (_event, params: SearchByTagParams) => { try { return ipcSuccess(getMemoService().searchByTag(params)) } catch { return ipcError(ErrorCode.DBQueryFailed, 'Failed to search by tag') } }) ipcMain.handle(IPC_CHANNELS.MEMO.EXPORT, async (_event, params: ExportMemoParams) => { try { return ipcSuccess(getMemoService().exportMarkdown(params)) } catch (err) { if (err instanceof D3ROError && err.code === ErrorCode.MemoExportFailed) { return ipcError(ErrorCode.MemoExportFailed, err.message) } return ipcError(ErrorCode.MemoExportFailed, 'Failed to export memo') } }) }