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.
72 lines
1.6 KiB
72 lines
1.6 KiB
//
|
|
// RecipientsInteractor.swift
|
|
// GME Remit
|
|
//
|
|
// Created by InKwon James Kim on 08/08/2019.
|
|
//Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class RecipientsInteractor {
|
|
|
|
// MARK: Properties
|
|
|
|
weak var output: RecipientsInteractorOutput?
|
|
private let service: RecipientsServiceType
|
|
|
|
private var recipients: [Recipient]?
|
|
private var accounts: [Account]?
|
|
|
|
// MARK: Initialization
|
|
|
|
init(service: RecipientsServiceType) {
|
|
self.service = service
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: Recipients interactor input interface
|
|
|
|
extension RecipientsInteractor: RecipientsInteractorInput {
|
|
func fetchRecipients(isRefresh: Bool) {
|
|
if isRefresh {
|
|
fetchRecipients()
|
|
return
|
|
}
|
|
|
|
guard
|
|
let recipients = self.recipients,
|
|
let accounts = self.accounts
|
|
else {
|
|
fetchRecipients()
|
|
return
|
|
}
|
|
|
|
output?.setRecipients(using: recipients)
|
|
output?.setAccounts(using: accounts)
|
|
}
|
|
|
|
func deleteRecipient(who recipient: Recipient) {
|
|
let myUsername = GMEDB.shared.user.string(.userId) ?? ""
|
|
service.deleteRecipient(
|
|
username: myUsername,
|
|
reciepient: recipient,
|
|
success: { self.fetchRecipients(isRefresh: true) },
|
|
failure: {self.output?.setError(with: $0)}
|
|
)
|
|
}
|
|
|
|
private func fetchRecipients() {
|
|
service.fetchRecipients(
|
|
success: {
|
|
self.recipients = $0.recipients
|
|
self.accounts = $0.accounts
|
|
|
|
self.output?.setRecipients(using: $0.recipients ?? [])
|
|
self.output?.setAccounts(using: $0.accounts ?? [])
|
|
},
|
|
failure: { self.output?.setError(with:$0) }
|
|
)
|
|
}
|
|
}
|