Vasilis
...@@ -140,6 +140,7 @@ public class swiftApi { ...@@ -140,6 +140,7 @@ public class swiftApi {
140 let category: String? 140 let category: String?
141 let barcode: String? 141 let barcode: String?
142 let status: Int? 142 let status: Int?
143 + var couponset_data: CouponSetItemModel?
143 144
144 init(dictionary: [String: Any]) { 145 init(dictionary: [String: Any]) {
145 self.couponset_uuid = dictionary["couponset_uuid"] as? String? ?? "" 146 self.couponset_uuid = dictionary["couponset_uuid"] as? String? ?? ""
...@@ -151,6 +152,7 @@ public class swiftApi { ...@@ -151,6 +152,7 @@ public class swiftApi {
151 self.category = dictionary["category"] as? String? ?? "" 152 self.category = dictionary["category"] as? String? ?? ""
152 self.barcode = dictionary["barcode"] as? String? ?? "" 153 self.barcode = dictionary["barcode"] as? String? ?? ""
153 self.status = dictionary["status"] as? Int? ?? nil 154 self.status = dictionary["status"] as? Int? ?? nil
155 + self.couponset_data = dictionary["couponset_data"] as? CouponSetItemModel? ?? nil
154 156
155 let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""] 157 let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""]
156 let expirationString = expirationObject?["value"] as? String? ?? "" 158 let expirationString = expirationObject?["value"] as? String? ?? ""
...@@ -170,6 +172,11 @@ public class swiftApi { ...@@ -170,6 +172,11 @@ public class swiftApi {
170 172
171 } 173 }
172 174
175 +
176 + public func setCouponSetData(_ couponSet: CouponSetItemModel) {
177 + self.couponset_data = couponSet
178 + }
179 +
173 // var asDictionary : [String:Any] { 180 // var asDictionary : [String:Any] {
174 // let mirror = Mirror(reflecting: self) 181 // let mirror = Mirror(reflecting: self)
175 // let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in 182 // let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in
...@@ -186,26 +193,69 @@ public class swiftApi { ...@@ -186,26 +193,69 @@ public class swiftApi {
186 init() { //initializer method 193 init() { //initializer method
187 let instanceOfMyApi = MyApi() 194 let instanceOfMyApi = MyApi()
188 let coupons = instanceOfMyApi.getCoupons() 195 let coupons = instanceOfMyApi.getCoupons()
196 + let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil)
197 +
189 var couponsArray:Array<CouponItemModel> = [] 198 var couponsArray:Array<CouponItemModel> = []
190 199
191 - if let myCouponsDictionary = coupons as? [String : AnyObject] { 200 +
192 - let couponsData = (myCouponsDictionary["result"] as! NSArray) 201 + if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] {
193 - 202 + let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>)
194 - 203 + if let myCouponsDictionary = coupons as? [String : AnyObject] {
195 - for coupon in couponsData { 204 + let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>)
196 - let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any]) 205 + if let sets = couponSetsData as? NSArray {
197 - couponsArray.append(tempCoupon) 206 + for set in sets {
207 + let s = set as! [String : Any]
208 + if let cpns = couponsData as? NSArray {
209 + for coupon in cpns {
210 + var c = coupon as! [String : Any]
211 + // var temp = NSMutableDictionary(dictionary: s);
212 + if c["couponset_uuid"] as! String == s["uuid"] as! String {
213 + let temp = NSMutableDictionary(dictionary: c);
214 +
215 + temp.setValue(s as [AnyHashable : Any],forKey: "couponset_data")
216 +
217 + let tempCoupon = CouponItemModel(dictionary: temp as! [String : Any])
218 + couponsArray.append(tempCoupon)
219 + }
220 +
221 + }
222 + }
223 +
224 + }
225 + }
198 } 226 }
199 -
200 } 227 }
228 +
229 +// if let myCouponsDictionary = coupons as? [String : AnyObject] {
230 +// let couponsData = (myCouponsDictionary["result"] as! NSArray)
231 +//
232 +//
233 +// for coupon in couponsData {
234 +// let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any])
235 +// couponsArray.append(tempCoupon)
236 +// }
237 +//
238 +// }
201 self.data = couponsArray 239 self.data = couponsArray
202 } 240 }
203 241
204 var getData: Array<CouponItemModel> { 242 var getData: Array<CouponItemModel> {
205 get { // getter 243 get { // getter
206 - return data 244 + return data.filter({
245 + return $0.status == 1
246 + })
207 } 247 }
208 } 248 }
249 +
250 +
251 + var getOldCoupons: Array<CouponItemModel> {
252 + get { // getter
253 + return data.filter({
254 + return $0.status != 1
255 + })
256 + }
257 + }
258 +
209 } 259 }
210 260
211 public func getCoupons() -> Array<CouponItemModel> { 261 public func getCoupons() -> Array<CouponItemModel> {
......