Skip to content

Commit

Permalink
lts/fix/handing-future-rides
Browse files Browse the repository at this point in the history
  • Loading branch information
rupakkorde committed Dec 13, 2024
1 parent 3906704 commit c125f5a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
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
4 changes: 2 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

0 comments on commit c125f5a

Please sign in to comment.