Spaces:
Running
Running
Commit ·
8d4e4f8
1
Parent(s): 5c48718
refactor(merchant): move address formatting logic to pipeline stage
Browse filesThe address formatting fallback logic was moved from the projection definition to the pipeline stage in merchant service for better maintainability and consistency with other pipeline operations.
- app/models/optimized_projections.py +1 -20
- app/services/merchant.py +24 -0
app/models/optimized_projections.py
CHANGED
|
@@ -28,27 +28,8 @@ CARD_FIELDS = {
|
|
| 28 |
"city": 1,
|
| 29 |
"merchant_category": 1,
|
| 30 |
"merchant_subcategory": 1,
|
| 31 |
-
# Include entire address object
|
| 32 |
"address": 1,
|
| 33 |
-
# Ensure address.formatted_address is populated with a sensible fallback
|
| 34 |
-
"address.formatted_address": {
|
| 35 |
-
"$ifNull": [
|
| 36 |
-
"$address.formatted_address",
|
| 37 |
-
{
|
| 38 |
-
"$trim": {
|
| 39 |
-
"input": {
|
| 40 |
-
"$concat": [
|
| 41 |
-
{"$ifNull": ["$address.street", ""]},
|
| 42 |
-
{"$literal": " "},
|
| 43 |
-
{"$ifNull": ["$address.area", ""]},
|
| 44 |
-
{"$literal": " "},
|
| 45 |
-
{"$ifNull": ["$city", ""]}
|
| 46 |
-
]
|
| 47 |
-
}
|
| 48 |
-
}
|
| 49 |
-
}
|
| 50 |
-
]
|
| 51 |
-
},
|
| 52 |
"promotions": 1,
|
| 53 |
}
|
| 54 |
|
|
|
|
| 28 |
"city": 1,
|
| 29 |
"merchant_category": 1,
|
| 30 |
"merchant_subcategory": 1,
|
| 31 |
+
# Include entire address object (formatted_address fallback handled in pipeline)
|
| 32 |
"address": 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
"promotions": 1,
|
| 34 |
}
|
| 35 |
|
app/services/merchant.py
CHANGED
|
@@ -119,6 +119,30 @@ def build_optimized_merchant_pipeline(
|
|
| 119 |
|
| 120 |
# Add go_live_from normalization
|
| 121 |
pipeline.append(get_go_live_from_normalized_stage())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
# Add distance calculation if needed
|
| 124 |
if include_distance and user_lat and user_lng:
|
|
|
|
| 119 |
|
| 120 |
# Add go_live_from normalization
|
| 121 |
pipeline.append(get_go_live_from_normalized_stage())
|
| 122 |
+
|
| 123 |
+
# Ensure formatted address is present by adding a fallback
|
| 124 |
+
pipeline.append({
|
| 125 |
+
"$addFields": {
|
| 126 |
+
"address.formatted_address": {
|
| 127 |
+
"$ifNull": [
|
| 128 |
+
"$address.formatted_address",
|
| 129 |
+
{
|
| 130 |
+
"$trim": {
|
| 131 |
+
"input": {
|
| 132 |
+
"$concat": [
|
| 133 |
+
{"$ifNull": ["$address.street", ""]},
|
| 134 |
+
{"$literal": " "},
|
| 135 |
+
{"$ifNull": ["$address.area", ""]},
|
| 136 |
+
{"$literal": " "},
|
| 137 |
+
{"$ifNull": ["$city", ""]}
|
| 138 |
+
]
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
]
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
})
|
| 146 |
|
| 147 |
# Add distance calculation if needed
|
| 148 |
if include_distance and user_lat and user_lng:
|