Guest User

Untitled

a guest
Jul 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. impl Request for OrdersGetRequest {
  2. type Response = OrdersGetResponse;
  3.  
  4. fn handle(self, app: &App) -> Result<OrdersGetResponse, ErrorResponse> {
  5.  
  6. let mut pagination;
  7.  
  8. let is_get_by_status = self.status.is_some();
  9.  
  10.  
  11.  
  12. let conn = try!(app.conn());
  13.  
  14. let orders;
  15. // for payment verify
  16. if self.is_payment_verify.is_some() {
  17. orders = try!(get_payment_verify_orders(&conn, &mut pagination, &is_pagination, &self.offset, &self.length));
  18. } else {
  19. orders = if self.with_skus == Some(true) {
  20. let (mut orders, item_orders, mut coupons) = if self.with_trade_snap == Some(true) {
  21.  
  22. try!(get_by_status_with_skus_trade(&conn, &self.status.unwrap(), &mut pagination, &is_pagination, &self.offset, &self.length))
  23.  
  24. };
  25.  
  26. orders.dedup();
  27. coupons.dedup();
  28. let item_orders_map: HashMap<i64, Vec<ItemOrder>> = item_orders.into_iter().fold(HashMap::new(), |mut item_orders_map, item_order| {
  29. let order_id = item_order.order_id.clone().unwrap();
  30. if item_orders_map.contains_key(&order_id) {
  31. item_orders_map.get_mut(&order_id).unwrap().push(item_order);
  32. } else {
  33. item_orders_map.insert(order_id, vec!());
  34. item_orders_map.get_mut(&order_id).unwrap().push(item_order);
  35. }
  36.  
  37. item_orders_map
  38. });
  39.  
  40. let item_coupons_map: HashMap<i64, Vec<Coupon>> = coupons.into_iter().fold(HashMap::new(), |mut item_coupons_map, coupon| {
  41. let order_id = coupon.order_id.clone().unwrap();
  42. if item_coupons_map.contains_key(&order_id) {
  43. item_coupons_map.get_mut(&order_id).unwrap().push(coupon);
  44. } else {
  45. item_coupons_map.insert(order_id, vec!());
  46. item_coupons_map.get_mut(&order_id).unwrap().push(coupon);
  47. }
  48.  
  49. item_coupons_map
  50. });
  51.  
  52. orders = orders.into_iter().map(|mut order| {
  53. if !order.id.is_some() {
  54. debug!("{:?}", order);
  55. }
  56.  
  57. let order_id = order.id.clone().unwrap();
  58. order.skus = item_orders_map.get(&order_id).cloned();
  59. order.coupons = item_coupons_map.get(&order_id).cloned();
  60.  
  61. order
  62. }).collect();
  63.  
  64. orders
  65. };
  66. }
  67.  
  68. if is_pagination {
  69. try!(pagination.validate_offset());
  70. Ok(OrdersGetResponse {
  71. orders: orders,
  72. pagination: Some(pagination),
  73. })
  74. } else {
  75. Ok(OrdersGetResponse {
  76. orders: orders,
  77. pagination: None,
  78. })
  79. }
  80.  
  81. }
  82. }
Add Comment
Please, Sign In to add comment