修正更新成員沒有回應資料的問題
This commit is contained in:
+5
-5
@@ -24,19 +24,19 @@ class BattleRecordService(private val database: MongoDatabase) {
|
|||||||
memberCollection = database.getCollection("member")
|
memberCollection = database.getCollection("member")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new car
|
// Create new battle record
|
||||||
suspend fun create(data: BattleRecordDto): BattleRecordDto = withContext(Dispatchers.IO) {
|
suspend fun create(data: BattleRecordDto): BattleRecordDto = withContext(Dispatchers.IO) {
|
||||||
val doc = data.toDocument()
|
val doc = data.toDocument()
|
||||||
collection.insertOne(doc)
|
collection.insertOne(doc)
|
||||||
doc.let(BattleRecordDto::fromDocument)
|
doc.let(BattleRecordDto::fromDocument)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a car
|
// Read a battle record
|
||||||
suspend fun read(date: String): List<BattleRecordDto> = withContext(Dispatchers.IO) {
|
suspend fun read(date: String): List<BattleRecordDto> = withContext(Dispatchers.IO) {
|
||||||
collection.find(Filters.eq("date", date)).toList().map(BattleRecordDto::fromDocument)
|
collection.find(Filters.eq("date", date)).toList().map(BattleRecordDto::fromDocument)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read a car
|
// Read a battle record
|
||||||
suspend fun read(date: String, uid: String): BattleRecordDto? = withContext(Dispatchers.IO) {
|
suspend fun read(date: String, uid: String): BattleRecordDto? = withContext(Dispatchers.IO) {
|
||||||
val filter = and(
|
val filter = and(
|
||||||
Filters.eq("date", date),
|
Filters.eq("date", date),
|
||||||
@@ -45,7 +45,7 @@ class BattleRecordService(private val database: MongoDatabase) {
|
|||||||
collection.find(filter).first()?.let(BattleRecordDto::fromDocument)
|
collection.find(filter).first()?.let(BattleRecordDto::fromDocument)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update a car
|
// Update a battle record
|
||||||
suspend fun update(date: String, data: BattleRecordDto): BattleRecordDto? = withContext(Dispatchers.IO) {
|
suspend fun update(date: String, data: BattleRecordDto): BattleRecordDto? = withContext(Dispatchers.IO) {
|
||||||
val filter = and(
|
val filter = and(
|
||||||
Filters.eq("date", date),
|
Filters.eq("date", date),
|
||||||
@@ -55,7 +55,7 @@ class BattleRecordService(private val database: MongoDatabase) {
|
|||||||
collection.find(filter).first()?.let(BattleRecordDto::fromDocument)
|
collection.find(filter).first()?.let(BattleRecordDto::fromDocument)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a car
|
// Delete a battle record
|
||||||
suspend fun delete(date: String, uid: String): Document? = withContext(Dispatchers.IO) {
|
suspend fun delete(date: String, uid: String): Document? = withContext(Dispatchers.IO) {
|
||||||
val filter = and(
|
val filter = and(
|
||||||
Filters.eq("date", date),
|
Filters.eq("date", date),
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ fun Application.configureMongo() {
|
|||||||
call.respond(HttpStatusCode.OK, member)
|
call.respond(HttpStatusCode.OK, member)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read member
|
// Read member
|
||||||
get("/member/{uid}") {
|
get("/member/{uid}") {
|
||||||
val uid = call.parameters["uid"] ?: throw IllegalArgumentException("No ID found")
|
val uid = call.parameters["uid"] ?: throw IllegalArgumentException("No ID found")
|
||||||
@@ -43,6 +44,7 @@ fun Application.configureMongo() {
|
|||||||
call.respond(HttpStatusCode.OK, member)
|
call.respond(HttpStatusCode.OK, member)
|
||||||
} ?: call.respond(HttpStatusCode.NotFound)
|
} ?: call.respond(HttpStatusCode.NotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create member
|
// Create member
|
||||||
post("/member") {
|
post("/member") {
|
||||||
val member = call.receive<MemberRequest>()
|
val member = call.receive<MemberRequest>()
|
||||||
@@ -54,14 +56,16 @@ fun Application.configureMongo() {
|
|||||||
call.respond(HttpStatusCode.Conflict)
|
call.respond(HttpStatusCode.Conflict)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update member
|
// Update member
|
||||||
put("/member/{uid}") {
|
put("/member/{uid}") {
|
||||||
val uid = call.parameters["uid"] ?: throw IllegalArgumentException("No ID found")
|
val uid = call.parameters["uid"] ?: throw IllegalArgumentException("No ID found")
|
||||||
val member = call.receive<UpdateMemberRequest>()
|
val member = call.receive<UpdateMemberRequest>()
|
||||||
memberService.update(uid, member.toDto(uid))?.let {
|
memberService.update(uid, member.toDto(uid))?.let { member ->
|
||||||
call.respond(HttpStatusCode.OK)
|
call.respond(HttpStatusCode.OK, member)
|
||||||
} ?: call.respond(HttpStatusCode.NotFound)
|
} ?: call.respond(HttpStatusCode.NotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete member
|
// Delete member
|
||||||
delete("/member/{uid}") {
|
delete("/member/{uid}") {
|
||||||
val uid = call.parameters["uid"] ?: throw IllegalArgumentException("No ID found")
|
val uid = call.parameters["uid"] ?: throw IllegalArgumentException("No ID found")
|
||||||
|
|||||||
Reference in New Issue
Block a user