Manos Chorianopoulos

ShareViewController CouponSharing optimizations

......@@ -285,17 +285,22 @@ import SwiftEventBus
if (response?.getStatus == 1) {
self.showSuccessDialog("Συγχαρητήρια!","Μόλις έκανες δώρο ένα κουπόνι!")
swiftApi().getCouponsAsync(getCouponsCallback, failureCallback: {errorCode in })
func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void {
if (couponsData != nil) {
DispatchQueue.main.async {
if let tempCoupon = self.coupon {
swiftApi().removeCouponItem(couponArg: tempCoupon)
SwiftEventBus.post("coupons_fetched")
}
} else {
}
}
// swiftApi().getCouponsAsync(getCouponsCallback, failureCallback: {errorCode in })
// func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void {
// if (couponsData != nil) {
// DispatchQueue.main.async {
// SwiftEventBus.post("coupons_fetched")
// }
// } else {
// }
// }
} else if (response?.getStatus == 4) {
self.showDialog("Αποτυχία", response?.getMsg ?? "")
......
......@@ -9259,11 +9259,16 @@ public class swiftApi {
}
public func addCouponItem(newCoupon: CouponItemModel) {
var tempCouponList = getCouponList()
var tempCouponList = swiftApi().getCouponList()
tempCouponList.append(newCoupon)
swiftApi().setCouponList(tempCouponList)
}
public func removeCouponItem(couponArg: CouponItemModel) {
let tempCouponList = swiftApi().getCouponList().filter { $0.coupon != couponArg.coupon }
swiftApi().setCouponList(tempCouponList)
}
public func removeCampaignItem(campaignArg: CampaignItemModel) {
let allCampaigns = swiftApi().getAllCampaignList().filter { $0.session_uuid != campaignArg.session_uuid }
swiftApi().setUniqueCampaignList(allCampaigns)
......