Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend/potential fix #145

Open
wants to merge 2 commits into
base: main
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
7 changes: 2 additions & 5 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: CI

permissions:
contents: read
packages: write
contents: read
packages: write

on:
push:
Expand Down Expand Up @@ -34,13 +34,11 @@ jobs:

- name: Docker tasks
id: docker
if: (github.ref == 'refs/heads/main')
run: |
nix build .#dockerImage -o docker-image.tgz
echo "image_name=$(nix eval --raw .#dockerImage.imageName):$(nix eval --raw .#dockerImage.imageTag)" >> $GITHUB_OUTPUT

- name: Upload Docker image tarball
if: (github.ref == 'refs/heads/main')
uses: actions/upload-artifact@v4
with:
name: docker-image
Expand All @@ -49,7 +47,6 @@ jobs:
push-docker:
needs: build
runs-on: ubuntu-latest
if: (github.ref == 'refs/heads/main')
steps:
- name: Download Docker image tarball
uses: actions/download-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions crates/location_tracking_service/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ pub struct AuthData {
pub merchant_operating_city_id: MerchantOperatingCityId,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct DriverLocationPoint {
pub driver_id: DriverId,
pub location: Point,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ async fn search_nearby_drivers_with_vehicle(
)
.await?;

info!("Drivers in nearby {:?}", nearby_drivers);

let driver_ids: Vec<DriverId> = nearby_drivers
.iter()
.map(|driver| driver.driver_id.to_owned())
Expand Down Expand Up @@ -75,6 +77,8 @@ async fn search_nearby_drivers_with_vehicle(
})
.collect::<Vec<DriverLocationDetail>>();

info!("Final resp {:?}", resp);

Ok(resp)
}

