實作ar model刪除、查詢、修改

This commit is contained in:
Raymond Yang 2023-05-16 14:59:30 +08:00
parent d787932e45
commit a2acb7b928
2 changed files with 6 additions and 15 deletions

View File

@ -60,14 +60,6 @@ fun Application.configureArModelRouting() {
}
val body = call.receive<ArModel>()
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)
call.sendSuccess(mapOf("success" to isSuccess))
}

View File

@ -16,8 +16,6 @@ class ModelService {
return arModel._id
}
fun findAll(): List<ArModel> = arModelCollection.find().toList()
fun findById(id: String): ArModel? {
val bsonId: Id<ArModel> = ObjectId(id).toId()
return arModelCollection.findOne(ArModel::_id eq bsonId)
@ -28,16 +26,17 @@ class ModelService {
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 =
findById(id)?.let { arModel ->
val updateResult = arModelCollection.replaceOne(
arModel.copy(
name = request.name,
position = request.position,
rotation = request.rotation,
scale = request.scale,
modelData = request.modelData,
events = request.events,
childEvents = request.childEvents,
updatedAt = request.updatedAt
)
)