Showing
3 changed files
with
178 additions
and
2 deletions
No preview for this file type
... | @@ -32,8 +32,8 @@ | ... | @@ -32,8 +32,8 @@ |
32 | endingColumnNumber = "9223372036854775807" | 32 | endingColumnNumber = "9223372036854775807" |
33 | startingLineNumber = "212" | 33 | startingLineNumber = "212" |
34 | endingLineNumber = "212" | 34 | endingLineNumber = "212" |
35 | - landmarkName = "goBack()" | 35 | + landmarkName = "body" |
36 | - landmarkType = "7"> | 36 | + landmarkType = "24"> |
37 | </BreakpointContent> | 37 | </BreakpointContent> |
38 | </BreakpointProxy> | 38 | </BreakpointProxy> |
39 | </Breakpoints> | 39 | </Breakpoints> | ... | ... |
... | @@ -9,6 +9,10 @@ import Foundation | ... | @@ -9,6 +9,10 @@ import Foundation |
9 | 9 | ||
10 | public class swiftApi { | 10 | public class swiftApi { |
11 | 11 | ||
12 | + public init() { | ||
13 | + | ||
14 | + } | ||
15 | + | ||
12 | public func getUserTag() -> String { | 16 | public func getUserTag() -> String { |
13 | return "1" | 17 | return "1" |
14 | } | 18 | } |
... | @@ -24,4 +28,176 @@ public class swiftApi { | ... | @@ -24,4 +28,176 @@ public class swiftApi { |
24 | public func setCCMSLoyaltyCampaigns(campaigns: Array<Dictionary<String, String>>) { | 28 | public func setCCMSLoyaltyCampaigns(campaigns: Array<Dictionary<String, String>>) { |
25 | 29 | ||
26 | } | 30 | } |
31 | + | ||
32 | + public class CouponSetItemModel { | ||
33 | + let uuid: String? | ||
34 | + let admin_name: String? | ||
35 | + let name: String? | ||
36 | + let img_preview: String? | ||
37 | + let expiration: String? | ||
38 | + let description: String? | ||
39 | + let short_description: String? | ||
40 | + let discount: String? | ||
41 | + let sorting: Int? | ||
42 | + let inner_text: String? | ||
43 | + let buyable: Bool? | ||
44 | + let visible: Bool? | ||
45 | + | ||
46 | + init(dictionary: [String: Any]) { | ||
47 | + self.uuid = dictionary["uuid"] as? String? ?? "" | ||
48 | + self.admin_name = dictionary["admin_name"] as? String? ?? "" | ||
49 | + self.name = dictionary["name"] as? String? ?? "" | ||
50 | + self.img_preview = dictionary["img_preview"] as? String? ?? "" | ||
51 | + self.description = dictionary["description"] as? String? ?? "" | ||
52 | + self.short_description = dictionary["short_description"] as? String? ?? "" | ||
53 | + self.discount = dictionary["discount"] as? String? ?? "" | ||
54 | + self.sorting = dictionary["sorting"] as? Int? ?? nil | ||
55 | + self.inner_text = dictionary["inner_text"] as? String? ?? "" | ||
56 | + self.buyable = dictionary["buyable"] as? Bool? ?? false | ||
57 | + self.visible = dictionary["visible"] as? Bool? ?? false | ||
58 | + | ||
59 | + let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""] | ||
60 | + let expirationString = expirationObject?["value"] as? String? ?? "" | ||
61 | + | ||
62 | + // Example expirationString: Optional(2022-12-05 01:55) | ||
63 | + | ||
64 | + let dateFormatter = DateFormatter() | ||
65 | + dateFormatter.dateFormat = "yyyy-MM-dd hh:mm" | ||
66 | + if let date = dateFormatter.date(from: expirationString ?? "") { | ||
67 | + dateFormatter.dateFormat = "dd/MM/yyyy" | ||
68 | + let resultString = dateFormatter.string(from: date) | ||
69 | + self.expiration = resultString | ||
70 | + } else { | ||
71 | + self.expiration = "" | ||
72 | + } | ||
73 | + | ||
74 | + | ||
75 | + } | ||
76 | + | ||
77 | +// var asDictionary : [String:Any] { | ||
78 | +// let mirror = Mirror(reflecting: self) | ||
79 | +// let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in | ||
80 | +// guard let label = label else { return nil } | ||
81 | +// return (label, value) | ||
82 | +// }).compactMap { $0 }) | ||
83 | +// return dict | ||
84 | +// } | ||
85 | + } | ||
86 | + | ||
87 | + public class CouponSetsDataModel { | ||
88 | + var data: Array<CouponSetItemModel> = [] | ||
89 | + | ||
90 | + init() { //initializer method | ||
91 | + let instanceOfMyApi = MyApi() | ||
92 | + let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil) | ||
93 | + var couponSetsArray:Array<CouponSetItemModel> = [] | ||
94 | + | ||
95 | + if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] { | ||
96 | + let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! NSArray) | ||
97 | + | ||
98 | + | ||
99 | + for couponset in couponSetsData { | ||
100 | + let tempCouponset = CouponSetItemModel(dictionary: couponset as! [String : Any]) | ||
101 | + couponSetsArray.append(tempCouponset) | ||
102 | + } | ||
103 | + | ||
104 | + } | ||
105 | + self.data = couponSetsArray | ||
106 | + } | ||
107 | + | ||
108 | + var getData: Array<CouponSetItemModel> { | ||
109 | + get { // getter | ||
110 | + return data | ||
111 | + } | ||
112 | + } | ||
113 | + } | ||
114 | + | ||
115 | + public func getCouponSets() -> Array<CouponSetItemModel> { | ||
116 | + return CouponSetsDataModel().getData | ||
117 | + } | ||
118 | + | ||
119 | + | ||
120 | + public class CouponItemModel { | ||
121 | + let couponset_uuid: String? | ||
122 | + let name: String? | ||
123 | + let image: String? | ||
124 | + let expiration: String? | ||
125 | + let description: String? | ||
126 | + let discount: String? | ||
127 | + let coupon: String? | ||
128 | + let category: String? | ||
129 | + let barcode: String? | ||
130 | + let status: Int? | ||
131 | + | ||
132 | + init(dictionary: [String: Any]) { | ||
133 | + self.couponset_uuid = dictionary["couponset_uuid"] as? String? ?? "" | ||
134 | + self.name = dictionary["name"] as? String? ?? "" | ||
135 | + self.image = dictionary["image"] as? String? ?? "" | ||
136 | + self.description = dictionary["description"] as? String? ?? "" | ||
137 | + self.discount = dictionary["discount"] as? String? ?? "" | ||
138 | + self.coupon = dictionary["coupon"] as? String? ?? "" | ||
139 | + self.category = dictionary["category"] as? String? ?? "" | ||
140 | + self.barcode = dictionary["barcode"] as? String? ?? "" | ||
141 | + self.status = dictionary["status"] as? Int? ?? nil | ||
142 | + | ||
143 | + let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""] | ||
144 | + let expirationString = expirationObject?["value"] as? String? ?? "" | ||
145 | + | ||
146 | + // Example expirationString: Optional(2022-12-05 01:55) | ||
147 | + | ||
148 | + let dateFormatter = DateFormatter() | ||
149 | + dateFormatter.dateFormat = "yyyy-MM-dd hh:mm" | ||
150 | + if let date = dateFormatter.date(from: expirationString ?? "") { | ||
151 | + dateFormatter.dateFormat = "dd/MM/yyyy" | ||
152 | + let resultString = dateFormatter.string(from: date) | ||
153 | + self.expiration = resultString | ||
154 | + } else { | ||
155 | + self.expiration = "" | ||
156 | + } | ||
157 | + | ||
158 | + | ||
159 | + } | ||
160 | + | ||
161 | +// var asDictionary : [String:Any] { | ||
162 | +// let mirror = Mirror(reflecting: self) | ||
163 | +// let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in | ||
164 | +// guard let label = label else { return nil } | ||
165 | +// return (label, value) | ||
166 | +// }).compactMap { $0 }) | ||
167 | +// return dict | ||
168 | +// } | ||
169 | + } | ||
170 | + | ||
171 | + public class CouponsDataModel { | ||
172 | + var data: Array<CouponItemModel> = [] | ||
173 | + | ||
174 | + init() { //initializer method | ||
175 | + let instanceOfMyApi = MyApi() | ||
176 | + let coupons = instanceOfMyApi.getCoupons() | ||
177 | + var couponsArray:Array<CouponItemModel> = [] | ||
178 | + | ||
179 | + if let myCouponsDictionary = coupons as? [String : AnyObject] { | ||
180 | + let couponsData = (myCouponsDictionary["result"] as! NSArray) | ||
181 | + | ||
182 | + | ||
183 | + for coupon in couponsData { | ||
184 | + let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any]) | ||
185 | + couponsArray.append(tempCoupon) | ||
186 | + } | ||
187 | + | ||
188 | + } | ||
189 | + self.data = couponsArray | ||
190 | + } | ||
191 | + | ||
192 | + var getData: Array<CouponItemModel> { | ||
193 | + get { // getter | ||
194 | + return data | ||
195 | + } | ||
196 | + } | ||
197 | + } | ||
198 | + | ||
199 | + public func getCoupons() -> Array<CouponItemModel> { | ||
200 | + return CouponsDataModel().getData | ||
201 | + } | ||
202 | + | ||
27 | } | 203 | } | ... | ... |
-
Please register or login to post a comment