-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
240 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
SWDestinyTrades/Classes/Sets/Interactor/SetsListInteractor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// SetsListInteractor.swift | ||
// SWDestinyTrades | ||
// | ||
// Created by Diogo Autilio on 29/11/23. | ||
// Copyright © 2023 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol SetsInteractorProtocol { | ||
func retrieveSets() async throws -> [SetDTO] | ||
} | ||
|
||
final class SetsListInteractor: SetsInteractorProtocol { | ||
|
||
private let service: SWDestinyServiceProtocol | ||
|
||
init(service: SWDestinyServiceProtocol = SWDestinyService()) { | ||
self.service = service | ||
} | ||
|
||
func retrieveSets() async throws -> [SetDTO] { | ||
return try await service.retrieveSetList() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
SWDestinyTrades/Classes/Sets/Presenter/SetsListPresenter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// SetsListPresenter.swift | ||
// SWDestinyTrades | ||
// | ||
// Created by Diogo Autilio on 28/11/23. | ||
// Copyright © 2023 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol SetsPresenterProtocol { | ||
func viewDidLoad() | ||
func retrieveSets() | ||
func aboutButtonTouched() | ||
func searchButtonTouched() | ||
func didSelectSet(_ set: SetDTO) | ||
} | ||
|
||
final class SetsPresenter: SetsPresenterProtocol { | ||
|
||
weak var view: SetsViewProtocol? | ||
private let interactor: SetsInteractorProtocol | ||
private let database: DatabaseProtocol? | ||
private let navigator: SetsListNavigator | ||
|
||
init(view: SetsViewProtocol, | ||
interactor: SetsInteractorProtocol, | ||
database: DatabaseProtocol?, | ||
navigator: SetsListNavigator) { | ||
self.view = view | ||
self.interactor = interactor | ||
self.database = database | ||
self.navigator = navigator | ||
} | ||
|
||
func viewDidLoad() { | ||
view?.startAnimating() | ||
view?.setupNavigationItem() | ||
retrieveSets() | ||
} | ||
|
||
func retrieveSets() { | ||
Task { [weak self] in | ||
do { | ||
guard let self else { return } | ||
|
||
let setList = try await interactor.retrieveSets() | ||
|
||
await MainActor.run { [weak self] in | ||
self?.view?.updateSetList(setList) | ||
self?.view?.stopAnimating() | ||
self?.view?.endRefreshControl() | ||
} | ||
} catch { | ||
await MainActor.run { [weak self] in | ||
ToastMessages.showNetworkErrorMessage() | ||
LoggerManager.shared.log(event: .setsList, parameters: ["error": error.localizedDescription]) | ||
self?.view?.stopAnimating() | ||
self?.view?.endRefreshControl() | ||
} | ||
} | ||
} | ||
} | ||
|
||
func didSelectSet(_ set: SetDTO) { | ||
navigator.navigate(to: .cardList(database: database, with: set)) | ||
} | ||
|
||
func aboutButtonTouched() { | ||
navigator.navigate(to: .about) | ||
} | ||
|
||
func searchButtonTouched() { | ||
navigator.navigate(to: .search(database: database)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// SWDTabBarFactory.swift | ||
// SWDestinyTrades | ||
// | ||
// Created by Diogo Autilio on 28/11/23. | ||
// Copyright © 2023 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
final class SWDTabBarFactory { | ||
|
||
func makeSetsList(with database: DatabaseProtocol?) -> UIViewController { | ||
let viewController = SetsListViewController() | ||
let router = SetsListNavigator(viewController) | ||
let interactor = SetsListInteractor() | ||
let presenter = SetsPresenter(view: viewController, | ||
interactor: interactor, | ||
database: database, | ||
navigator: router) | ||
viewController.presenter = presenter | ||
return viewController | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
SWDestinyTradesTests/Screens/Sets/Interactor/SetsListInteractorTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// SetsListInteractorTests.swift | ||
// SWDestinyTradesTests | ||
// | ||
// Created by Diogo Autilio on 29/11/23. | ||
// Copyright © 2023 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Nimble | ||
import Nimble_Snapshots | ||
import Quick | ||
import UIKit | ||
|
||
@testable import SWDestinyTrades | ||
|
||
final class SetsListInteractorTests: AsyncSpec { | ||
|
||
override class func spec() { | ||
|
||
var sut: SetsListInteractor! | ||
var service: SWDestinyService! | ||
var client: HttpClientMock! | ||
|
||
describe("SetsListInteractor") { | ||
|
||
beforeEach { | ||
client = HttpClientMock() | ||
service = SWDestinyService(client: client) | ||
sut = SetsListInteractor(service: service) | ||
} | ||
|
||
it("should retrieve the set list with success") { | ||
let setList = try await sut.retrieveSets() | ||
expect(setList.count) == 20 | ||
} | ||
|
||
it("should fail to retrieve the set list") { | ||
client.error = true | ||
await expect { try await sut.retrieveSets() }.to(throwError()) | ||
} | ||
} | ||
} | ||
} |