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.

69 lines
1.9 KiB

  1. //
  2. // RecipientsService.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon James Kim on 08/08/2019.
  6. //Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. import Alamofire
  10. class RecipientsService: RecipientsServiceType {
  11. func fetchRecipients(
  12. success: @escaping (FetchRecipientsModel) -> Void,
  13. failure: @escaping (Error) -> Void
  14. ) {
  15. let senderID = GMEDB.shared.user.string(.senderId) ?? ""
  16. APIRouter
  17. .fetchRecipients(senderID: senderID)
  18. .json(success: success, failure: failure)
  19. }
  20. func fetchReciepientList(
  21. username: String,
  22. success: @escaping (RecipientListWrapperContainer?) -> Void,
  23. failure: @escaping (Error) -> Void
  24. ) {
  25. let url = baseUrl + "/mobile/" + username + "/receivers"
  26. let params = ["search": ""]
  27. auth.request(
  28. method: .get,
  29. url: url,
  30. params: params,
  31. encoding: URLEncoding.default,
  32. success: { (response: RecipientListContainer) in
  33. if (response.errorCode ?? "") == "1" {
  34. let error = NSError(domain: "Network", code: 0, message: response.message ?? "")
  35. failure(error)
  36. } else {
  37. let model = response.data
  38. success(model)
  39. }
  40. },
  41. failure: {failure($0)}
  42. )
  43. }
  44. func deleteRecipient(
  45. username: String,
  46. reciepient: Recipient,
  47. success: @escaping () -> Void,
  48. failure: @escaping (Error) -> Void
  49. ) {
  50. let id = GMEDB.shared.user.string(.senderId) ?? ""
  51. let recipientID = reciepient.receiverID ?? ""
  52. APIRouter.deleteRecipient(senderID: id, recipientID: recipientID)
  53. .request(
  54. success: { (response: ResponseContainer<String>) in
  55. if response.errorCode != "0" {
  56. let error = NSError(domain: "Network", code: 0, message: "Failed Delete Recipient")
  57. failure(error)
  58. }
  59. success()
  60. },
  61. failure: failure
  62. )
  63. }
  64. }