mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	feat(router): add offset in mandate list route (#3923)
This commit is contained in:
		 Panagiotis Ganelis
					Panagiotis Ganelis
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							a004b8ae0d
						
					
				
				
					commit
					17a866a735
				
			| @ -87,6 +87,8 @@ pub struct MandateCardDetails { | ||||
| pub struct MandateListConstraints { | ||||
|     /// limit on the number of objects to return | ||||
|     pub limit: Option<i64>, | ||||
|     /// offset on the number of objects to return | ||||
|     pub offset: Option<i64>, | ||||
|     /// status of the mandate | ||||
|     pub mandate_status: Option<api_enums::MandateStatus>, | ||||
|     /// connector linked to mandate | ||||
|  | ||||
| @ -262,14 +262,22 @@ impl MandateInterface for MockDb { | ||||
|             checker | ||||
|         }); | ||||
|  | ||||
|         #[allow(clippy::as_conversions)] | ||||
|         let offset = (if mandate_constraints.offset.unwrap_or(0) < 0 { | ||||
|             0 | ||||
|         } else { | ||||
|             mandate_constraints.offset.unwrap_or(0) | ||||
|         }) as usize; | ||||
|  | ||||
|         let mandates: Vec<storage::Mandate> = if let Some(limit) = mandate_constraints.limit { | ||||
|             #[allow(clippy::as_conversions)] | ||||
|             mandates_iter | ||||
|                 .skip(offset) | ||||
|                 .take((if limit < 0 { 0 } else { limit }) as usize) | ||||
|                 .cloned() | ||||
|                 .collect() | ||||
|         } else { | ||||
|             mandates_iter.cloned().collect() | ||||
|             mandates_iter.skip(offset).cloned().collect() | ||||
|         }; | ||||
|         Ok(mandates) | ||||
|     } | ||||
|  | ||||
| @ -101,6 +101,7 @@ pub async fn revoke_mandate( | ||||
|         ("created_time.gt" = Option<PrimitiveDateTime>, Query, description = "Time greater than the mandate created time"), | ||||
|         ("created_time.lte" = Option<PrimitiveDateTime>, Query, description = "Time less than or equals to the mandate created time"), | ||||
|         ("created_time.gte" = Option<PrimitiveDateTime>, Query, description = "Time greater than or equals to the mandate created time"), | ||||
|         ("offset" = Option<i64>, Query, description = "The number of Mandate Objects to skip when retrieving the list Mandates."), | ||||
|     ), | ||||
|     responses( | ||||
|         (status = 200, description = "The mandate list was retrieved successfully", body = Vec<MandateResponse>), | ||||
|  | ||||
| @ -54,6 +54,9 @@ impl MandateDbExt for Mandate { | ||||
|         if let Some(limit) = mandate_list_constraints.limit { | ||||
|             filter = filter.limit(limit); | ||||
|         } | ||||
|         if let Some(offset) = mandate_list_constraints.offset { | ||||
|             filter = filter.offset(offset); | ||||
|         } | ||||
|  | ||||
|         logger::debug!(query = %diesel::debug_query::<diesel::pg::Pg, _>(&filter).to_string()); | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user