Expand All @@ -93,8 +97,22 @@ pub async fn get_nearby_drivers(

let current_bucket = get_bucket_from_timestamp(&data.bucket_size, TimeStamp(Utc::now()));

info!("lat type before {:?}", lat);
info!("lon type before {:?}", lon);
info!("type type before {:?}", vehicle_type);
info!("radius type before {:?}", radius);
info!("mid type before {:?}", merchant_id);

let vehicle_type = match vehicle_type {
Some(ref vec) if vec.is_empty() => None,
_ => vehicle_type,
};

info!("Vehicle type after {:?}", vehicle_type);

match vehicle_type {
None => {
info!("Woohoo 3");
let mut resp: Vec<DriverLocationDetail> = Vec::new();

for vehicle in VehicleType::iter() {
Expand Down Expand Up @@ -122,6 +140,7 @@ pub async fn get_nearby_drivers(
Ok(resp)
}
Some(vehicles) => {
info!("Woohoo 1");
let mut resp: Vec<DriverLocationDetail> = Vec::new();
for vehicle in vehicles {
let nearby_drivers = search_nearby_drivers_with_vehicle(
Expand Down
73 changes: 45 additions & 28 deletions crates/location_tracking_service/src/domain/action/internal/ride.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@ pub async fn ride_create(
data: Data<AppState>,
request_body: RideCreateRequest,
) -> Result<APISuccess, AppError> {
set_ride_details(
&data.redis,
&data.redis_expiry,
&request_body.merchant_id,
&request_body.driver_id,
ride_id.to_owned(),
RideStatus::NEW,
Some(request_body.vehicle_number),
Some(request_body.ride_start_otp),
Some(request_body.estimated_pickup_distance),
)
.await?;
if let Some(false) | None = request_body.is_future_ride {
set_ride_details_for_driver(
&data.redis,
&data.redis_expiry,
&request_body.merchant_id,
&request_body.driver_id,
ride_id.to_owned(),
RideStatus::NEW,
Some(request_body.vehicle_number),
Some(request_body.ride_start_otp),
Some(request_body.estimated_pickup_distance),
)
.await?;
}

let driver_details = DriverDetails {
driver_id: request_body.driver_id,
};

set_driver_details(&data.redis, &data.redis_expiry, &ride_id, driver_details).await?;
set_on_ride_driver_details(&data.redis, &data.redis_expiry, &ride_id, driver_details).await?;

Ok(APISuccess::default())
}
Expand All @@ -44,7 +46,7 @@ pub async fn ride_start(
data: Data<AppState>,
request_body: RideStartRequest,
) -> Result<APISuccess, AppError> {
set_ride_details(
set_ride_details_for_driver(
&data.redis,
&data.redis_expiry,
&request_body.merchant_id,
Expand Down Expand Up @@ -86,6 +88,19 @@ pub async fn ride_end(
)
.await?;

if let Some(next_ride_id) = request_body.next_ride_id {
let ride_details_request = RideDetailsRequest {
ride_id: next_ride_id,
ride_status: RideStatus::NEW,
is_future_ride: Some(false),
merchant_id: request_body.merchant_id,
driver_id: request_body.driver_id.clone(),
lat: request_body.lat,
lon: request_body.lon,
};
ride_details(data, ride_details_request).await?;
}

Ok(RideEndResponse {
ride_id,
driver_id: request_body.driver_id,
Expand Down Expand Up @@ -116,7 +131,7 @@ pub async fn get_driver_locations(
})
}

// TODO :: To be deprecated...
// TODO :: To be deprecated...but is currently being used
pub async fn ride_details(
data: Data<AppState>,
request_body: RideDetailsRequest,
Expand All @@ -130,24 +145,26 @@ pub async fn ride_details(
)
.await?;
} else {
set_ride_details(
&data.redis,
&data.redis_expiry,
&request_body.merchant_id,
&request_body.driver_id,
request_body.ride_id.to_owned(),
request_body.ride_status,
None,
None,
None,
)
.await?;
if let Some(false) | None = request_body.is_future_ride {
set_ride_details_for_driver(
&data.redis,
&data.redis_expiry,
&request_body.merchant_id,
&request_body.driver_id,
request_body.ride_id.to_owned(),
request_body.ride_status,
None,
None,
None,
)
.await?;
}

let driver_details = DriverDetails {
driver_id: request_body.driver_id,
};

set_driver_details(
set_on_ride_driver_details(
&data.redis,
&data.redis_expiry,
&request_body.ride_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct RideCreateRequest {
pub vehicle_number: String,
pub ride_start_otp: u32,
pub estimated_pickup_distance: Meters,
pub is_future_ride: Option<bool>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -38,6 +39,7 @@ pub struct RideEndRequest {
pub lon: Longitude,
pub driver_id: DriverId,
pub merchant_id: MerchantId,
pub next_ride_id: Option<RideId>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -68,6 +70,7 @@ pub struct RideEndResponse {
pub struct RideDetailsRequest {
pub ride_id: RideId,
pub ride_status: RideStatus,
pub is_future_ride: Option<bool>,
pub merchant_id: MerchantId,
pub driver_id: DriverId,
pub lat: Latitude,
Expand Down
10 changes: 8 additions & 2 deletions crates/location_tracking_service/src/redis/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use tracing::{error, info};
/// # Returns
/// * A Result indicating the success or failure of the operation.
#[allow(clippy::too_many_arguments)]
pub async fn set_ride_details(
pub async fn set_ride_details_for_driver(
redis: &RedisConnectionPool,
redis_expiry: &u32,
merchant_id: &MerchantId,
Expand Down Expand Up @@ -151,7 +151,7 @@ pub async fn ride_cleanup(
///
/// * `Ok(())` if the driver details are successfully stored.
/// * `Err(AppError::SerializationError)` if there's an error during serialization.
pub async fn set_driver_details(
pub async fn set_on_ride_driver_details(
redis: &RedisConnectionPool,
redis_expiry: &u32,
ride_id: &RideId,
Expand Down Expand Up @@ -204,10 +204,14 @@ pub async fn get_drivers_within_radius(
let Latitude(lat) = location.lat;
let Longitude(lon) = location.lon;

info!("Bucket value {:?}", bucket);

let bucket_keys: Vec<String> = (0..*nearby_bucket_threshold)
.map(|bucket_idx| driver_loc_bucket_key(merchant_id, city, vehicle, &(bucket - bucket_idx)))
.collect();

info!("BucketKeys {:?}", bucket_keys);

let nearby_drivers = redis
.mgeo_search(
bucket_keys,
Expand All @@ -218,6 +222,8 @@ pub async fn get_drivers_within_radius(
.await
.map_err(|err| AppError::InternalError(err.to_string()))?;

info!("Get Nearby Drivers 1 {:?}", nearby_drivers);

let nearby_drivers: Vec<(DriverId, Point)> = cat_maybes(nearby_drivers)
.into_iter()
.map(|(driver_id, point)| {
Expand Down
Loading