Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

added geohashes and replaced dropoff coordinates by the decoded geohash #12

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/main/kotlin/com/colivery/engine/Mapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.colivery.engine.model.Order
import com.colivery.engine.model.OrderItem
import com.colivery.engine.model.PoIType
import com.colivery.geo.Coordinate
import com.colivery.geo.GeoHash
import com.google.cloud.firestore.DocumentSnapshot
import com.google.cloud.firestore.GeoPoint
import java.time.Instant
Expand All @@ -14,9 +15,12 @@ fun DocumentSnapshot.toOrder(items: List<OrderItem>?) = Order(
created = getCreated(),
updated = getUpdated(),
userId = notNull("user_id", this::getString),
pickupLocationGeohash = getString("pickup_location_geohash"),
pickupAddress = getString("pickup_address"),
pickupLocation = getGeoPoint("pickup_location")?.toCoordinate(),
dropoffLocation = notNull("dropoff_location", this::getGeoPoint).toCoordinate(),
dropoffLocationGeohash = notNull("dropoff_location_geohash", this::getString),
dropoffAddress = notNull("pickup_address", this::getString),
shopName = getString("shop_name"),
shopType = PoIType.valueOf(notNull("shop_type", this::getString)),
hint = getString("hint"),
Expand All @@ -26,6 +30,26 @@ fun DocumentSnapshot.toOrder(items: List<OrderItem>?) = Order(
maxPrice = getLong("max_price")
)

fun Order.pseudonymized() = Order(
id = id,
created = created,
updated = updated,
userId = userId,
pickupLocationGeohash = pickupLocationGeohash,
pickupAddress = pickupAddress,
pickupLocation = pickupLocation,
dropoffLocationGeohash = dropoffLocationGeohash,
dropoffLocation = GeoHash.decode(dropoffLocationGeohash),
dropoffAddress = dropoffAddress.substringAfter(","),
shopName = shopName,
shopType = shopType,
hint = hint,
driverUserId = driverUserId,
status = status,
items = items,
maxPrice = maxPrice
)

private fun DocumentSnapshot.getUpdated(): Instant? = updateTime?.seconds?.let { Instant.ofEpochSecond(it) }
private fun DocumentSnapshot.getCreated(): Instant? = createTime?.seconds?.let { Instant.ofEpochSecond(it) }

Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/com/colivery/engine/SearchController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class SearchController {
buildMapsLink(activitySequence))
}

@PostMapping("/order")
fun orders(@RequestBody @Valid request: OrderRequest): OrderResponse {
val startLocation = request.coordinate
val radius = request.range
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/com/colivery/engine/model/Order.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ data class Order(val id: String,
val hint: String?,
var shopType: PoIType,
val pickupLocation: Coordinate?,
val pickupLocationGeohash: String?,
val dropoffLocation: Coordinate,
val dropoffLocationGeohash: String,
val dropoffAddress: String,
val status: String,
val driverUserId: String?,
val items: List<OrderItem>?,
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/colivery/engine/service/OrderService.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.colivery.engine.service

import com.colivery.engine.model.Order
import com.colivery.engine.pseudonymized
import com.colivery.engine.toOrder
import com.colivery.engine.toOrderItem
import com.colivery.geo.Coordinate
Expand Down Expand Up @@ -40,7 +41,7 @@ class OrderService {
Distance.haversine(startLocation, order.pickupLocation) <= radius
}
.filter { order -> Distance.haversine(startLocation, order.dropoffLocation) <= radius }
orders.forEach { it.fixType() }
orders.map { order -> order.pseudonymized() }.forEach { it.fixType() }
return orders
}

Expand Down
20 changes: 16 additions & 4 deletions src/test/kotlin/com/colivery/engine/service/RouteServiceTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.colivery.engine.service

import com.colivery.engine.TestConfig
import com.colivery.engine.model.*
import com.colivery.engine.model.Activity
import com.colivery.engine.model.ActivityType
import com.colivery.engine.model.Order
import com.colivery.engine.model.PoIType
import com.colivery.geo.Coordinate
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -30,9 +33,12 @@ internal class RouteServiceTest {
"hint",
PoIType.supermarket,
Coordinate(49.1, 18.1),
"gwxp",
Coordinate(49.2, 18.2),
"gwxp",
"Weg 1, 81234 München",
"to_be_delivered",
null,
"",
emptyList(),
10
)
Expand Down Expand Up @@ -62,9 +68,12 @@ internal class RouteServiceTest {
"hint",
PoIType.supermarket,
Coordinate(49.1, 18.1),
"gwxp",
Coordinate(49.4, 18.4),
"gwxp",
"Weg 1, 81234 München",
"to_be_delivered",
null,
"",
emptyList(),
10
)
Expand All @@ -78,9 +87,12 @@ internal class RouteServiceTest {
"hint",
PoIType.supermarket,
Coordinate(49.2, 18.2),
"gwxp",
Coordinate(49.3, 18.3),
"gwxp",
"Weg 1, 81234 München",
"to_be_delivered",
null,
"",
emptyList(),
10
)
Expand Down