-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from HoonHaChoi/feat-3-EndPoint
EndPoint Merge
- Loading branch information
Showing
10 changed files
with
189 additions
and
60 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
Binary file modified
BIN
+12.6 KB
(120%)
...proj/project.xcworkspace/xcuserdata/hoonhachoi.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
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,17 @@ | ||
// | ||
// DIContainer.swift | ||
// Side-dish | ||
// | ||
// Created by HOONHA CHOI on 2021/04/20. | ||
// | ||
|
||
import Foundation | ||
|
||
class DIContainer { | ||
static func createDI() -> SideDishViewModel { | ||
let networkManage = NetworkManager() | ||
let useCase = SideDishUseCase(networkManager: networkManage) | ||
let viewModel = SideDishViewModel(sideDishUseCase: useCase) | ||
return viewModel | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
Side-dish/Side-dish/DomainLayer/UseCase/SideDishUseCase.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 @@ | ||
// | ||
// UseCase.swift | ||
// Side-dish | ||
// | ||
// Created by HOONHA CHOI on 2021/04/20. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
protocol SideDishProtocol { | ||
func execute(path: Path) -> AnyPublisher<SideDishes, NetworkError> | ||
} | ||
|
||
class SideDishUseCase: SideDishProtocol { | ||
|
||
private let networkManager: NetworkManageable | ||
|
||
init(networkManager : NetworkManageable) { | ||
self.networkManager = networkManager | ||
} | ||
|
||
func execute(path: Path) -> AnyPublisher<SideDishes, NetworkError> { | ||
return networkManager.requestResource(path: path, method: .get) | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
Side-dish/Side-dish/PresentationLayer/SideDishViewModel.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,52 @@ | ||
// | ||
// ViewModel.swift | ||
// Side-dish | ||
// | ||
// Created by HOONHA CHOI on 2021/04/20. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
class SideDishViewModel { | ||
|
||
private let sideDishUseCase: SideDishProtocol | ||
private var cancellable = Set<AnyCancellable>() | ||
|
||
@Published var errorMessage = "" | ||
@Published var item: [Item] = [] | ||
|
||
init(sideDishUseCase: SideDishProtocol) { | ||
self.sideDishUseCase = sideDishUseCase | ||
request() | ||
} | ||
|
||
private func request() { | ||
Path.allCases.forEach { (path) in | ||
sideDishUseCase.execute(path: path).sink { (complete) in | ||
if case .failure(let error) = complete { | ||
self.errorMessage = error.message | ||
} | ||
} receiveValue: { (SideDishes) in | ||
self.item = SideDishes.body | ||
}.store(in: &cancellable) | ||
} | ||
|
||
} | ||
|
||
func test(completion: @escaping ([Item]) -> ()){ | ||
$item | ||
.dropFirst() | ||
.sink { (item) in | ||
completion(item) | ||
}.store(in: &cancellable) | ||
} | ||
|
||
func occur(completion: @escaping ((String) ->())) { | ||
$errorMessage | ||
.dropFirst() | ||
.sink { (message) in | ||
completion(message) | ||
}.store(in: &cancellable) | ||
} | ||
} |
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