Skip to content

Commit

Permalink
Prevent returning duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanOltmann committed Nov 3, 2024
1 parent 20973f5 commit a1dc8f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/main/kotlin/Routings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,23 @@ fun Application.configureRouting() {
)
}

val cluster: Cluster? = database
.getCollection<Cluster>("worlds")
.find(
Filters.eq("coordinate", cleanCoordinate)
).firstOrNull()

if (cluster != null) {

/* Mark the coordinate status as duplicated. */
collection.updateOne(
Filters.eq(RequestedCoordinate::coordinate.name, cleanCoordinate),
Updates.set(RequestedCoordinate::status.name, RequestedCoordinateStatus.DUPLICATED)
)

continue@findseed
}

call.respond(HttpStatusCode.OK, cleanCoordinate)

/*
Expand All @@ -779,6 +796,8 @@ fun Application.configureRouting() {
Filters.eq(RequestedCoordinate::coordinate.name, ex.coordinate),
Updates.set(RequestedCoordinate::status.name, RequestedCoordinateStatus.ILLEGAL)
)

continue@findseed
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/model/RequestedCoordinateStatus.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ enum class RequestedCoordinateStatus {
ILLEGAL,
DELIVERED,
COMPLETED,
FAILED
FAILED,
DUPLICATED
}

0 comments on commit a1dc8f2

Please sign in to comment.