88import Foundation
99import ICTMDBNetworkManagerKit
1010
11- import Foundation
1211
13- /// `HomeInteractor` handles the data-fetching logic for the Home module.
14- final class HomeInteractor : @preconcurrency PresenterToInteractorHomeProtocol {
15-
12+ final class HomeInteractor : PresenterToInteractorHomeProtocol {
13+
1614 // MARK: - Properties
1715
1816 /// Reference to the Presenter to send data or errors back.
@@ -24,59 +22,45 @@ final class HomeInteractor: @preconcurrency PresenterToInteractorHomeProtocol {
2422 /// Current device language code (e.g., tr, en).
2523 let deviceLanguageCode = Locale . current. language. languageCode ?? . english
2624
27-
2825 init ( network: NetworkManagerProtocol ) {
2926 self . network = network
3027 }
3128
3229 // MARK: - Popular TV Shows
3330
34- /// Loads the list of popular TV shows from the API.
35- func loadPopularMovies( ) {
31+ /// Requests popular TV shows data
32+ func loadPopularMovies( ) async {
3633 let request = PopularMoviesRequest (
3734 language: deviceLanguageCode == . turkish ? . tr : . en,
3835 page: 1
3936 )
40-
41- // Executes the network request asynchronously.
42- network. execute ( request) { [ weak self] result in
43- guard let self else { return }
44-
45- switch result {
46- case . success( let list) :
47- // Sends the fetched popular shows to the Presenter.
48- presenter? . sendPopularTvShows ( list. results)
49-
50- case . failure:
51- // Notifies Presenter of an error.
52- presenter? . sendError ( . popular)
53- }
37+
38+ do {
39+ let list = try await network. execute ( request)
40+ presenter? . sendPopularTvShows ( list. results)
41+ } catch {
42+ presenter? . sendError ( . popular)
5443 }
5544 }
45+
46+
5647
5748 // MARK: - Airing Today TV Shows
5849
59- /// Loads the list of TV shows airing today.
60- func loadAiringMovies( ) {
50+ /// Requests airing today TV shows data
51+
52+ func loadAiringMovies( ) async {
6153 let request = AiringTodayRequest (
6254 language: deviceLanguageCode == . turkish ? . tr : . en,
6355 page: 1
6456 )
6557
66- // Executes the network request asynchronously.
67- network. execute ( request) { [ weak self] result in
68- guard let self else { return }
69-
70- switch result {
71- case . success( let list) :
72- // Sends the fetched airing shows to the Presenter.
73- presenter? . sendAiringTvShows ( list. results)
74-
75- case . failure:
76- // Notifies Presenter of an error.
77- presenter? . sendError ( . airingToday)
78- }
58+ do {
59+ let list = try await network. execute ( request)
60+ presenter? . sendAiringTvShows ( list. results)
61+ } catch {
62+ presenter? . sendError ( . airingToday)
63+
7964 }
8065 }
8166}
82-
0 commit comments