diff --git a/iOS/Airbnb/Airbnb.xcodeproj/project.pbxproj b/iOS/Airbnb/Airbnb.xcodeproj/project.pbxproj index 35316117e..14ab9077c 100644 --- a/iOS/Airbnb/Airbnb.xcodeproj/project.pbxproj +++ b/iOS/Airbnb/Airbnb.xcodeproj/project.pbxproj @@ -38,6 +38,7 @@ AEC52F712663FF3600D8F802 /* ConditionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC52F6F2663FF3600D8F802 /* ConditionCell.swift */; }; AEC52F742664041200D8F802 /* ConditionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC52F732664041200D8F802 /* ConditionViewModel.swift */; }; AEF03BA526674E8200050531 /* PriceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEF03BA426674E8200050531 /* PriceViewController.swift */; }; + AEF03BA726675AB200050531 /* PriceUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEF03BA626675AB200050531 /* PriceUseCase.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -95,6 +96,7 @@ AEC52F6F2663FF3600D8F802 /* ConditionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConditionCell.swift; sourceTree = ""; }; AEC52F732664041200D8F802 /* ConditionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConditionViewModel.swift; sourceTree = ""; }; AEF03BA426674E8200050531 /* PriceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PriceViewController.swift; sourceTree = ""; }; + AEF03BA626675AB200050531 /* PriceUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PriceUseCase.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -273,6 +275,7 @@ isa = PBXGroup; children = ( AEF03BA426674E8200050531 /* PriceViewController.swift */, + AEF03BA626675AB200050531 /* PriceUseCase.swift */, ); path = Price; sourceTree = ""; @@ -411,6 +414,7 @@ buildActionMask = 2147483647; files = ( AE9AC6A7265CCCBF0038C198 /* CalendarViewController.swift in Sources */, + AEF03BA726675AB200050531 /* PriceUseCase.swift in Sources */, AE11F5AE265F3D920034779F /* Date+extension.swift in Sources */, AE0B5DE326560287000B35E7 /* MainPageUseCase.swift in Sources */, AE0B5DEF26563BE4000B35E7 /* RecommandedDestinationViewController.swift in Sources */, diff --git a/iOS/Airbnb/Airbnb.xcodeproj/project.xcworkspace/xcuserdata/gimjigyeong.xcuserdatad/UserInterfaceState.xcuserstate b/iOS/Airbnb/Airbnb.xcodeproj/project.xcworkspace/xcuserdata/gimjigyeong.xcuserdatad/UserInterfaceState.xcuserstate index 0c40f5564..f811edb0c 100644 Binary files a/iOS/Airbnb/Airbnb.xcodeproj/project.xcworkspace/xcuserdata/gimjigyeong.xcuserdatad/UserInterfaceState.xcuserstate and b/iOS/Airbnb/Airbnb.xcodeproj/project.xcworkspace/xcuserdata/gimjigyeong.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/iOS/Airbnb/Airbnb.xcodeproj/xcuserdata/gimjigyeong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/iOS/Airbnb/Airbnb.xcodeproj/xcuserdata/gimjigyeong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 9ebaaea7a..22d3e2e89 100644 --- a/iOS/Airbnb/Airbnb.xcodeproj/xcuserdata/gimjigyeong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/iOS/Airbnb/Airbnb.xcodeproj/xcuserdata/gimjigyeong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -84,53 +84,5 @@ landmarkType = "7"> - - - - - - - - - - - - diff --git a/iOS/Airbnb/Airbnb/ConditionPage/Price/PriceUseCase.swift b/iOS/Airbnb/Airbnb/ConditionPage/Price/PriceUseCase.swift new file mode 100644 index 000000000..7bf5ebfdb --- /dev/null +++ b/iOS/Airbnb/Airbnb/ConditionPage/Price/PriceUseCase.swift @@ -0,0 +1,43 @@ +// +// PriceUseCase.swift +// Airbnb +// +// Created by Lia on 2021/06/02. +// + +import Foundation +import Combine + +class PriceUseCase { + + @Published var prices: Prices! + @Published var error: Error! + + private var networkManager: NetworkManageable + private var cancelBag = Set() + + init(networkManager: NetworkManageable = NetworkManager()) { + self.networkManager = networkManager + } + +} + +extension PriceUseCase { + + func requestMainPage(condition: Condition) { + + networkManager.post(url: EndPoint.url(path: "/rooms/price")!, data: condition, result: Prices.self) + .receive(on: DispatchQueue.main) + .sink { error in + print("๐Ÿ˜ก๐Ÿ“ฎerror", error) + self.error = error as? Error + } receiveValue: { games in + self.prices = games.self + }.store(in: &cancelBag) + } + +} + +struct Prices: Decodable { + var prices: [Int] +} diff --git a/iOS/Airbnb/Airbnb/ConditionPage/Price/PriceViewController.swift b/iOS/Airbnb/Airbnb/ConditionPage/Price/PriceViewController.swift index b88b6575d..02dda0e46 100644 --- a/iOS/Airbnb/Airbnb/ConditionPage/Price/PriceViewController.swift +++ b/iOS/Airbnb/Airbnb/ConditionPage/Price/PriceViewController.swift @@ -6,11 +6,14 @@ // import UIKit +import Combine class PriceViewController: UIViewController { private var conditionViewModel: ConditionViewModel + private var priceUseCase = PriceUseCase() + private var cancelBag = Set() private var containerView: UIView! let label = UILabel() @@ -26,6 +29,8 @@ class PriceViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white + priceUseCase.requestMainPage(condition: Condition(cityId: conditionViewModel.city, schedule: conditionViewModel.schedule, price: conditionViewModel.price, people: conditionViewModel.people)) + bind() configure() configureContainer() configureNavigation() @@ -35,6 +40,25 @@ class PriceViewController: UIViewController { } +extension PriceViewController { + + private func bind() { + priceUseCase.$prices.receive(on: DispatchQueue.main) + .sink { prices in + guard let prices = prices else { return } + print(prices) + } + .store(in: &cancelBag) + + priceUseCase.$error + .receive(on: DispatchQueue.main) + .sink { error in + guard let error = error else { return } + print(error) ///์‚ฌ์šฉ์ž์—๊ฒŒ ์—๋Ÿฌ ํ‘œ์‹œํ•˜๋Š” ๋ถ€๋ถ„ ๋ฏธ๊ตฌํ˜„ + }.store(in: &cancelBag) + } +} + extension PriceViewController { diff --git a/iOS/Airbnb/Airbnb/Network.swift b/iOS/Airbnb/Airbnb/Network.swift index 3c854d340..a4b7c1003 100644 --- a/iOS/Airbnb/Airbnb/Network.swift +++ b/iOS/Airbnb/Airbnb/Network.swift @@ -32,7 +32,7 @@ enum EndPoint { protocol NetworkManageable { func get(type: T.Type, url: URL) -> AnyPublisher - func post(url: URL, data: T) -> AnyPublisher + func post(url: URL, data: T, result: R.Type) -> AnyPublisher } @@ -66,7 +66,7 @@ extension NetworkManager: NetworkManageable { .eraseToAnyPublisher() } - func post(url: URL, data: T) -> AnyPublisher { + func post(url: URL, data: T, result: R.Type) -> AnyPublisher { return Just(data) .encode(encoder: JSONEncoder()) @@ -85,12 +85,13 @@ extension NetworkManager: NetworkManageable { } .flatMap { request in return self.session.dataTaskPublisher(for: request) - .tryMap { element -> Void in + .tryMap { element -> R in guard let httpResponse = element.response as? HTTPURLResponse, httpResponse.statusCode == 200 else { throw NetworkError.BadURL } - return + let result = try JSONDecoder().decode(R.self, from: element.data) + return result } } .eraseToAnyPublisher()