From 4ac30fd9b5e20285a5f216eee142175bddf3fd72 Mon Sep 17 00:00:00 2001 From: "Andres Gomez, Thomas (ITDV RL)" Date: Fri, 4 Apr 2025 13:44:44 +0200 Subject: [PATCH] Server & Client move the tags into a separate branch --- .../desktop/lwa/network/LwaClient.kt | 10 +- .../desktop/lwa/network/LwaClientImpl.kt | 20 ++-- server/src/main/kotlin/Module.kt | 2 + .../lwa/model/alteration/AlterationService.kt | 7 -- .../model/character/CharacterSheetService.kt | 15 --- .../server/lwa/model/item/ItemService.kt | 7 -- .../server/lwa/model/tag/TagService.kt | 19 +++ .../com/pixelized/server/lwa/server/Engine.kt | 2 + .../com/pixelized/server/lwa/server/Server.kt | 113 +++++++++--------- .../{alteration => tag}/GET_AlterationTags.kt | 4 +- .../{character => tag}/GET_CharacterTags.kt | 4 +- .../server/rest/{item => tag}/GET_ItemTags.kt | 4 +- 12 files changed, 102 insertions(+), 105 deletions(-) create mode 100644 server/src/main/kotlin/com/pixelized/server/lwa/model/tag/TagService.kt rename server/src/main/kotlin/com/pixelized/server/lwa/server/rest/{alteration => tag}/GET_AlterationTags.kt (84%) rename server/src/main/kotlin/com/pixelized/server/lwa/server/rest/{character => tag}/GET_CharacterTags.kt (84%) rename server/src/main/kotlin/com/pixelized/server/lwa/server/rest/{item => tag}/GET_ItemTags.kt (85%) diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/network/LwaClient.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/network/LwaClient.kt index bd7dd73..80a3ad1 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/network/LwaClient.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/network/LwaClient.kt @@ -26,8 +26,6 @@ interface LwaClient { alterationId: String, ): APIResponse - suspend fun getAlterationTags(): APIResponse> - // Campaign suspend fun getCampaign(): APIResponse @@ -52,8 +50,6 @@ interface LwaClient { suspend fun getCharacters(): APIResponse> - suspend fun getCharacterTags(): APIResponse> - suspend fun getCharacter( characterSheetId: String, ): APIResponse @@ -87,6 +83,12 @@ interface LwaClient { characterSheetId: String, ): APIResponse + // Tags + + suspend fun getAlterationTags(): APIResponse> + + suspend fun getCharacterTags(): APIResponse> + companion object { fun error(error: APIResponse<*>): Nothing = throw LwaNetworkException(error) } diff --git a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/network/LwaClientImpl.kt b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/network/LwaClientImpl.kt index 9eda911..a24f2da 100644 --- a/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/network/LwaClientImpl.kt +++ b/composeApp/src/commonMain/kotlin/com/pixelized/desktop/lwa/network/LwaClientImpl.kt @@ -50,11 +50,6 @@ class LwaClientImpl( .delete("$root/alteration/delete?alterationId=$alterationId") .body>() - @Throws - override suspend fun getAlterationTags(): APIResponse> = client - .get("$root/alteration/tags") - .body() - @Throws override suspend fun getCampaign(): APIResponse = client .get("$root/campaign") @@ -93,11 +88,6 @@ class LwaClientImpl( .get("$root/character/all") .body() - @Throws - override suspend fun getCharacterTags(): APIResponse> = client - .get("$root/character/tags") - .body() - @Throws override suspend fun getCharacter( characterSheetId: String, @@ -152,4 +142,14 @@ class LwaClientImpl( override suspend fun deleteCharacterSheet(characterSheetId: String) = client .delete("$root/character/delete?characterSheetId=$characterSheetId") .body>() + + @Throws + override suspend fun getAlterationTags(): APIResponse> = client + .get("$root/tag/alteration") + .body() + + @Throws + override suspend fun getCharacterTags(): APIResponse> = client + .get("$root/tag/character") + .body() } \ No newline at end of file diff --git a/server/src/main/kotlin/Module.kt b/server/src/main/kotlin/Module.kt index e71efd5..9be8eb3 100644 --- a/server/src/main/kotlin/Module.kt +++ b/server/src/main/kotlin/Module.kt @@ -6,6 +6,7 @@ import com.pixelized.server.lwa.model.character.CharacterSheetService import com.pixelized.server.lwa.model.character.CharacterSheetStore import com.pixelized.server.lwa.model.item.ItemService import com.pixelized.server.lwa.model.item.ItemStore +import com.pixelized.server.lwa.model.tag.TagService import com.pixelized.server.lwa.model.tag.TagStore import com.pixelized.server.lwa.server.Engine import com.pixelized.shared.lwa.utils.PathProvider @@ -48,4 +49,5 @@ val serviceDependencies singleOf(::CampaignService) singleOf(::AlterationService) singleOf(::ItemService) + singleOf(::TagService) } diff --git a/server/src/main/kotlin/com/pixelized/server/lwa/model/alteration/AlterationService.kt b/server/src/main/kotlin/com/pixelized/server/lwa/model/alteration/AlterationService.kt index d7f8bd3..e450290 100644 --- a/server/src/main/kotlin/com/pixelized/server/lwa/model/alteration/AlterationService.kt +++ b/server/src/main/kotlin/com/pixelized/server/lwa/model/alteration/AlterationService.kt @@ -1,9 +1,7 @@ package com.pixelized.server.lwa.model.alteration -import com.pixelized.server.lwa.model.tag.TagStore import com.pixelized.shared.lwa.model.alteration.AlterationJson import com.pixelized.shared.lwa.model.alteration.AlterationJsonFactory -import com.pixelized.shared.lwa.model.tag.TagJson import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -13,7 +11,6 @@ import kotlinx.coroutines.flow.stateIn class AlterationService( private val alterationStore: AlterationStore, - private val tagStore: TagStore, factory: AlterationJsonFactory, ) { private val scope = CoroutineScope(Dispatchers.IO + Job()) @@ -34,10 +31,6 @@ class AlterationService( return alterationHashFlow.value[alterationId] } - fun tags(): List { - return tagStore.alterationTags().value.values.toList() - } - @Throws fun save( json: AlterationJson, diff --git a/server/src/main/kotlin/com/pixelized/server/lwa/model/character/CharacterSheetService.kt b/server/src/main/kotlin/com/pixelized/server/lwa/model/character/CharacterSheetService.kt index 57d7b92..0298cc4 100644 --- a/server/src/main/kotlin/com/pixelized/server/lwa/model/character/CharacterSheetService.kt +++ b/server/src/main/kotlin/com/pixelized/server/lwa/model/character/CharacterSheetService.kt @@ -1,10 +1,8 @@ package com.pixelized.server.lwa.model.character -import com.pixelized.server.lwa.model.tag.TagStore import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet import com.pixelized.shared.lwa.model.characterSheet.CharacterSheetJson import com.pixelized.shared.lwa.model.characterSheet.factory.CharacterSheetJsonFactory -import com.pixelized.shared.lwa.model.tag.TagJson import com.pixelized.shared.lwa.protocol.rest.CharacterPreviewJson import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -15,7 +13,6 @@ import kotlinx.coroutines.flow.stateIn class CharacterSheetService( private val characterStore: CharacterSheetStore, - private val tagStore: TagStore, private val factory: CharacterSheetJsonFactory, ) { private val scope = CoroutineScope(Dispatchers.IO + Job()) @@ -30,22 +27,10 @@ class CharacterSheetService( initialValue = emptyMap() ) - private val alterationTags = tagStore.characterTags() - .map { it.values.toList() } - .stateIn( - scope = scope, - started = SharingStarted.Eagerly, - initialValue = emptyList() - ) - fun character(characterSheetId: String): CharacterSheet? { return sheets[characterSheetId] } - fun tags(): Collection { - return alterationTags.value - } - fun charactersJson(): List { return sheets.map { factory.convertToPreviewJson(sheet = it.value) } } diff --git a/server/src/main/kotlin/com/pixelized/server/lwa/model/item/ItemService.kt b/server/src/main/kotlin/com/pixelized/server/lwa/model/item/ItemService.kt index 744dd48..b3d1aba 100644 --- a/server/src/main/kotlin/com/pixelized/server/lwa/model/item/ItemService.kt +++ b/server/src/main/kotlin/com/pixelized/server/lwa/model/item/ItemService.kt @@ -1,9 +1,7 @@ package com.pixelized.server.lwa.model.item -import com.pixelized.server.lwa.model.tag.TagStore import com.pixelized.shared.lwa.model.item.ItemJson import com.pixelized.shared.lwa.model.item.factory.ItemJsonFactory -import com.pixelized.shared.lwa.model.tag.TagJson import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -13,7 +11,6 @@ import kotlinx.coroutines.flow.stateIn class ItemService( private val itemStore: ItemStore, - private val tagStore: TagStore, factory: ItemJsonFactory, ) { private val scope = CoroutineScope(Dispatchers.IO + Job()) @@ -34,10 +31,6 @@ class ItemService( return itemHashFlow.value[itemId] } - fun tags(): List { - return tagStore.itemTags().value.values.toList() - } - @Throws fun save( json: ItemJson, diff --git a/server/src/main/kotlin/com/pixelized/server/lwa/model/tag/TagService.kt b/server/src/main/kotlin/com/pixelized/server/lwa/model/tag/TagService.kt new file mode 100644 index 0000000..6b2ecbf --- /dev/null +++ b/server/src/main/kotlin/com/pixelized/server/lwa/model/tag/TagService.kt @@ -0,0 +1,19 @@ +package com.pixelized.server.lwa.model.tag + +import com.pixelized.shared.lwa.model.tag.TagJson + +class TagService( + private val tagStore: TagStore, +) { + fun alterations(): List { + return tagStore.alterationTags().value.values.toList() + } + + fun characters(): List { + return tagStore.characterTags().value.values.toList() + } + + fun items(): List { + return tagStore.itemTags().value.values.toList() + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/com/pixelized/server/lwa/server/Engine.kt b/server/src/main/kotlin/com/pixelized/server/lwa/server/Engine.kt index e10cca9..919bb91 100644 --- a/server/src/main/kotlin/com/pixelized/server/lwa/server/Engine.kt +++ b/server/src/main/kotlin/com/pixelized/server/lwa/server/Engine.kt @@ -4,6 +4,7 @@ import com.pixelized.server.lwa.model.alteration.AlterationService import com.pixelized.server.lwa.model.campaign.CampaignService import com.pixelized.server.lwa.model.character.CharacterSheetService import com.pixelized.server.lwa.model.item.ItemService +import com.pixelized.server.lwa.model.tag.TagService import com.pixelized.shared.lwa.model.campaign.factory.CampaignJsonFactory import com.pixelized.shared.lwa.protocol.websocket.ApiSynchronisation import com.pixelized.shared.lwa.protocol.websocket.CampaignEvent @@ -18,6 +19,7 @@ class Engine( val campaignService: CampaignService, val alterationService: AlterationService, val itemService: ItemService, + val tagService: TagService, val campaignJsonFactory: CampaignJsonFactory, ) { val webSocket = MutableSharedFlow() diff --git a/server/src/main/kotlin/com/pixelized/server/lwa/server/Server.kt b/server/src/main/kotlin/com/pixelized/server/lwa/server/Server.kt index a074acd..0a58ceb 100644 --- a/server/src/main/kotlin/com/pixelized/server/lwa/server/Server.kt +++ b/server/src/main/kotlin/com/pixelized/server/lwa/server/Server.kt @@ -3,7 +3,6 @@ package com.pixelized.server.lwa.server import com.pixelized.server.lwa.server.rest.alteration.deleteAlteration import com.pixelized.server.lwa.server.rest.alteration.getAlteration -import com.pixelized.server.lwa.server.rest.alteration.getAlterationTags import com.pixelized.server.lwa.server.rest.alteration.getAlterations import com.pixelized.server.lwa.server.rest.alteration.putAlteration import com.pixelized.server.lwa.server.rest.campaign.getCampaign @@ -14,7 +13,6 @@ import com.pixelized.server.lwa.server.rest.campaign.removeCampaignCharacter import com.pixelized.server.lwa.server.rest.campaign.removeCampaignNpc import com.pixelized.server.lwa.server.rest.character.deleteCharacter import com.pixelized.server.lwa.server.rest.character.getCharacter -import com.pixelized.server.lwa.server.rest.character.getCharacterTags import com.pixelized.server.lwa.server.rest.character.getCharacters import com.pixelized.server.lwa.server.rest.character.putCharacter import com.pixelized.server.lwa.server.rest.character.putCharacterAlteration @@ -23,9 +21,11 @@ import com.pixelized.server.lwa.server.rest.character.putCharacterDiminished import com.pixelized.server.lwa.server.rest.character.putCharacterFatigue import com.pixelized.server.lwa.server.rest.item.deleteItem import com.pixelized.server.lwa.server.rest.item.getItem -import com.pixelized.server.lwa.server.rest.item.getItemTags import com.pixelized.server.lwa.server.rest.item.getItems import com.pixelized.server.lwa.server.rest.item.putItem +import com.pixelized.server.lwa.server.rest.tag.getAlterationTags +import com.pixelized.server.lwa.server.rest.tag.getCharacterTags +import com.pixelized.server.lwa.server.rest.tag.getItemTags import com.pixelized.shared.lwa.SERVER_PORT import com.pixelized.shared.lwa.protocol.websocket.SocketMessage import com.pixelized.shared.lwa.sharedModuleDependencies @@ -124,29 +124,34 @@ class LocalServer { } } ) - // TODO Tags. - route( - path = "/alteration", - ) { + route(path = "/campaign") { get( - path = "/all", - body = engine.getAlterations(), - ) - get( - path = "/detail", - body = engine.getAlteration(), - ) - get( - path = "/tags", - body = engine.getAlterationTags(), + path = "", + body = engine.getCampaign(), ) + route(path = "/character") { + put( + path = "/add", + body = engine.putCampaignCharacter(), + ) + delete( + path = "/delete", + body = engine.removeCampaignCharacter(), + ) + } + route(path = "/npc") { + put( + path = "/add", + body = engine.putCampaignNpc(), + ) + delete( + path = "/delete", + body = engine.removeCampaignNpc(), + ) + } put( - path = "/update", - body = engine.putAlteration() - ) - delete( - path = "/delete", - body = engine.deleteAlteration() + path = "/scene", + body = engine.putCampaignScene(), ) } route( @@ -156,10 +161,6 @@ class LocalServer { path = "/all", body = engine.getCharacters(), ) - get( - path = "/tags", - body = engine.getCharacterTags(), - ) get( path = "/detail", body = engine.getCharacter(), @@ -193,34 +194,24 @@ class LocalServer { ) } } - route(path = "/campaign") { + route( + path = "/alteration", + ) { get( - path = "", - body = engine.getCampaign(), + path = "/all", + body = engine.getAlterations(), + ) + get( + path = "/detail", + body = engine.getAlteration(), ) - route(path = "/character") { - put( - path = "/add", - body = engine.putCampaignCharacter(), - ) - delete( - path = "/delete", - body = engine.removeCampaignCharacter(), - ) - } - route(path = "/npc") { - put( - path = "/add", - body = engine.putCampaignNpc(), - ) - delete( - path = "/delete", - body = engine.removeCampaignNpc(), - ) - } put( - path = "/scene", - body = engine.putCampaignScene(), + path = "/update", + body = engine.putAlteration() + ) + delete( + path = "/delete", + body = engine.deleteAlteration() ) } route(path = "item") { @@ -232,10 +223,6 @@ class LocalServer { path = "/detail", body = engine.getItem(), ) - get( - path = "/tags", - body = engine.getItemTags(), - ) put( path = "/update", body = engine.putItem(), @@ -245,6 +232,20 @@ class LocalServer { body = engine.deleteItem(), ) } + route(path = "tag") { + get( + path = "/character", + body = engine.getCharacterTags(), + ) + get( + path = "/alteration", + body = engine.getAlterationTags(), + ) + get( + path = "/item", + body = engine.getItemTags(), + ) + } } } ) diff --git a/server/src/main/kotlin/com/pixelized/server/lwa/server/rest/alteration/GET_AlterationTags.kt b/server/src/main/kotlin/com/pixelized/server/lwa/server/rest/tag/GET_AlterationTags.kt similarity index 84% rename from server/src/main/kotlin/com/pixelized/server/lwa/server/rest/alteration/GET_AlterationTags.kt rename to server/src/main/kotlin/com/pixelized/server/lwa/server/rest/tag/GET_AlterationTags.kt index fe86478..8dcaffa 100644 --- a/server/src/main/kotlin/com/pixelized/server/lwa/server/rest/alteration/GET_AlterationTags.kt +++ b/server/src/main/kotlin/com/pixelized/server/lwa/server/rest/tag/GET_AlterationTags.kt @@ -1,4 +1,4 @@ -package com.pixelized.server.lwa.server.rest.alteration +package com.pixelized.server.lwa.server.rest.tag import com.pixelized.server.lwa.server.Engine import com.pixelized.server.lwa.utils.extentions.exception @@ -11,7 +11,7 @@ fun Engine.getAlterationTags(): suspend RoutingContext.() -> Unit { try { call.respond( message = APIResponse.success( - data = alterationService.tags(), + data = tagService.alterations(), ), ) } catch (exception: Exception) { diff --git a/server/src/main/kotlin/com/pixelized/server/lwa/server/rest/character/GET_CharacterTags.kt b/server/src/main/kotlin/com/pixelized/server/lwa/server/rest/tag/GET_CharacterTags.kt similarity index 84% rename from server/src/main/kotlin/com/pixelized/server/lwa/server/rest/character/GET_CharacterTags.kt rename to server/src/main/kotlin/com/pixelized/server/lwa/server/rest/tag/GET_CharacterTags.kt index 8f1b876..932e0d5 100644 --- a/server/src/main/kotlin/com/pixelized/server/lwa/server/rest/character/GET_CharacterTags.kt +++ b/server/src/main/kotlin/com/pixelized/server/lwa/server/rest/tag/GET_CharacterTags.kt @@ -1,4 +1,4 @@ -package com.pixelized.server.lwa.server.rest.character +package com.pixelized.server.lwa.server.rest.tag import com.pixelized.server.lwa.server.Engine import com.pixelized.server.lwa.utils.extentions.exception @@ -11,7 +11,7 @@ fun Engine.getCharacterTags(): suspend RoutingContext.() -> Unit { try { call.respond( message = APIResponse.success( - data = characterService.tags(), + data = tagService.characters(), ), ) } catch (exception: Exception) { diff --git a/server/src/main/kotlin/com/pixelized/server/lwa/server/rest/item/GET_ItemTags.kt b/server/src/main/kotlin/com/pixelized/server/lwa/server/rest/tag/GET_ItemTags.kt similarity index 85% rename from server/src/main/kotlin/com/pixelized/server/lwa/server/rest/item/GET_ItemTags.kt rename to server/src/main/kotlin/com/pixelized/server/lwa/server/rest/tag/GET_ItemTags.kt index bdb959f..7705a66 100644 --- a/server/src/main/kotlin/com/pixelized/server/lwa/server/rest/item/GET_ItemTags.kt +++ b/server/src/main/kotlin/com/pixelized/server/lwa/server/rest/tag/GET_ItemTags.kt @@ -1,4 +1,4 @@ -package com.pixelized.server.lwa.server.rest.item +package com.pixelized.server.lwa.server.rest.tag import com.pixelized.server.lwa.server.Engine import com.pixelized.server.lwa.utils.extentions.exception @@ -11,7 +11,7 @@ fun Engine.getItemTags(): suspend RoutingContext.() -> Unit { try { call.respond( message = APIResponse.success( - data = itemService.tags(), + data = tagService.items(), ), ) } catch (exception: Exception) {