diff --git a/electron/ipc/character.ipc.ts b/electron/ipc/character.ipc.ts new file mode 100644 index 0000000..96aca07 --- /dev/null +++ b/electron/ipc/character.ipc.ts @@ -0,0 +1,65 @@ +import { ipcMain } from 'electron'; +import { createHandler } from '../database/LocalSystem.js'; +import Character from '../database/models/Character.js'; +import type { CharacterProps, CharacterPropsPost, CharacterAttribute } from '../database/models/Character.js'; + +interface AddCharacterData { + character: CharacterPropsPost; + bookId: string; +} + +interface AddAttributeData { + characterId: string; + type: string; + name: string; +} + +// GET /character/list - Get character list +ipcMain.handle('db:character:list', createHandler( + function(userId: string, bookId: string, lang: 'fr' | 'en'): CharacterProps[] { + return Character.getCharacterList(userId, bookId, lang); + } + ) +); + +// GET /character/attribute - Get character attributes +ipcMain.handle('db:character:attributes', createHandler( + function(userId: string, characterId: string, lang: 'fr' | 'en'): CharacterAttribute[] { + return Character.getAttributes(characterId, userId, lang); + } + ) +); + +// POST /character/add - Add new character +ipcMain.handle('db:character:create', createHandler( + function(userId: string, data: AddCharacterData, lang: 'fr' | 'en'): string { + return Character.addNewCharacter(userId, data.character, data.bookId, lang); + } + ) +); + +// POST /character/attribute/add - Add attribute to character +ipcMain.handle('db:character:attribute:add', createHandler( + function(userId: string, data: AddAttributeData, lang: 'fr' | 'en'): string { + return Character.addNewAttribute(data.characterId, userId, data.type, data.name, lang); + } + ) +); + +// DELETE /character/attribute/delete - Delete character attribute +ipcMain.handle('db:character:attribute:delete', createHandler( + function(userId: string, attributeId: string, lang: 'fr' | 'en') { + return Character.deleteAttribute(userId, attributeId, lang); + } + ) +); + +// POST /character/update - Update character +ipcMain.handle('db:character:update', createHandler( + function(userId: string, character: CharacterPropsPost, lang: 'fr' | 'en'): boolean { + return Character.updateCharacter(userId, character, lang); + } + ) +); + +console.log('[IPC] Character handlers registered'); diff --git a/electron/ipc/location.ipc.ts b/electron/ipc/location.ipc.ts new file mode 100644 index 0000000..e4d3d43 --- /dev/null +++ b/electron/ipc/location.ipc.ts @@ -0,0 +1,89 @@ +import { ipcMain } from 'electron'; +import { createHandler } from '../database/LocalSystem.js'; +import Location from '../database/models/Location.js'; +import type { LocationProps } from '../database/models/Location.js'; + +interface AddLocationSectionData { + locationName: string; + bookId: string; +} + +interface AddLocationElementData { + locationId: string; + elementName: string; +} + +interface AddLocationSubElementData { + elementId: string; + subElementName: string; +} + +interface UpdateLocationData { + locations: LocationProps[]; +} + +// GET /location/all - Get all locations +ipcMain.handle('db:location:all', createHandler( + function(userId: string, bookId: string, lang: 'fr' | 'en'): LocationProps[] { + return Location.getAllLocations(userId, bookId, lang); + } + ) +); + +// POST /location/section/add - Add location section +ipcMain.handle('db:location:section:add', createHandler( + function(userId: string, data: AddLocationSectionData, lang: 'fr' | 'en'): string { + return Location.addLocationSection(userId, data.locationName, data.bookId, lang); + } + ) +); + +// POST /location/element/add - Add location element +ipcMain.handle('db:location:element:add', createHandler( + function(userId: string, data: AddLocationElementData, lang: 'fr' | 'en') { + return Location.addLocationElement(userId, data.locationId, data.elementName, lang); + } + ) +); + +// POST /location/sub-element/add - Add location sub-element +ipcMain.handle('db:location:subelement:add', createHandler( + function(userId: string, data: AddLocationSubElementData, lang: 'fr' | 'en') { + return Location.addLocationSubElement(userId, data.elementId, data.subElementName, lang); + } + ) +); + +// POST /location/update - Update location section +ipcMain.handle('db:location:update', createHandler( + function(userId: string, data: UpdateLocationData, lang: 'fr' | 'en') { + return Location.updateLocationSection(userId, data.locations, lang); + } + ) +); + +// DELETE /location/delete - Delete location section +ipcMain.handle('db:location:delete', createHandler( + function(userId: string, locationId: string, lang: 'fr' | 'en') { + return Location.deleteLocationSection(userId, locationId, lang); + } + ) +); + +// DELETE /location/element/delete - Delete location element +ipcMain.handle('db:location:element:delete', createHandler( + function(userId: string, elementId: string, lang: 'fr' | 'en') { + return Location.deleteLocationElement(userId, elementId, lang); + } + ) +); + +// DELETE /location/sub-element/delete - Delete location sub-element +ipcMain.handle('db:location:subelement:delete', createHandler( + function(userId: string, subElementId: string, lang: 'fr' | 'en') { + return Location.deleteLocationSubElement(userId, subElementId, lang); + } + ) +); + +console.log('[IPC] Location handlers registered'); diff --git a/electron/main.ts b/electron/main.ts index 81e105d..169c941 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -10,6 +10,8 @@ import { getDatabaseService } from './database/database.service.js'; import './ipc/book.ipc.js'; import './ipc/user.ipc.js'; import './ipc/chapter.ipc.js'; +import './ipc/character.ipc.js'; +import './ipc/location.ipc.js'; // Fix pour __dirname en ES modules const __filename = fileURLToPath(import.meta.url);