修正新增出刀紀錄回傳結果
This commit is contained in:
+4
-3
@@ -18,10 +18,10 @@ class BattleRecordService(private val database: MongoDatabase) {
|
||||
}
|
||||
|
||||
// Create new car
|
||||
suspend fun create(data: BattleRecordDto): String = withContext(Dispatchers.IO) {
|
||||
suspend fun create(data: BattleRecordDto): BattleRecordDto = withContext(Dispatchers.IO) {
|
||||
val doc = data.toDocument()
|
||||
collection.insertOne(doc)
|
||||
doc["uid"].toString()
|
||||
doc.let(BattleRecordDto::fromDocument)
|
||||
}
|
||||
|
||||
// Read a car
|
||||
@@ -39,12 +39,13 @@ class BattleRecordService(private val database: MongoDatabase) {
|
||||
}
|
||||
|
||||
// Update a car
|
||||
suspend fun update(date: String, data: BattleRecordDto): Document? = withContext(Dispatchers.IO) {
|
||||
suspend fun update(date: String, data: BattleRecordDto): BattleRecordDto? = withContext(Dispatchers.IO) {
|
||||
val filter = and(
|
||||
Filters.eq("date", date),
|
||||
Filters.eq("uid", data.uid)
|
||||
)
|
||||
collection.findOneAndReplace(filter, data.toDocument())
|
||||
collection.find(filter).first()?.let(BattleRecordDto::fromDocument)
|
||||
}
|
||||
|
||||
// Delete a car
|
||||
|
||||
Reference in New Issue
Block a user