fix: Server-App WebSocket-Kompatibilität und DELETE-Route
- WebSocketManager: inventory_updated -> inventoryUpdated,
full_sync_required -> fullSyncRequired (camelCase wie App erwartet)
- InventoryRoutes: DELETE /api/inventory/items/{id} hinzugefügt
- InventoryRepository: deleteItem(inventoryId, itemId) implementiert
This commit is contained in:
parent
2d4ebd63b0
commit
2555a942ec
3 changed files with 27 additions and 2 deletions
|
|
@ -203,4 +203,13 @@ internal class InventoryRepository {
|
||||||
updated > 0
|
updated > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun deleteItem(inventoryId: String, itemId: String): Boolean {
|
||||||
|
return transaction {
|
||||||
|
val deleted = Items.deleteWhere {
|
||||||
|
(Items.id eq itemId) and (Items.inventoryId eq inventoryId)
|
||||||
|
}
|
||||||
|
deleted > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,22 @@ internal fun Route.inventoryRoutes(
|
||||||
call.respond(HttpStatusCode.OK, item)
|
call.respond(HttpStatusCode.OK, item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete("/items/{id}") {
|
||||||
|
val userId = call.principal<UserPrincipal>()?.userId
|
||||||
|
?: return@delete call.respond(HttpStatusCode.Unauthorized, ErrorResponse(status = 401, message = "Unauthorized"))
|
||||||
|
val inventoryId = repository.getEffectiveInventoryId(userId)
|
||||||
|
val itemId = call.parameters["id"] ?: return@delete call.respond(
|
||||||
|
HttpStatusCode.BadRequest, ErrorResponse(status = 400, message = "Missing item id")
|
||||||
|
)
|
||||||
|
val deleted = repository.deleteItem(inventoryId, itemId)
|
||||||
|
if (!deleted) {
|
||||||
|
call.respond(HttpStatusCode.NotFound, ErrorResponse(status = 404, message = "Item not found"))
|
||||||
|
} else {
|
||||||
|
wsManager.notifyInventoryUpdated(userId, itemId)
|
||||||
|
call.respond(HttpStatusCode.NoContent)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ internal class WebSocketManager {
|
||||||
|
|
||||||
suspend fun notifyInventoryUpdated(userId: String, itemId: String) {
|
suspend fun notifyInventoryUpdated(userId: String, itemId: String) {
|
||||||
val payload = buildJsonObject {
|
val payload = buildJsonObject {
|
||||||
put("type", "inventory_updated")
|
put("type", "inventoryUpdated")
|
||||||
put("itemId", itemId)
|
put("itemId", itemId)
|
||||||
put("timestamp", System.currentTimeMillis())
|
put("timestamp", System.currentTimeMillis())
|
||||||
}
|
}
|
||||||
|
|
@ -35,7 +35,7 @@ internal class WebSocketManager {
|
||||||
|
|
||||||
suspend fun notifyFullSyncRequired(userId: String) {
|
suspend fun notifyFullSyncRequired(userId: String) {
|
||||||
val payload = buildJsonObject {
|
val payload = buildJsonObject {
|
||||||
put("type", "full_sync_required")
|
put("type", "fullSyncRequired")
|
||||||
put("timestamp", System.currentTimeMillis())
|
put("timestamp", System.currentTimeMillis())
|
||||||
}
|
}
|
||||||
broadcast(userId, Json.encodeToString(payload))
|
broadcast(userId, Json.encodeToString(payload))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue