diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index a3a50e8..1dad603 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -1,8 +1,8 @@ name: CI permissions: - contents: read - packages: write + contents: read + packages: write on: push: @@ -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 @@ -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 diff --git a/crates/location_tracking_service/src/common/types.rs b/crates/location_tracking_service/src/common/types.rs index 65719f1..1e7d103 100644 --- a/crates/location_tracking_service/src/common/types.rs +++ b/crates/location_tracking_service/src/common/types.rs @@ -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, diff --git a/crates/location_tracking_service/src/domain/action/internal/location.rs b/crates/location_tracking_service/src/domain/action/internal/location.rs index 90f3cfc..14afbe8 100644 --- a/crates/location_tracking_service/src/domain/action/internal/location.rs +++ b/crates/location_tracking_service/src/domain/action/internal/location.rs @@ -48,6 +48,8 @@ async fn search_nearby_drivers_with_vehicle( ) .await?; + info!("Drivers in nearby {:?}", nearby_drivers); + let driver_ids: Vec = nearby_drivers .iter() .map(|driver| driver.driver_id.to_owned()) @@ -75,6 +77,8 @@ async fn search_nearby_drivers_with_vehicle( }) .collect::>(); + info!("Final resp {:?}", resp); + Ok(resp) } @@ -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 = Vec::new(); for vehicle in VehicleType::iter() { @@ -122,6 +140,7 @@ pub async fn get_nearby_drivers( Ok(resp) } Some(vehicles) => { + info!("Woohoo 1"); let mut resp: Vec = Vec::new(); for vehicle in vehicles { let nearby_drivers = search_nearby_drivers_with_vehicle( diff --git a/crates/location_tracking_service/src/domain/action/internal/ride.rs b/crates/location_tracking_service/src/domain/action/internal/ride.rs index 583e436..76f5bdc 100644 --- a/crates/location_tracking_service/src/domain/action/internal/ride.rs +++ b/crates/location_tracking_service/src/domain/action/internal/ride.rs @@ -17,24 +17,26 @@ pub async fn ride_create( data: Data, request_body: RideCreateRequest, ) -> Result { - 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()) } @@ -44,7 +46,7 @@ pub async fn ride_start( data: Data, request_body: RideStartRequest, ) -> Result { - set_ride_details( + set_ride_details_for_driver( &data.redis, &data.redis_expiry, &request_body.merchant_id, @@ -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, @@ -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, request_body: RideDetailsRequest, @@ -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, diff --git a/crates/location_tracking_service/src/domain/types/internal/ride.rs b/crates/location_tracking_service/src/domain/types/internal/ride.rs index 82346c5..667f409 100644 --- a/crates/location_tracking_service/src/domain/types/internal/ride.rs +++ b/crates/location_tracking_service/src/domain/types/internal/ride.rs @@ -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, } #[derive(Serialize, Deserialize, Debug)] @@ -38,6 +39,7 @@ pub struct RideEndRequest { pub lon: Longitude, pub driver_id: DriverId, pub merchant_id: MerchantId, + pub next_ride_id: Option, } #[derive(Serialize, Deserialize, Clone, Debug)] @@ -68,6 +70,7 @@ pub struct RideEndResponse { pub struct RideDetailsRequest { pub ride_id: RideId, pub ride_status: RideStatus, + pub is_future_ride: Option, pub merchant_id: MerchantId, pub driver_id: DriverId, pub lat: Latitude, diff --git a/crates/location_tracking_service/src/redis/commands.rs b/crates/location_tracking_service/src/redis/commands.rs index 24fd54d..cac62ab 100644 --- a/crates/location_tracking_service/src/redis/commands.rs +++ b/crates/location_tracking_service/src/redis/commands.rs @@ -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, @@ -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, @@ -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 = (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, @@ -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)| {