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.

52 lines
1.2 KiB

5 years ago
5 years ago
  1. //
  2. // HotLineInteractor.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon Devik Kim on 23/05/2019.
  6. //Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class HotLineInteractor {
  10. // MARK: Properties
  11. weak var output: HotLineInteractorOutput?
  12. private let service: HotLineServiceType
  13. // MARK: Initialization
  14. init(service: HotLineServiceType) {
  15. self.service = service
  16. }
  17. }
  18. // MARK: HotLine interactor input interface
  19. extension HotLineInteractor: HotLineInteractorInput {
  20. func fetchHotLines() {
  21. service.fetchHotLines(
  22. success: {
  23. // Base selected Language
  24. // Base Native Country as lowercased
  25. let userCountry = GMEDB.shared.user.string(.countryCode)?.lowercased()
  26. guard
  27. let userHotLine = $0?.filter({ $0.countryCode == userCountry }),
  28. let anotherHotLines = $0?.filter ({ $0.countryCode != userCountry })
  29. else {
  30. self.output?.setHotLine(with: $0)
  31. return
  32. }
  33. let restoredHotLines = userHotLine + anotherHotLines
  34. self.output?.setHotLine(with: restoredHotLines)
  35. },
  36. failure: {
  37. self.output?.setError(with: $0)
  38. }
  39. )
  40. }
  41. }