Add map admin feature.
This commit is contained in:
parent
db98fbede7
commit
2b09126650
26 changed files with 1214 additions and 32 deletions
|
|
@ -15,9 +15,11 @@ fun Engine.putMap(): suspend RoutingContext.() -> Unit {
|
|||
return {
|
||||
try {
|
||||
val form = call.receive<MapJson>()
|
||||
val create = call.queryParameters.create
|
||||
|
||||
mapService.save(
|
||||
json = form,
|
||||
create = create,
|
||||
)
|
||||
call.respond(
|
||||
message = APIResponse.success(),
|
||||
|
|
|
|||
|
|
@ -19,9 +19,11 @@ class MapService(
|
|||
@Throws
|
||||
suspend fun save(
|
||||
json: MapJson,
|
||||
create: Boolean,
|
||||
) {
|
||||
mapStore.save(
|
||||
map = json,
|
||||
create = create,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import kotlinx.coroutines.launch
|
|||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.File
|
||||
import java.text.Collator
|
||||
|
||||
class MapStore(
|
||||
private val pathProvider: PathProvider,
|
||||
|
|
@ -74,18 +73,27 @@ class MapStore(
|
|||
}
|
||||
|
||||
@Throws(JsonConversionException::class, FileWriteException::class)
|
||||
suspend fun save(map: MapJson) {
|
||||
// convert the data to json format
|
||||
val json = try {
|
||||
suspend fun save(
|
||||
map: MapJson,
|
||||
create: Boolean,
|
||||
) {
|
||||
val file = mapFile(id = map.id)
|
||||
// Guard case on update alteration
|
||||
if (create && file.exists()) {
|
||||
throw BusinessException(
|
||||
message = "Map already exist, creation is impossible.",
|
||||
)
|
||||
}
|
||||
// Encode the json into a string.
|
||||
val data = try {
|
||||
this.jsonSerializer.encodeToString(map)
|
||||
} catch (exception: Exception) {
|
||||
throw JsonConversionException(root = exception)
|
||||
}
|
||||
// write the file
|
||||
// write the map into a file
|
||||
try {
|
||||
val file = mapFile(id = map.id)
|
||||
file.writeText(
|
||||
text = json,
|
||||
text = data,
|
||||
charset = Charsets.UTF_8,
|
||||
)
|
||||
} catch (exception: Exception) {
|
||||
|
|
@ -105,13 +113,13 @@ class MapStore(
|
|||
// Guard case on the file existence.
|
||||
if (file.exists().not()) {
|
||||
throw BusinessException(
|
||||
message = "Alteration doesn't not exist, deletion is impossible.",
|
||||
message = "Map doesn't not exist, deletion is impossible.",
|
||||
)
|
||||
}
|
||||
// Guard case on the file deletion
|
||||
if (file.delete().not()) {
|
||||
throw BusinessException(
|
||||
message = "Alteration file have not been deleted for unknown reason.",
|
||||
message = "Map file have not been deleted for unknown reason.",
|
||||
)
|
||||
}
|
||||
// Update the data model with the deleted alteration.
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ val Parameters.itemId: String
|
|||
val Parameters.mapId: String
|
||||
get() = param(
|
||||
name = "mapId",
|
||||
code = APIResponse.ErrorCode.ItemId,
|
||||
code = APIResponse.ErrorCode.MapId,
|
||||
)
|
||||
|
||||
val Parameters.count: Float
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue