Manos Chorianopoulos

swiftApi model changes

......@@ -128,6 +128,7 @@ public class swiftApi {
let category: String?
let barcode: String?
let status: Int?
var couponset_data: CouponSetItemModel?
init(dictionary: [String: Any]) {
self.couponset_uuid = dictionary["couponset_uuid"] as? String? ?? ""
......@@ -139,6 +140,7 @@ public class swiftApi {
self.category = dictionary["category"] as? String? ?? ""
self.barcode = dictionary["barcode"] as? String? ?? ""
self.status = dictionary["status"] as? Int? ?? nil
self.couponset_data = dictionary["couponset_data"] as? CouponSetItemModel? ?? nil
let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""]
let expirationString = expirationObject?["value"] as? String? ?? ""
......@@ -158,6 +160,11 @@ public class swiftApi {
}
public func setCouponSetData(_ couponSet: CouponSetItemModel) {
self.couponset_data = couponSet
}
// var asDictionary : [String:Any] {
// let mirror = Mirror(reflecting: self)
// let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in
......@@ -174,26 +181,69 @@ public class swiftApi {
init() { //initializer method
let instanceOfMyApi = MyApi()
let coupons = instanceOfMyApi.getCoupons()
var couponsArray:Array<CouponItemModel> = []
let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil)
if let myCouponsDictionary = coupons as? [String : AnyObject] {
let couponsData = (myCouponsDictionary["result"] as! NSArray)
var couponsArray:Array<CouponItemModel> = []
for coupon in couponsData {
let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any])
if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] {
let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>)
if let myCouponsDictionary = coupons as? [String : AnyObject] {
let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>)
if let sets = couponSetsData as? NSArray {
for set in sets {
let s = set as! [String : Any]
if let cpns = couponsData as? NSArray {
for coupon in cpns {
var c = coupon as! [String : Any]
// var temp = NSMutableDictionary(dictionary: s);
if c["couponset_uuid"] as! String == s["uuid"] as! String {
let temp = NSMutableDictionary(dictionary: c);
temp.setValue(s as [AnyHashable : Any],forKey: "couponset_data")
let tempCoupon = CouponItemModel(dictionary: temp as! [String : Any])
couponsArray.append(tempCoupon)
}
}
}
}
}
}
}
// if let myCouponsDictionary = coupons as? [String : AnyObject] {
// let couponsData = (myCouponsDictionary["result"] as! NSArray)
//
//
// for coupon in couponsData {
// let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any])
// couponsArray.append(tempCoupon)
// }
//
// }
self.data = couponsArray
}
var getData: Array<CouponItemModel> {
get { // getter
return data
return data.filter({
return $0.status == 1
})
}
}
var getOldCoupons: Array<CouponItemModel> {
get { // getter
return data.filter({
return $0.status != 1
})
}
}
}
public func getCoupons() -> Array<CouponItemModel> {
......