Manos Chorianopoulos

add sorting to campaigns

...@@ -179,7 +179,7 @@ public class swiftApi { ...@@ -179,7 +179,7 @@ public class swiftApi {
179 self.description = dictionary["description"] as? String? ?? "" 179 self.description = dictionary["description"] as? String? ?? ""
180 self.short_description = dictionary["short_description"] as? String? ?? "" 180 self.short_description = dictionary["short_description"] as? String? ?? ""
181 self.discount = dictionary["discount"] as? String? ?? "" 181 self.discount = dictionary["discount"] as? String? ?? ""
182 - self.sorting = dictionary["sorting"] as? Int? ?? nil 182 + self.sorting = dictionary["sorting"] as? Int? ?? 0
183 self.inner_text = dictionary["inner_text"] as? String? ?? "" 183 self.inner_text = dictionary["inner_text"] as? String? ?? ""
184 self.buyable = dictionary["buyable"] as? Bool? ?? false 184 self.buyable = dictionary["buyable"] as? Bool? ?? false
185 self.visible = dictionary["visible"] as? Bool? ?? false 185 self.visible = dictionary["visible"] as? Bool? ?? false
...@@ -523,7 +523,7 @@ public class swiftApi { ...@@ -523,7 +523,7 @@ public class swiftApi {
523 // self.campaign_type_settings = [String: Any]() 523 // self.campaign_type_settings = [String: Any]()
524 self.couponset = "" 524 self.couponset = ""
525 self.type = "" 525 self.type = ""
526 - self.sorting = nil 526 + self.sorting = 0
527 } 527 }
528 528
529 public init(dictionary: [String: Any]) { 529 public init(dictionary: [String: Any]) {
...@@ -537,7 +537,7 @@ public class swiftApi { ...@@ -537,7 +537,7 @@ public class swiftApi {
537 self.message = dictionary["message"] as? String? ?? "" 537 self.message = dictionary["message"] as? String? ?? ""
538 self.loyaltyPackageId = "" 538 self.loyaltyPackageId = ""
539 self.campaign_type = dictionary["campaign_type"] as? String? ?? "" 539 self.campaign_type = dictionary["campaign_type"] as? String? ?? ""
540 - self.sorting = dictionary["sorting"] as? Int? ?? nil 540 + self.sorting = dictionary["sorting"] as? Int? ?? 0
541 541
542 // let extra_fields = dictionary["extra_fields"] as? [String: Any]? ?? ["":""] 542 // let extra_fields = dictionary["extra_fields"] as? [String: Any]? ?? ["":""]
543 if let extra_fields = dictionary["extra_fields"] as? [String: Any] { 543 if let extra_fields = dictionary["extra_fields"] as? [String: Any] {
...@@ -745,7 +745,12 @@ public class swiftApi { ...@@ -745,7 +745,12 @@ public class swiftApi {
745 745
746 return (!isCcmsOffer) 746 return (!isCcmsOffer)
747 } 747 }
748 - getCampaignsCallback(filteredCampaigns); 748 +
749 + let sortedCampaigns = filteredCampaigns.sorted {
750 + $0._sorting < $1._sorting
751 + }
752 +
753 + getCampaignsCallback(sortedCampaigns);
749 } 754 }
750 755
751 func campaignsFailureCallback(_ error: Error?) -> Void { 756 func campaignsFailureCallback(_ error: Error?) -> Void {
...@@ -810,7 +815,11 @@ public class swiftApi { ...@@ -810,7 +815,11 @@ public class swiftApi {
810 filteredCampaigns = filteredCampaigns.filter { $0.offer_category != "questionnaire" } 815 filteredCampaigns = filteredCampaigns.filter { $0.offer_category != "questionnaire" }
811 } 816 }
812 817
813 - getCampaignsCallback(filteredCampaigns); 818 + let sortedCampaigns = filteredCampaigns.sorted {
819 + $0._sorting < $1._sorting
820 + }
821 +
822 + getCampaignsCallback(sortedCampaigns);
814 }) 823 })
815 824
816 } else { 825 } else {
...@@ -2760,7 +2769,11 @@ public class swiftApi { ...@@ -2760,7 +2769,11 @@ public class swiftApi {
2760 // } 2769 // }
2761 // } 2770 // }
2762 2771
2763 - GlobalVariables.campaigns = campaigns 2772 + let sortedCampaigns = campaigns.sorted {
2773 + $0._sorting < $1._sorting
2774 + }
2775 +
2776 + GlobalVariables.campaigns = sortedCampaigns
2764 } 2777 }
2765 2778
2766 2779
...@@ -2900,7 +2913,11 @@ public class swiftApi { ...@@ -2900,7 +2913,11 @@ public class swiftApi {
2900 // } 2913 // }
2901 // } 2914 // }
2902 2915
2903 - GlobalVariables.campaigns = campaigns 2916 + let sortedCampaigns = campaigns.sorted {
2917 + $0._sorting < $1._sorting
2918 + }
2919 +
2920 + GlobalVariables.campaigns = sortedCampaigns
2904 } 2921 }
2905 2922
2906 2923
......