實作ar model刪除、查詢、修改
This commit is contained in:
parent
d787932e45
commit
a2acb7b928
@ -60,14 +60,6 @@ fun Application.configureArModelRouting() {
|
|||||||
}
|
}
|
||||||
val body = call.receive<ArModel>()
|
val body = call.receive<ArModel>()
|
||||||
val id = call.parameters["id"].toString()
|
val id = call.parameters["id"].toString()
|
||||||
val model = modelService.findById(id) ?: run {
|
|
||||||
call.sendNotFound()
|
|
||||||
return@put
|
|
||||||
}
|
|
||||||
body.apply {
|
|
||||||
ownerId = model.ownerId
|
|
||||||
createAt = model.createAt
|
|
||||||
}
|
|
||||||
val isSuccess = modelService.updateById(id, body)
|
val isSuccess = modelService.updateById(id, body)
|
||||||
call.sendSuccess(mapOf("success" to isSuccess))
|
call.sendSuccess(mapOf("success" to isSuccess))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,8 +16,6 @@ class ModelService {
|
|||||||
return arModel._id
|
return arModel._id
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findAll(): List<ArModel> = arModelCollection.find().toList()
|
|
||||||
|
|
||||||
fun findById(id: String): ArModel? {
|
fun findById(id: String): ArModel? {
|
||||||
val bsonId: Id<ArModel> = ObjectId(id).toId()
|
val bsonId: Id<ArModel> = ObjectId(id).toId()
|
||||||
return arModelCollection.findOne(ArModel::_id eq bsonId)
|
return arModelCollection.findOne(ArModel::_id eq bsonId)
|
||||||
@ -28,16 +26,17 @@ class ModelService {
|
|||||||
return arModelCollection.find(ArModel::ownerId eq bsonId).toList()
|
return arModelCollection.find(ArModel::ownerId eq bsonId).toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findByName(name: String): List<ArModel> {
|
|
||||||
val caseSensitiveTypeSafeFilter = ArModel::name regex name
|
|
||||||
return arModelCollection.find(caseSensitiveTypeSafeFilter).toList()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateById(id: String, request: ArModel): Boolean =
|
fun updateById(id: String, request: ArModel): Boolean =
|
||||||
findById(id)?.let { arModel ->
|
findById(id)?.let { arModel ->
|
||||||
val updateResult = arModelCollection.replaceOne(
|
val updateResult = arModelCollection.replaceOne(
|
||||||
arModel.copy(
|
arModel.copy(
|
||||||
name = request.name,
|
name = request.name,
|
||||||
|
position = request.position,
|
||||||
|
rotation = request.rotation,
|
||||||
|
scale = request.scale,
|
||||||
|
modelData = request.modelData,
|
||||||
|
events = request.events,
|
||||||
|
childEvents = request.childEvents,
|
||||||
updatedAt = request.updatedAt
|
updatedAt = request.updatedAt
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user