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
69 lines
1.9 KiB
//
|
|
// RecipientsService.swift
|
|
// GME Remit
|
|
//
|
|
// Created by InKwon James Kim on 08/08/2019.
|
|
//Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import Alamofire
|
|
|
|
class RecipientsService: RecipientsServiceType {
|
|
func fetchRecipients(
|
|
success: @escaping (FetchRecipientsModel) -> Void,
|
|
failure: @escaping (Error) -> Void
|
|
) {
|
|
let senderID = GMEDB.shared.user.string(.senderId) ?? ""
|
|
APIRouter
|
|
.fetchRecipients(senderID: senderID)
|
|
.json(success: success, failure: failure)
|
|
}
|
|
|
|
func fetchReciepientList(
|
|
username: String,
|
|
success: @escaping (RecipientListWrapperContainer?) -> Void,
|
|
failure: @escaping (Error) -> Void
|
|
) {
|
|
let url = baseUrl + "/mobile/" + username + "/receivers"
|
|
let params = ["search": ""]
|
|
auth.request(
|
|
method: .get,
|
|
url: url,
|
|
params: params,
|
|
encoding: URLEncoding.default,
|
|
success: { (response: RecipientListContainer) in
|
|
if (response.errorCode ?? "") == "1" {
|
|
let error = NSError(domain: "Network", code: 0, message: response.message ?? "")
|
|
failure(error)
|
|
} else {
|
|
let model = response.data
|
|
success(model)
|
|
}
|
|
},
|
|
failure: {failure($0)}
|
|
)
|
|
}
|
|
|
|
func deleteRecipient(
|
|
username: String,
|
|
reciepient: Recipient,
|
|
success: @escaping () -> Void,
|
|
failure: @escaping (Error) -> Void
|
|
) {
|
|
let id = GMEDB.shared.user.string(.senderId) ?? ""
|
|
let recipientID = reciepient.receiverID ?? ""
|
|
APIRouter.deleteRecipient(senderID: id, recipientID: recipientID)
|
|
.request(
|
|
success: { (response: ResponseContainer<String>) in
|
|
if response.errorCode != "0" {
|
|
let error = NSError(domain: "Network", code: 0, message: "Failed Delete Recipient")
|
|
failure(error)
|
|
}
|
|
|
|
success()
|
|
},
|
|
failure: failure
|
|
)
|
|
}
|
|
}
|