You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

89 lines
2.3 KiB

//
// CouponBoxService.swift
// GME Remit
//
// Created by Jeongbae Kong on 03/12/2019.
//Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
//
import Foundation
class CouponBoxService: CouponBoxServiceType {
func fetchCouponBox(
success: @escaping (([CouponBoxModel]?) -> Void),
failure: @escaping ((Error) -> Void)
) {
guard let customerId = GMEDB.shared.user.string(.senderId) else {
let error = NSError.init(
domain: "Network",
code: 0,
userInfo: [NSLocalizedDescriptionKey : "no exist senderId"])
failure(error)
return
}
// let testString =
// """
// {
// "ErrorCode": "0",
// "Msg": "SUCCESS",
// "Id": "",
// "Extra": "",
// "Extra2": "",
// "Data": [
// {
// "schemeId": "10",
// "couponType": "1",
// "couponName": "100% coupon",
// "discountType": "1",
// "discountValue": "100.0000",
// "expireDate": "2020-06-28 5:39:12",
// "buyDate": "2019-06-28 5:51:53"
// },
// {
// "schemeId": "12",
// "couponType": "2",
// "couponName": "5000 Won Discount Coupon",
// "discountType": "",
// "discountValue": "5000",
// "expireDate": "2020-06-28 5:39:12",
// "buyDate": "2019-06-28 5:51:53"
// }
// ]
// }
// """
// let json = ResponseContainerArray<CouponBoxModel>(JSONString: testString)
// success(json?.data)
let parameter = [
"customerId": customerId
]
let url = baseUrlWithoutVersion + "v1/mobile/GetCouponList"
auth.request(
method: .post,
url: url,
params: parameter,
success: { (response: CouponBoxModelContainer) in
if (response.errorCode ?? "") == "1" {
let error = NSError.init(
domain: "Network",
code: 0,
userInfo: [NSLocalizedDescriptionKey :
response.message ?? ""])
failure(error)
} else {
let model = response.data
success(model)
}
},
failure: { failure($0) }
)
}
}