Server & Client move the tags into a separate branch
This commit is contained in:
parent
57c535afd6
commit
4ac30fd9b5
12 changed files with 102 additions and 105 deletions
|
|
@ -26,8 +26,6 @@ interface LwaClient {
|
|||
alterationId: String,
|
||||
): APIResponse<Unit>
|
||||
|
||||
suspend fun getAlterationTags(): APIResponse<List<TagJson>>
|
||||
|
||||
// Campaign
|
||||
|
||||
suspend fun getCampaign(): APIResponse<CampaignJson>
|
||||
|
|
@ -52,8 +50,6 @@ interface LwaClient {
|
|||
|
||||
suspend fun getCharacters(): APIResponse<List<CharacterPreviewJson>>
|
||||
|
||||
suspend fun getCharacterTags(): APIResponse<List<TagJson>>
|
||||
|
||||
suspend fun getCharacter(
|
||||
characterSheetId: String,
|
||||
): APIResponse<CharacterSheetJson>
|
||||
|
|
@ -87,6 +83,12 @@ interface LwaClient {
|
|||
characterSheetId: String,
|
||||
): APIResponse<Unit>
|
||||
|
||||
// Tags
|
||||
|
||||
suspend fun getAlterationTags(): APIResponse<List<TagJson>>
|
||||
|
||||
suspend fun getCharacterTags(): APIResponse<List<TagJson>>
|
||||
|
||||
companion object {
|
||||
fun error(error: APIResponse<*>): Nothing = throw LwaNetworkException(error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,11 +50,6 @@ class LwaClientImpl(
|
|||
.delete("$root/alteration/delete?alterationId=$alterationId")
|
||||
.body<APIResponse<Unit>>()
|
||||
|
||||
@Throws
|
||||
override suspend fun getAlterationTags(): APIResponse<List<TagJson>> = client
|
||||
.get("$root/alteration/tags")
|
||||
.body()
|
||||
|
||||
@Throws
|
||||
override suspend fun getCampaign(): APIResponse<CampaignJson> = client
|
||||
.get("$root/campaign")
|
||||
|
|
@ -93,11 +88,6 @@ class LwaClientImpl(
|
|||
.get("$root/character/all")
|
||||
.body()
|
||||
|
||||
@Throws
|
||||
override suspend fun getCharacterTags(): APIResponse<List<TagJson>> = 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<APIResponse<Unit>>()
|
||||
|
||||
@Throws
|
||||
override suspend fun getAlterationTags(): APIResponse<List<TagJson>> = client
|
||||
.get("$root/tag/alteration")
|
||||
.body()
|
||||
|
||||
@Throws
|
||||
override suspend fun getCharacterTags(): APIResponse<List<TagJson>> = client
|
||||
.get("$root/tag/character")
|
||||
.body()
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<TagJson> {
|
||||
return tagStore.alterationTags().value.values.toList()
|
||||
}
|
||||
|
||||
@Throws
|
||||
fun save(
|
||||
json: AlterationJson,
|
||||
|
|
|
|||
|
|
@ -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<TagJson> {
|
||||
return alterationTags.value
|
||||
}
|
||||
|
||||
fun charactersJson(): List<CharacterPreviewJson> {
|
||||
return sheets.map { factory.convertToPreviewJson(sheet = it.value) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<TagJson> {
|
||||
return tagStore.itemTags().value.values.toList()
|
||||
}
|
||||
|
||||
@Throws
|
||||
fun save(
|
||||
json: ItemJson,
|
||||
|
|
|
|||
|
|
@ -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<TagJson> {
|
||||
return tagStore.alterationTags().value.values.toList()
|
||||
}
|
||||
|
||||
fun characters(): List<TagJson> {
|
||||
return tagStore.characterTags().value.values.toList()
|
||||
}
|
||||
|
||||
fun items(): List<TagJson> {
|
||||
return tagStore.itemTags().value.values.toList()
|
||||
}
|
||||
}
|
||||
|
|
@ -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<SocketMessage>()
|
||||
|
|
|
|||
|
|
@ -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 = "/update",
|
||||
body = engine.putAlteration()
|
||||
path = "/add",
|
||||
body = engine.putCampaignCharacter(),
|
||||
)
|
||||
delete(
|
||||
path = "/delete",
|
||||
body = engine.deleteAlteration()
|
||||
body = engine.removeCampaignCharacter(),
|
||||
)
|
||||
}
|
||||
route(path = "/npc") {
|
||||
put(
|
||||
path = "/add",
|
||||
body = engine.putCampaignNpc(),
|
||||
)
|
||||
delete(
|
||||
path = "/delete",
|
||||
body = engine.removeCampaignNpc(),
|
||||
)
|
||||
}
|
||||
put(
|
||||
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(),
|
||||
path = "/update",
|
||||
body = engine.putAlteration()
|
||||
)
|
||||
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(),
|
||||
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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
@ -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) {
|
||||
|
|
@ -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) {
|
||||
Loading…
Add table
Add a link
Reference in a new issue