Showing
2 changed files
with
24 additions
and
149 deletions
No preview for this file type
| ... | @@ -13,146 +13,6 @@ import Foundation | ... | @@ -13,146 +13,6 @@ import Foundation |
| 13 | import UIKit | 13 | import UIKit |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | -class CouponSetItemModel { | ||
| 17 | - let uuid: String? | ||
| 18 | - let admin_name: String? | ||
| 19 | - let name: String? | ||
| 20 | - let img_preview: String? | ||
| 21 | - let expiration: String? | ||
| 22 | - let description: String? | ||
| 23 | - let short_description: String? | ||
| 24 | - let discount: String? | ||
| 25 | - | ||
| 26 | - init(dictionary: [String: Any]) { | ||
| 27 | - self.uuid = dictionary["uuid"] as? String? ?? "" | ||
| 28 | - self.admin_name = dictionary["admin_name"] as? String? ?? "" | ||
| 29 | - self.name = dictionary["name"] as? String? ?? "" | ||
| 30 | - self.img_preview = dictionary["img_preview"] as? String? ?? "" | ||
| 31 | - self.description = dictionary["description"] as? String? ?? "" | ||
| 32 | - self.short_description = dictionary["short_description"] as? String? ?? "" | ||
| 33 | - self.discount = dictionary["discount"] as? String? ?? "" | ||
| 34 | - | ||
| 35 | - let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""] | ||
| 36 | - let expirationString = expirationObject?["value"] as? String? ?? "" | ||
| 37 | - | ||
| 38 | -// Example expirationString: Optional(2022-12-05 01:55) | ||
| 39 | - | ||
| 40 | - let dateFormatter = DateFormatter() | ||
| 41 | - dateFormatter.dateFormat = "yyyy-MM-dd hh:mm" | ||
| 42 | - if let date = dateFormatter.date(from: expirationString ?? "") { | ||
| 43 | - dateFormatter.dateFormat = "dd/MM/yyyy" | ||
| 44 | - let resultString = dateFormatter.string(from: date) | ||
| 45 | - self.expiration = resultString | ||
| 46 | - } else { | ||
| 47 | - self.expiration = "" | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - var asDictionary : [String:Any] { | ||
| 54 | - let mirror = Mirror(reflecting: self) | ||
| 55 | - let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in | ||
| 56 | - guard let label = label else { return nil } | ||
| 57 | - return (label, value) | ||
| 58 | - }).compactMap { $0 }) | ||
| 59 | - return dict | ||
| 60 | - } | ||
| 61 | -} | ||
| 62 | - | ||
| 63 | -class CouponDataModel { | ||
| 64 | - var data: Array<CouponSetItemModel> = [] | ||
| 65 | - | ||
| 66 | - init() { //initializer method | ||
| 67 | - let instanceOfMyApi = MyApi() | ||
| 68 | - let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil) | ||
| 69 | - var couponSetsArray:Array<CouponSetItemModel> = [] | ||
| 70 | - | ||
| 71 | - if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] { | ||
| 72 | - let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! NSArray) | ||
| 73 | - | ||
| 74 | - | ||
| 75 | - for couponset in couponSetsData { | ||
| 76 | - let tempCouponset = CouponSetItemModel(dictionary: couponset as! [String : Any]) | ||
| 77 | - couponSetsArray.append(tempCouponset) | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - } | ||
| 81 | - self.data = couponSetsArray | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - var getData: Array<CouponSetItemModel> { | ||
| 85 | - get { // getter | ||
| 86 | - return data | ||
| 87 | - } | ||
| 88 | - } | ||
| 89 | -} | ||
| 90 | - | ||
| 91 | - | ||
| 92 | -class CampaignItemModel { | ||
| 93 | - let index_url: String? | ||
| 94 | - let logo_url: String? | ||
| 95 | - let offer_category: String? | ||
| 96 | - let title: String? | ||
| 97 | - let subtitle: String? | ||
| 98 | - let session_uuid: String? | ||
| 99 | - let subcategory: String? | ||
| 100 | - | ||
| 101 | - init(dictionary: [String: Any]) { | ||
| 102 | - self.index_url = dictionary["index_url"] as? String? ?? "" | ||
| 103 | - self.logo_url = dictionary["logo_url"] as? String? ?? "" | ||
| 104 | - self.offer_category = dictionary["offer_category"] as? String? ?? "" | ||
| 105 | - self.title = dictionary["title"] as? String? ?? "" | ||
| 106 | - self.subtitle = dictionary["subtitle"] as? String? ?? "" | ||
| 107 | - self.session_uuid = dictionary["session_uuid"] as? String? ?? "" | ||
| 108 | - | ||
| 109 | -// let extra_fields = dictionary["extra_fields"] as? [String: Any]? ?? ["":""] | ||
| 110 | - let extra_fields = dictionary["extra_fields"] as AnyObject | ||
| 111 | - var extra_fields_parsed:[String: Any] | ||
| 112 | - | ||
| 113 | - let json = extra_fields.data(using: String.Encoding.utf8.rawValue) | ||
| 114 | - do { | ||
| 115 | - if let jsonArray = try JSONSerialization.jsonObject(with: json!, options: .allowFragments) as? [String:AnyObject] | ||
| 116 | - { | ||
| 117 | - extra_fields_parsed = jsonArray; | ||
| 118 | - self.subcategory = extra_fields_parsed["subcategory"] as? String? ?? "" | ||
| 119 | - } else { | ||
| 120 | - self.subcategory = "" | ||
| 121 | - print("bad json") | ||
| 122 | - } | ||
| 123 | - } catch let error as NSError { | ||
| 124 | - self.subcategory = "" | ||
| 125 | - print(error) | ||
| 126 | - } | ||
| 127 | - | ||
| 128 | - } | ||
| 129 | -} | ||
| 130 | - | ||
| 131 | -class CampaignDataModel { | ||
| 132 | - var data: Array<CampaignItemModel> = [] | ||
| 133 | - | ||
| 134 | - init() { //initializer method | ||
| 135 | - let instanceOfMyApi = MyApi() | ||
| 136 | - let products = instanceOfMyApi.getInbox() as NSMutableArray? | ||
| 137 | - | ||
| 138 | - var giftsArray:Array<CampaignItemModel> = [] | ||
| 139 | - | ||
| 140 | - | ||
| 141 | - for gift in products ?? [] { | ||
| 142 | - let tempGift = CampaignItemModel(dictionary: gift as! [String : Any]) | ||
| 143 | - giftsArray.append(tempGift) | ||
| 144 | - } | ||
| 145 | - | ||
| 146 | - self.data = giftsArray; | ||
| 147 | - | ||
| 148 | - } | ||
| 149 | - | ||
| 150 | - var getData: Array<CampaignItemModel> { | ||
| 151 | - get { // getter | ||
| 152 | - return data | ||
| 153 | - } | ||
| 154 | - } | ||
| 155 | -} | ||
| 156 | 16 | ||
| 157 | extension String { | 17 | extension String { |
| 158 | func htmlToString() -> String { | 18 | func htmlToString() -> String { |
| ... | @@ -374,7 +234,7 @@ extension GiftsView { | ... | @@ -374,7 +234,7 @@ extension GiftsView { |
| 374 | 234 | ||
| 375 | 235 | ||
| 376 | struct giftItemView: View { | 236 | struct giftItemView: View { |
| 377 | - var item: CampaignItemModel | 237 | + var item: swiftApi.CampaignItemModel |
| 378 | var isFirst: Bool | 238 | var isFirst: Bool |
| 379 | var isLast: Bool | 239 | var isLast: Bool |
| 380 | var parentView: UIView | 240 | var parentView: UIView |
| ... | @@ -416,7 +276,7 @@ extension GiftsView { | ... | @@ -416,7 +276,7 @@ extension GiftsView { |
| 416 | } | 276 | } |
| 417 | 277 | ||
| 418 | struct giftsContainer: View { | 278 | struct giftsContainer: View { |
| 419 | - @State var gifts:Array<CampaignItemModel> = [] | 279 | + @State var gifts:Array<swiftApi.CampaignItemModel> = [] |
| 420 | @State var title:String = "" | 280 | @State var title:String = "" |
| 421 | @State var parentView:UIView | 281 | @State var parentView:UIView |
| 422 | 282 | ||
| ... | @@ -452,7 +312,7 @@ extension GiftsView { | ... | @@ -452,7 +312,7 @@ extension GiftsView { |
| 452 | } | 312 | } |
| 453 | 313 | ||
| 454 | struct couponsContainer: View { | 314 | struct couponsContainer: View { |
| 455 | - @State var coupons:Array<CouponSetItemModel> = [] | 315 | + @State var coupons:Array<swiftApi.CouponSetItemModel> = [] |
| 456 | @State var title:String = "" | 316 | @State var title:String = "" |
| 457 | @State var parentView:UIView | 317 | @State var parentView:UIView |
| 458 | 318 | ||
| ... | @@ -489,7 +349,7 @@ extension GiftsView { | ... | @@ -489,7 +349,7 @@ extension GiftsView { |
| 489 | } | 349 | } |
| 490 | 350 | ||
| 491 | struct couponItemView: View { | 351 | struct couponItemView: View { |
| 492 | - var item: CouponSetItemModel | 352 | + var item: swiftApi.CouponSetItemModel |
| 493 | var isFirst: Bool | 353 | var isFirst: Bool |
| 494 | var isLast: Bool | 354 | var isLast: Bool |
| 495 | var parentView: UIView | 355 | var parentView: UIView |
| ... | @@ -499,9 +359,9 @@ extension GiftsView { | ... | @@ -499,9 +359,9 @@ extension GiftsView { |
| 499 | var body: some View { | 359 | var body: some View { |
| 500 | Button { | 360 | Button { |
| 501 | // GiftItem Action | 361 | // GiftItem Action |
| 502 | - let tempItem = item.asDictionary | 362 | +// let tempItem = item.asDictionary |
| 503 | - let instanceOfMyApi = MyApi() | 363 | + let instanceOfMySwiftApi = swiftApi() |
| 504 | - let couponViewController = instanceOfMyApi.openCoupon(parentView, coupon: tempItem)! | 364 | + let couponViewController = instanceOfMySwiftApi.openCoupon(parentView, coupon: item)! |
| 505 | couponViewController.view.tag = 2 | 365 | couponViewController.view.tag = 2 |
| 506 | // addChild(couponsViewController) | 366 | // addChild(couponsViewController) |
| 507 | couponViewController.view.frame = parentView.frame | 367 | couponViewController.view.frame = parentView.frame |
| ... | @@ -598,11 +458,26 @@ extension GiftsView { | ... | @@ -598,11 +458,26 @@ extension GiftsView { |
| 598 | struct GiftsView: View { | 458 | struct GiftsView: View { |
| 599 | var parentView: UIView | 459 | var parentView: UIView |
| 600 | 460 | ||
| 601 | - var coupons:Array<CouponSetItemModel> = CouponDataModel().getData | 461 | +// var coupons:Array<CouponSetItemModel> = CouponDataModel().getData |
| 602 | - var campains:Array<CampaignItemModel> = CampaignDataModel().getData.filter { $0.offer_category == "gifts_for_you" } | 462 | +// var campains:Array<CampaignItemModel> = CampaignDataModel().getData.filter { $0.offer_category == "gifts_for_you" } |
| 463 | + | ||
| 464 | + | ||
| 465 | + var coupons:Array<swiftApi.CouponSetItemModel> = [] | ||
| 466 | + var campains:Array<swiftApi.CampaignItemModel> = [] | ||
| 603 | 467 | ||
| 604 | var uiscreen = UIScreen.main.bounds | 468 | var uiscreen = UIScreen.main.bounds |
| 605 | 469 | ||
| 470 | + init(parentView: UIView) { //initializer method | ||
| 471 | + | ||
| 472 | + let instanceOfMySwiftApi = swiftApi() | ||
| 473 | + let couponsData = instanceOfMySwiftApi.getCouponSets() | ||
| 474 | + let campaignsData = instanceOfMySwiftApi.getCampaigns() | ||
| 475 | + | ||
| 476 | + self.coupons = couponsData | ||
| 477 | + self.campains = campaignsData.filter { $0.offer_category == "gifts_for_you" } | ||
| 478 | + self.parentView = parentView | ||
| 479 | + } | ||
| 480 | + | ||
| 606 | func goBack(){ | 481 | func goBack(){ |
| 607 | for subview in parentView.subviews { | 482 | for subview in parentView.subviews { |
| 608 | if(subview.tag == 5) { | 483 | if(subview.tag == 5) { | ... | ... |
-
Please register or login to post a comment