Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- impl Request for OrdersGetRequest {
- type Response = OrdersGetResponse;
- fn handle(self, app: &App) -> Result<OrdersGetResponse, ErrorResponse> {
- let mut pagination;
- let is_get_by_status = self.status.is_some();
- let conn = try!(app.conn());
- let orders;
- // for payment verify
- if self.is_payment_verify.is_some() {
- orders = try!(get_payment_verify_orders(&conn, &mut pagination, &is_pagination, &self.offset, &self.length));
- } else {
- orders = if self.with_skus == Some(true) {
- let (mut orders, item_orders, mut coupons) = if self.with_trade_snap == Some(true) {
- try!(get_by_status_with_skus_trade(&conn, &self.status.unwrap(), &mut pagination, &is_pagination, &self.offset, &self.length))
- };
- orders.dedup();
- coupons.dedup();
- let item_orders_map: HashMap<i64, Vec<ItemOrder>> = item_orders.into_iter().fold(HashMap::new(), |mut item_orders_map, item_order| {
- let order_id = item_order.order_id.clone().unwrap();
- if item_orders_map.contains_key(&order_id) {
- item_orders_map.get_mut(&order_id).unwrap().push(item_order);
- } else {
- item_orders_map.insert(order_id, vec!());
- item_orders_map.get_mut(&order_id).unwrap().push(item_order);
- }
- item_orders_map
- });
- let item_coupons_map: HashMap<i64, Vec<Coupon>> = coupons.into_iter().fold(HashMap::new(), |mut item_coupons_map, coupon| {
- let order_id = coupon.order_id.clone().unwrap();
- if item_coupons_map.contains_key(&order_id) {
- item_coupons_map.get_mut(&order_id).unwrap().push(coupon);
- } else {
- item_coupons_map.insert(order_id, vec!());
- item_coupons_map.get_mut(&order_id).unwrap().push(coupon);
- }
- item_coupons_map
- });
- orders = orders.into_iter().map(|mut order| {
- if !order.id.is_some() {
- debug!("{:?}", order);
- }
- let order_id = order.id.clone().unwrap();
- order.skus = item_orders_map.get(&order_id).cloned();
- order.coupons = item_coupons_map.get(&order_id).cloned();
- order
- }).collect();
- orders
- };
- }
- if is_pagination {
- try!(pagination.validate_offset());
- Ok(OrdersGetResponse {
- orders: orders,
- pagination: Some(pagination),
- })
- } else {
- Ok(OrdersGetResponse {
- orders: orders,
- pagination: None,
- })
- }
- }
- }
Add Comment
Please, Sign In to add comment