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

  1. //
  2. // CouponBoxService.swift
  3. // GME Remit
  4. //
  5. // Created by Jeongbae Kong on 03/12/2019.
  6. //Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class CouponBoxService: CouponBoxServiceType {
  10. func fetchCouponBox(
  11. success: @escaping (([CouponBoxModel]?) -> Void),
  12. failure: @escaping ((Error) -> Void)
  13. ) {
  14. guard let customerId = GMEDB.shared.user.string(.senderId) else {
  15. let error = NSError.init(
  16. domain: "Network",
  17. code: 0,
  18. userInfo: [NSLocalizedDescriptionKey : "no exist senderId"])
  19. failure(error)
  20. return
  21. }
  22. // let testString =
  23. // """
  24. // {
  25. // "ErrorCode": "0",
  26. // "Msg": "SUCCESS",
  27. // "Id": "",
  28. // "Extra": "",
  29. // "Extra2": "",
  30. // "Data": [
  31. // {
  32. // "schemeId": "10",
  33. // "couponType": "1",
  34. // "couponName": "100% coupon",
  35. // "discountType": "1",
  36. // "discountValue": "100.0000",
  37. // "expireDate": "2020-06-28 5:39:12",
  38. // "buyDate": "2019-06-28 5:51:53"
  39. // },
  40. // {
  41. // "schemeId": "12",
  42. // "couponType": "2",
  43. // "couponName": "5000 Won Discount Coupon",
  44. // "discountType": "",
  45. // "discountValue": "5000",
  46. // "expireDate": "2020-06-28 5:39:12",
  47. // "buyDate": "2019-06-28 5:51:53"
  48. // }
  49. // ]
  50. // }
  51. // """
  52. // let json = ResponseContainerArray<CouponBoxModel>(JSONString: testString)
  53. // success(json?.data)
  54. let parameter = [
  55. "customerId": customerId
  56. ]
  57. let url = baseUrlWithoutVersion + "v1/mobile/GetCouponList"
  58. auth.request(
  59. method: .post,
  60. url: url,
  61. params: parameter,
  62. success: { (response: CouponBoxModelContainer) in
  63. if (response.errorCode ?? "") == "1" {
  64. let error = NSError.init(
  65. domain: "Network",
  66. code: 0,
  67. userInfo: [NSLocalizedDescriptionKey :
  68. response.message ?? ""])
  69. failure(error)
  70. } else {
  71. let model = response.data
  72. success(model)
  73. }
  74. },
  75. failure: { failure($0) }
  76. )
  77. }
  78. }