Skip to content

Commit

Permalink
feat: ✨accommodation network usecase & DTO 생성(#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lia316 committed Jun 3, 2021
1 parent 5c5fe7d commit 89a2ba5
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
8 changes: 8 additions & 0 deletions iOS/Airbnb/Airbnb.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
AE87A7862668DF22003E9541 /* ResultSupplementaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE87A7852668DF22003E9541 /* ResultSupplementaryView.swift */; };
AE87A7892668DFB1003E9541 /* AccommodationCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE87A7872668DFB1003E9541 /* AccommodationCell.swift */; };
AE87A78A2668DFB1003E9541 /* AccommodationCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = AE87A7882668DFB1003E9541 /* AccommodationCell.xib */; };
AE87A78C266906AE003E9541 /* SearchRoomsUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE87A78B266906AE003E9541 /* SearchRoomsUseCase.swift */; };
AE87A78E26690954003E9541 /* RoomDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE87A78D26690954003E9541 /* RoomDTO.swift */; };
AE8CD3B42653538700BCB8FC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8CD3B32653538700BCB8FC /* AppDelegate.swift */; };
AE8CD3B62653538700BCB8FC /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8CD3B52653538700BCB8FC /* SceneDelegate.swift */; };
AE8CD3B82653538700BCB8FC /* MainPageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8CD3B72653538700BCB8FC /* MainPageViewController.swift */; };
Expand Down Expand Up @@ -94,6 +96,8 @@
AE87A7852668DF22003E9541 /* ResultSupplementaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResultSupplementaryView.swift; sourceTree = "<group>"; };
AE87A7872668DFB1003E9541 /* AccommodationCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccommodationCell.swift; sourceTree = "<group>"; };
AE87A7882668DFB1003E9541 /* AccommodationCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccommodationCell.xib; sourceTree = "<group>"; };
AE87A78B266906AE003E9541 /* SearchRoomsUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchRoomsUseCase.swift; sourceTree = "<group>"; };
AE87A78D26690954003E9541 /* RoomDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomDTO.swift; sourceTree = "<group>"; };
AE8CD3B02653538700BCB8FC /* Airbnb.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Airbnb.app; sourceTree = BUILT_PRODUCTS_DIR; };
AE8CD3B32653538700BCB8FC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
AE8CD3B52653538700BCB8FC /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -188,6 +192,8 @@
isa = PBXGroup;
children = (
AE87A7832668D19D003E9541 /* SearchResultViewController.swift */,
AE87A78B266906AE003E9541 /* SearchRoomsUseCase.swift */,
AE87A78D26690954003E9541 /* RoomDTO.swift */,
AE87A7852668DF22003E9541 /* ResultSupplementaryView.swift */,
AE87A7872668DFB1003E9541 /* AccommodationCell.swift */,
AE87A7882668DFB1003E9541 /* AccommodationCell.xib */,
Expand Down Expand Up @@ -460,6 +466,8 @@
files = (
AEF03BA92667649000050531 /* PeopleViewController.swift in Sources */,
AE9AC6A7265CCCBF0038C198 /* CalendarViewController.swift in Sources */,
AE87A78E26690954003E9541 /* RoomDTO.swift in Sources */,
AE87A78C266906AE003E9541 /* SearchRoomsUseCase.swift in Sources */,
AEF03BA726675AB200050531 /* PriceUseCase.swift in Sources */,
AE11F5AE265F3D920034779F /* Date+extension.swift in Sources */,
AE0B5DE326560287000B35E7 /* MainPageUseCase.swift in Sources */,
Expand Down
Binary file not shown.
55 changes: 55 additions & 0 deletions iOS/Airbnb/Airbnb/ResultPage/RoomDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// RoomDTO.swift
// Airbnb
//
// Created by Lia on 2021/06/03.
//

import Foundation

struct Rooms: Codable, Hashable {
var rooms : [Room]
}

struct Room: Codable, Hashable {
var roomId: Int
var images: Images
var price: Int
var people: Int
var title: String
var description: String
var host: Host
var detail: Detail
var grade: Int
var review: Int
var tax: Tax

struct Images: Codable, Hashable {
var mainImage: String
var detailImage: [String]
}

struct Host: Codable, Hashable {
var image: String
var name: String
}

struct Detail: Codable, Hashable {
var maxPeople: Int
var oneRoom: Bool
var bed: Int
var bath: Int
var hairDryer: Bool
var airConditioner: Bool
var WiFi: Bool
var kitchen: Bool
}

struct Tax: Codable, Hashable {
var cleanTax: Int
var serviceTax: Int
var accommodationTax: Int
}
}


37 changes: 37 additions & 0 deletions iOS/Airbnb/Airbnb/ResultPage/SearchRoomsUseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// SearchRoomsUseCase.swift
// Airbnb
//
// Created by Lia on 2021/06/03.
//

import Foundation
import Combine

class SearchRoomsUseCase {

@Published var rooms: Rooms!
@Published var error: Error!

private var networkManager: NetworkManageable
private var cancelBag = Set<AnyCancellable>()

init(networkManager: NetworkManageable = NetworkManager()) {
self.networkManager = networkManager
}

}

extension SearchRoomsUseCase {

func requestPirce(condition: ConditionData) {
networkManager.post(url: EndPoint.url(path: "/rooms")!, data: condition, result: Rooms.self)
.receive(on: DispatchQueue.main)
.sink { error in
self.error = error as? Error
} receiveValue: { rooms in
self.rooms = rooms.self
}.store(in: &cancelBag)
}

}

0 comments on commit 89a2ba5

Please sign in to comment.