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.

51 lines
1.4 KiB

  1. //
  2. // EditReciepientInteractor.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 28/08/2018.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class EditReciepientInteractor {
  10. // MARK: Properties
  11. weak var output: EditReciepientInteractorOutput?
  12. private let service: EditReciepientServiceType
  13. var reciepient: Recipient
  14. // MARK: Initialization
  15. init(service: EditReciepientServiceType, reciepient: Recipient) {
  16. self.service = service
  17. self.reciepient = reciepient
  18. }
  19. // MARK: Converting entities
  20. }
  21. // MARK: EditReciepient interactor input interface
  22. extension EditReciepientInteractor: EditReciepientInteractorInput {
  23. func viewIsReady() {
  24. self.service.fetch(success: { (model) in
  25. self.output?.show(model: model)
  26. self.output?.show(recipient: self.reciepient)
  27. }) { (error) in
  28. self.output?.show(error: error)
  29. }
  30. }
  31. func save(reciepient: Recipient) {
  32. let defaults = UserDefaults.standard
  33. let myUsername = defaults.string(forKey: "com.gmeremit.username") ?? ""
  34. self.service.save(model: reciepient.serialize(), username: myUsername, success: { (reciepient) in
  35. self.output?.success()
  36. }) { (error) in
  37. self.output?.show(error: error)
  38. }
  39. }
  40. }